My Project
main.c
Go to the documentation of this file.
1 
9 #include <stdio.h>
10 
11 #include <SDL/SDL.h>
12 #include <SDL/SDL_image.h>
13 #include <SDL/SDL_ttf.h>
14 
15 #include "constants.h"
16 #include "play.h"
17 
18 int main(int argc, char* argv[])
19 {
20  // --- DECLARE VARIABLES ---
21  LAYOUT layout;
22  SDL_Event event;
23  LIST tileList = initBoard(&layout);
24 
25  // --- CONTROL VARIABLE ---
26  int run = 1;
27 
28  // --- INIT APPLICATION ---
29  if(SDL_Init(SDL_INIT_VIDEO) == -1) // Load SDL video mode
30  {
31  fprintf(stderr, "ERROR loading SDL video mode"); // If not load properly, save error
32  exit(EXIT_FAILURE); // Exit application
33  }
34 
35  if(TTF_Init() != NULL) // Load TTF library for font handling
36  {
37  fprintf(stderr, "ERROR loading the TFF library"); // If not load properly, save error
38  exit(EXIT_FAILURE); // Exit application
39  }
40 
41  // --- PREPARE AND SET THE LAYOUT STRUCTURE ---
42  loadLayout(&layout);
43 
44  // --- EXECUTE APPLICATION CONTINUOUSLY ---
45  while(run)
46  {
47  drawMenu(&layout); // Draw the main menu of the game
48 
49  SDL_WaitEvent(&event); // Wait for the next user event
50  switch(event.type) // Test event type value
51  {
52  case SDL_QUIT: // If the user wants to close the window
53  run = 0; // Stop the application
54  break;
55  case SDL_KEYDOWN: // If the user pressed a keyboard key
56  switch(event.key.keysym.sym) // Test key value
57  {
58  case SDLK_RETURN: // If the user pressed the carriage return key
59  playGame(&layout); // Load the game
60  break;
61  case SDLK_ESCAPE: // If the user pressed the escape key
62  run = 0; // Stop the application
63  break;
64  default: // In any other case, do nothing
65  break;
66  }
67  default: // In any other case, do nothing
68  break;
69  }
70  }
71 
72  // --- CLEAN UP ---
73  cleanUp(&layout);
74 
75  // --- EXIT APPLICATION ---
76  TTF_Quit(); // Unload TFF library
77  SDL_QUIT; // Unload SDL video mode
78 
79  return EXIT_SUCCESS; // Return 0
80 }
int main(int argc, char *argv[])
Definition: main.c:18
Contains every application constants.
void loadLayout(LAYOUT *l)
Definition: play.c:85
void playGame(LAYOUT *l)
Definition: play.c:19
void drawMenu(LAYOUT *l)
Definition: play.c:134
Contains every functions declaration for play.c.
Definition: play.h:27
LIST initBoard(LAYOUT *l)
Definition: play.c:560
void cleanUp(LAYOUT *l)
Definition: play.c:543
Definition: play.h:52