1. 程式人生 > >俄羅斯方塊60分

俄羅斯方塊60分

flag true 俄羅斯方塊 highlight turn false bool ace else

#include<iostream>
using namespace std;
int main() {
	int a[15][10];
	int b[5][5];
	int height[4] = { 0,0,0,0 };
	int leftmargin;
	int max = 15;
	int i, j, k;
	int tmp;
	int x, y;
	bool flag;
	for (i = 0; i<15; i++)
		for (j = 0; j<10; j++)
			cin >> a[i][j];
	leftmargin = 3;
	for (i = 0; i<4; i++) {
		for (j = 0; j<4; j++) {
			cin >> b[i][j];
			if (b[i][j] == 1 && j < leftmargin)
				leftmargin = j;
		}
	}
	cin >> x;
	y = 0;
	for (i = 0; i < 4; i++) {
		if (x >= leftmargin) {
			for (j = x - leftmargin; j < x - leftmargin + 4; j++)
				a[i][j] = b[i][j - x + leftmargin];
		}
		else {
			for (j = x; j < x - leftmargin + 4; j++)
				a[i][j] = b[i][j - x + leftmargin];
		}
	}
	for (j = x; j < x + 4; j++) {
		flag = false;
		for (i = 0; i < 15; i++) {
			if (a[i][j] == 1 && a[i+1][j] == 0 && i < 4) {
				flag = true;
			}
			else if (a[i][j] == 0 && flag == true) {
				height[j - x]++;
			}
			else if (a[i][j] == 1 && i >= 4)
				break;
		}
	}
	for (i = 0; i < 4; i++) {
		if (height[i] < max && height[i] != 0)
			max = height[i];
	}
	for (i = 0; i < 4; i++)
		for (j = 0; j < 10; j++)
			a[i][j] = 0;
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			if (b[i][j] != 0)
				a[i + max][j + x - leftmargin] = b[i][j];
		}
	}
	for (i = 0; i < 15; i++) {
		for (j = 0; j < 10; j++) {
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

  

俄羅斯方塊60分