minesweeper

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit e13e3e4b9e75d90c98c4cdadafed2f0986e8a838
parent 60496d7c9276675374a371a54bb8c217fe99aee4
Author: Samdal <samdal@protonmail.com>
Date:   Thu, 29 Apr 2021 07:15:26 +0200

small fixes

Diffstat:
Mmain.c | 13+++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/main.c b/main.c @@ -2,7 +2,7 @@ #include <stdlib.h> // Global variables -static bool shouldRedraw = false; +static bool shouldRedraw = true; static int screenWidth = 800; static int screenHeight = 800; static Vector2 squareSize; @@ -48,6 +48,9 @@ int main(int argc, char *argv[]) { while (!WindowShouldClose()) UpdateDrawFrame(); + // close down and free memory + free(bombPos); + free(shown); CloseWindow(); return 0; } @@ -58,17 +61,19 @@ void InitGame(void) { TilesX = 20; if (TilesY <= 0) TilesY = 20; - if (TotalBombs <= 0 || TotalBombs >= TilesX * TilesY) + + int TileArea = TilesX * TilesY; + if (TotalBombs <= 0 || TotalBombs >= TileArea) TotalBombs = 20; + bombPos = malloc(20 * sizeof(Bomb)); - shown = calloc(TilesX * TilesY, sizeof(bool)); + bool(*shown)[TilesX] = calloc(TileArea, sizeof(bool)); // square size squareSize.x = (float)screenWidth / (float)TilesX; squareSize.y = (float)screenHeight / (float)TilesY; NewGame(); - shouldRedraw = true; } void NewGame(void) {