game controller & game over screen
This commit is contained in:
parent
4f7fb23724
commit
abe0457681
57
Tetris.cs
57
Tetris.cs
|
@ -47,9 +47,7 @@ namespace Tetris {
|
|||
public static void Main() {
|
||||
// Initialize board
|
||||
if (!hasStarted) {
|
||||
for (int i = 0; i < board.GetLength(0); i++)
|
||||
for (int j = 0; j < board.GetLength(1); j++)
|
||||
board[i, j] = black;
|
||||
initBoard();
|
||||
hasStarted = true;
|
||||
}
|
||||
|
||||
|
@ -90,6 +88,7 @@ namespace Tetris {
|
|||
canvas = matrix.SwapOnVsync(canvas);
|
||||
|
||||
// Inner loop for actual Gameplay
|
||||
score = 0;
|
||||
gameOver = false;
|
||||
while (!gameOver) {
|
||||
// Start of Frame
|
||||
|
@ -166,7 +165,8 @@ namespace Tetris {
|
|||
canvas.Clear();
|
||||
canvas.DrawText(font, 0, 8, col, "Game Over!");
|
||||
canvas.DrawText(font, 0, 24, col, " ) Weiter");
|
||||
canvas.DrawText(font, 0, 40, col, " ) Beenden");
|
||||
canvas.DrawText(font, 0, 32, col, " ) Beenden");
|
||||
canvas.DrawText(font, 0, 48, col, $"Score: {score}");
|
||||
// Cursor is a '#' at (0, 24 + i * 8) where i may be [0, 1]
|
||||
canvas.DrawText(font, 0, 24+selectionIndex*8, col, "#");
|
||||
canvas = matrix.SwapOnVsync(canvas);
|
||||
|
@ -211,6 +211,46 @@ namespace Tetris {
|
|||
}
|
||||
}
|
||||
|
||||
// Method to initialize the Game board
|
||||
private static void initBoard() {
|
||||
for (int i = 0; i < board.GetLength(0); i++)
|
||||
for (int j = 0; j < board.GetLength(1); j++)
|
||||
board[i, j] = black;
|
||||
|
||||
// P
|
||||
for (int i = 0; i < 8; i++)
|
||||
board[1, 13 + i] = colors[4];
|
||||
board[2, 13] = colors[4];
|
||||
board[3, 13] = colors[4];
|
||||
board[4, 14] = colors[4];
|
||||
board[4, 15] = colors[4];
|
||||
board[2, 16] = colors[4];
|
||||
board[3, 16] = colors[4];
|
||||
|
||||
// T
|
||||
for (int i = 0; i < 8; i++)
|
||||
board[5, 11 + i] = colors[5];
|
||||
board[3, 11] = colors[5];
|
||||
board[4, 11] = colors[5];
|
||||
board[6, 11] = colors[5];
|
||||
board[7, 11] = colors[5];
|
||||
|
||||
// B
|
||||
for (int i = 0; i < 8; i++)
|
||||
board[6, 13 + i] = colors[4];
|
||||
board[7, 13] = colors[4];
|
||||
board[8, 13] = colors[4];
|
||||
board[9, 14] = colors[4];
|
||||
board[9, 15] = colors[4];
|
||||
board[7, 16] = colors[4];
|
||||
board[8, 16] = colors[4];
|
||||
board[9, 17] = colors[4];
|
||||
board[9, 18] = colors[4];
|
||||
board[9, 19] = colors[4];
|
||||
board[7, 20] = colors[4];
|
||||
board[8, 20] = colors[4];
|
||||
}
|
||||
|
||||
// Method to check whether a block at given coordinates collides with any other block or border
|
||||
private static bool collisionCheck(int x, int y, int[][] block) {
|
||||
foreach (int[] b in block) {
|
||||
|
@ -282,11 +322,8 @@ namespace Tetris {
|
|||
// Otherwise reset game, because player has lost
|
||||
else {
|
||||
gameOver = true;
|
||||
for (int i = 0; i < board.GetLength(0); i++)
|
||||
for (int j = 0; j < board.GetLength(1); j++)
|
||||
board[i, j] = black;
|
||||
initBoard();
|
||||
player = new();
|
||||
score = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,11 +372,11 @@ namespace Tetris {
|
|||
// Method to choose what a given index has to do
|
||||
public static void enterSelection() {
|
||||
switch (selectionIndex) {
|
||||
case 0:
|
||||
case 1:
|
||||
selection = false;
|
||||
startOver = false;
|
||||
break;
|
||||
case 1:
|
||||
case 0:
|
||||
selection = false;
|
||||
frameCount = 0;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user