Browse Source

initialize minesweeper

remotes/origin/David
David Moeller 11 months ago
parent
commit
c1e8a99e7a
  1. 25
      src/main/c/Minesweeper/minesweeper_start.c
  2. 2
      src/main/c/Minesweeper/minesweeper_start.h
  3. 6
      src/main/c/Snake/snake_start.c

25
src/main/c/Minesweeper/minesweeper_start.c

@ -1,5 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "minesweeper_start.h"
#pragma region defines
#define BLOCK 219
#define FLAG '?'
@ -17,6 +19,8 @@
void main_menu_minesweeper();
void game_minesweeper();
void options_minesweeper();
Minesweeper_Board initialize_minesweeper();
void draw_minesweeper();
#pragma endregion
#pragma region Global
@ -26,7 +30,7 @@ int num_bombs = MIDDLE * MIDDLE / NORMAL;
#pragma endregion //Global
int minesweeper_start(){
void minesweeper_start(){
system("clear");
main_menu_minesweeper();
}
@ -65,7 +69,8 @@ void main_menu_minesweeper(){
}
void game_minesweeper(){
Minesweeper_Board board = initialize_minesweeper();
draw_minesweeper();
}
void options_minesweeper(){
@ -119,4 +124,20 @@ void options_minesweeper(){
break;
}
}
}
Minesweeper_Board initialize_minesweeper(){
Minesweeper_Board board;
board.width = width;
board.height = height;
char *tiles = (char*) malloc(width * height * sizeof(char));
for(int i = 0; i < width * height; i++){tiles[i] = FLAG;}
board.tiles = tiles;
board.num_bombs = num_bombs;
return board;
}
void draw_minesweeper(){
}

2
src/main/c/Minesweeper/minesweeper_start.h

@ -6,7 +6,7 @@ typedef struct Minesweeper_Board{
unsigned int height;
char *tiles;
int num_bombs;
unsigned int bombs[];
int *bombs;
}Minesweeper_Board;

6
src/main/c/Snake/snake_start.c

@ -19,7 +19,7 @@ void options_snake();
Snake initialize_snake();
void get_next_move(double limit, Snake *snake, bool *running);
void move_snake(Snake *snake);
void draw(Snake *snake, unsigned char fruit);
void draw_snake(Snake *snake, unsigned char fruit);
int part_of_snake(Snake *snake, unsigned char tile);
bool check_if_dead(Snake *snake);
unsigned char spawn_fruit(Snake *snake);
@ -76,7 +76,7 @@ void game_snake(){
while (running){
system("clear");
draw(&snake, fruit);
draw_snake(&snake, fruit);
if(check_if_dead(&snake)){break;}
t = clock() - t;
get_next_move(TIME_TURN - (double)t / CLOCKS_PER_SEC, &snake, &running);
@ -141,7 +141,7 @@ void move_snake(Snake *snake){
snake->segments[0] += snake->direction;
}
void draw(Snake *snake, unsigned char fruit){
void draw_snake(Snake *snake, unsigned char fruit){
printf("Score:%d Speed:%f\n", snake->length - START_LENGTH, TIME_TURN);
printf("+");
for(int i = 0; i < WIDTH; i++){printf("-");}

Loading…
Cancel
Save