Skip to content
Snippets Groups Projects
main.c 1.16 KiB
Newer Older
#include "grid.h"
#include "sdl2.h"
#include <stdbool.h>
Arnaud Albiez's avatar
Arnaud Albiez committed

Arnaud Albiez's avatar
Arnaud Albiez committed

Arnaud Albiez's avatar
Arnaud Albiez committed
enum Event
{
  EVT_QUIT = 0,
  EVT_TOP = 1,
  EVT_BOTTOM = 2,
  EVT_RIGTH = 3,
  EVT_LEFT = 4,
};

enum Event next_event()
{
  while (true)
  {
    char entry = fgetc(stdin);
    switch (entry)
    {
    case 'e':
      return EVT_QUIT;
    case 'z':
      return EVT_TOP;
    case 's':
      return EVT_BOTTOM;
    case 'q':
      return EVT_LEFT;
    case 'd':
      return EVT_RIGTH;
    }
  }
}

int main(void)
{
  struct Grid *grid = init_level("./level1.txt");
  sdl_init();
  bool run = true;
  while (run)
  {
    printf("%d \n", size_block(grid));
    void draw();
Arnaud Albiez's avatar
Arnaud Albiez committed
    if (win_condition(grid) == 1)
    {
      run = false;
    }
Arnaud Albiez's avatar
Arnaud Albiez committed
    enum Event event = next_event();
    switch (event)
Arnaud Albiez's avatar
Arnaud Albiez committed
    case EVT_QUIT: {
Arnaud Albiez's avatar
Arnaud Albiez committed
    case EVT_TOP: {
      move_player(grid, TOP);
      break;
    }
Arnaud Albiez's avatar
Arnaud Albiez committed
    case EVT_BOTTOM: {
      move_player(grid, BOTTOM);
      break;
    }
Arnaud Albiez's avatar
Arnaud Albiez committed
    case EVT_LEFT: {
      move_player(grid, LEFT);
      break;
    }
Arnaud Albiez's avatar
Arnaud Albiez committed
    case EVT_RIGTH: {
      move_player(grid, RIGHT);
      break;
    }
    }
  }
  free_grid(grid);