Added win and loss conditions along with their respective screens

This commit is contained in:
2026-03-06 18:00:19 +01:00
parent eb8834324e
commit 4c21d309e9
5 changed files with 99 additions and 27 deletions
+29 -7
View File
@@ -30,8 +30,7 @@ int main() {
srand(time(NULL));
reset_board(&game_state);
InitWindow(800, 600, "2048");
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "2048");
SetTargetFPS(30); // So my laptop doesn't burn
while (!WindowShouldClose()) {
@@ -57,12 +56,35 @@ int main() {
}
}
DrawText(TextFormat("Score: %d", game_state.score), 600, BOARD_MARGIN, 20, BLACK);
DrawText(TextFormat("Moves used: %d", game_state.moves_made), 600, BOARD_MARGIN + 20, 20, BLACK);
DrawText(TextFormat("Score: %d", game_state.score), WINDOW_HEIGHT, BOARD_MARGIN, 20, BLACK);
DrawText(TextFormat("Moves used: %d", game_state.moves_made), WINDOW_HEIGHT, BOARD_MARGIN + 20, 20, BLACK);
// Reset button
DrawRectangle(500, 455, 275, 24, RED);
DrawText("Reset", 500 + 275 / 2 - MeasureText("Reset", 20) / 2, 455 + 4, 20, WHITE);
if (game_state.status == PLAYING) {
DrawText("Drag with the mouse to move tiles", 400 - MeasureText("Drag with the mouse to move tiles", 20) / 2,
WINDOW_HEIGHT - 40, 20, GRAY);
// Reset button
DrawRectangle(500, 455, 275, 24, RED);
DrawText("Reset", 500 + 275 / 2 - MeasureText("Reset", 20) / 2, 455 + 4, 20, WHITE);
} else {
Color overlay = Fade(BLACK, 0.7f);
DrawRectangle(0, 0, WINDOW_WIDTH, 700, overlay);
if (game_state.status == WON) {
DrawText("You win!", 400 - MeasureText("You win!", 40) / 2, 250, 40, GREEN);
} else if (game_state.status == LOST) {
DrawText("Game over!", 400 - MeasureText("Game over!", 40) / 2, 250, 40, RED);
}
// Draw the scores under the win/loss message
DrawText(TextFormat("Score: %d", game_state.score),
400 - MeasureText(TextFormat("Score: %d", game_state.score), 20) / 2, 290, 20, WHITE);
DrawText(TextFormat("Moves used: %d", game_state.moves_made),
400 - MeasureText(TextFormat("Moves used: %d", game_state.moves_made), 20) / 2, 310, 20, WHITE);
DrawRectangle(400 - 100, 450, 200, 40, RED);
DrawText("Try again", 400 - MeasureText("Try again", 20) / 2, 455 + 4, 20, WHITE);
}
EndDrawing();
handle_mouse_input(&game_state);