uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

main.c (1056B)


      1 #include "audio.h"
      2 #include "gameplay.h"
      3 #include "main.h"
      4 #include "minesweeper.h"
      5 #include "settings.h"
      6 #include "wins.h"
      7 #include <pthread.h>
      8 
      9 int
     10 main(int argc, char **argv)
     11 {	
     12 #ifndef NCURSES_VERSION
     13 	fprintf(stderr, "ncurses is needed in order to run this program.\n");
     14 	return EXIT_FAILURE;
     15 #endif /* NCURSES_VERSION */
     16 	init_curses();
     17 	Board b;
     18 	reset(&b);
     19 	b.gw = game_win(b.rows, b.cols);
     20 	init_game(&b);
     21 
     22 	pthread_t audiothread;
     23 	long tid = 1;
     24 	pthread_create(&audiothread, NULL, play_audio, (void *)tid);
     25 	play(&b);
     26 	
     27 	pthread_cancel(audiothread);
     28 	clear_board(&b);
     29 	delwin(b.gw);
     30 	endwin();
     31 	return EXIT_SUCCESS;
     32 }
     33 
     34 void
     35 reset(Board *b)
     36 {
     37 	echo();
     38 	b->cols		= set_cols();
     39 	b->rows		= set_rows();
     40 	b->nmines	= set_nmines(b->rows * b->cols);
     41 	b->ndefused = b->x = b->y = 0;
     42 	b->gameover = FALSE;
     43 	noecho();
     44 	options_menu();
     45 	erase();
     46 	refresh();
     47 }
     48 
     49 void
     50 init_game(Board *b)
     51 {
     52 	init_db(b);
     53 	init_mb(b);
     54 }
     55 
     56 void
     57 clear_board(Board *b)
     58 {
     59 	int i;
     60 	for (i = 0; i < b->rows; i++)
     61 	{
     62 		free(b->db[i]);
     63 		free(b->mb[i]);
     64 	}
     65 	free(b->db);
     66 	free(b->mb);
     67 }