Help with Tetris Logic

I had the piece falling down the bucket correctly and then I implemented the following classes in order to stop the piece and there is a problem with my logic that I am not seeing. Any guidance would be appreciated. Thx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
int main() // main function
{
	srand (time(0));

	initializeBucket(); // creates bucket

	char answer; // declares answer
	
	cout << "Would you like to play tetris (y/n)?" << endl; // asks user to play
	cin >> answer; // input user response

	while (answer == 'y') // if-then loop to determine gameplay depending on user response
	{
		int shapeType = rand() % 7 + 1; // declare and assign random integer to represent tetris shapes
		TetrisShape currentShape(shapeType);
		TetrisShape nextShape(shapeType);
		updateBucket(currentShape); // calls display shape function
		displayBucket(); // displays bucket

		for (int x = 0; x < SHAPE; x++)
		{
			for (int y = 0; y < SHAPE; y++)
			{
				if (currentShape.shapeArray[x][y] != ' ')
				{
					if (x < 25 && y < 12)
					{
						if (bucket[x][y] != ' ')
						{
							// check for line
							currentShape.setShape(nextShape);
							int a = rand() % 7 + 1;
							nextShape.setShape(a);
						}
					}
					else if (x = 25)
					{
						// check for line
						currentShape.setShape(nextShape);
						int a = rand() % 7 + 1;
						nextShape.setShape(a);
					}
					else
					{
						int newshapeTopLefty = currentShape.shapeTopLefty;
						int newshapeTopLeftx = currentShape.shapeTopLeftx + 1;
											
						for (int x = currentShape.shapeTopLeftx; x < currentShape.shapeTopLeftx + 4; x++)
						{
							for (int y = currentShape.shapeTopLefty; y < currentShape.shapeTopLefty + 4; y++)
							{
								bucket[x][y] = ' ';
							}
						}
						currentShape.setshapeTopLefty(newshapeTopLefty);
						currentShape.setshapeTopLeftx(newshapeTopLeftx);
	
						updateBucket(currentShape);
						displayBucket();
	
						if (false == processDownArrow(currentShape))
						{
							// check for line
							currentShape.setShape(nextShape);
							int a = rand() % 7 + 1;
							nextShape.setShape(a);
						}
						else
						{
							int newshapeTopLefty = currentShape.shapeTopLefty;
							int newshapeTopLeftx = currentShape.shapeTopLeftx + 1;
											
							for (int x = currentShape.shapeTopLeftx; x < currentShape.shapeTopLeftx + 4; x++)
							{
								for (int y = currentShape.shapeTopLefty; y < currentShape.shapeTopLefty + 4; y++)
								{
									bucket[x][y] = ' ';
								}
							}
							currentShape.setshapeTopLefty(newshapeTopLefty);
							currentShape.setshapeTopLeftx(newshapeTopLeftx);
	
							updateBucket(currentShape);
							displayBucket();
						}
					}
				}
			}
		}
		Sleep(3000);
	}
	cout << "Goodbye!" << endl;

	system("pause"); // pauses application before end
	return 0; // end main function
}


1
2
3
4
5
6
7
8
9
10
11
12
13
void TetrisShape::setShape(TetrisShape nextTetrisShape)
{
	shapeType = nextTetrisShape.shapeType;
	shapeTopLeftx = nextTetrisShape.shapeTopLeftx;
	shapeTopLefty = nextTetrisShape.shapeTopLefty;
	for (int i = 0; i < SHAPE; i++)
	{
		for(int j = 0; j < SHAPE; j++)
		{
			shapeArray[i][j] = nextTetrisShape.shapeArray[i][j];
		}
	}
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bool processDownArrow(TetrisShape& tetrisShape)
{
	for (int x = 0; x < SHAPE; x++)
	{
		for (int y = 0; y < SHAPE; y++)
		{
			if (tetrisShape.shapeArray[x][y] != ' ')
			{
				if (x < 25 && y < 12)
				{
					if (bucket[x][y] != ' ')
					{
						return false;
					}
				}
				else if (x = 25)
				{
					return false;
				}
			}
		}
	}
	return true;
}
Topic archived. No new replies allowed.