diff --git a/main.cpp b/main.cpp index e96149a..7e137e2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #define X_MAX 80 #define Y_MAX 23 @@ -9,11 +10,65 @@ #define WALL 0xB2 #define EMPTY 0xFF +#define PLAYER 0x02 using namespace std; +void move(unsigned char map[X_MAX][Y_MAX], int player[2]) +{ + int player_x = player[0]; + int player_y = player[1]; + bool waiting = true; + while(waiting) + { + if(getch() == 224) + { + switch(getch()) + { + case 72: //Freccia su + if(map[player_x][player_y-1] == EMPTY) + { + map[player_x][player_y] = EMPTY; + map[player_x][player_y-1] = PLAYER; + player_y--; + waiting = false; + } + break; + case 80: //Freccia giù + if(map[player_x][player_y+1] == EMPTY) + { + map[player_x][player_y] = EMPTY; + map[player_x][player_y+1] = PLAYER; + player_y++; + waiting = false; + } + break; + case 75: //Freccia sinistra + if(map[player_x-1][player_y] == EMPTY) + { + map[player_x][player_y] = EMPTY; + map[player_x-1][player_y] = PLAYER; + player_x--; + waiting = false; + } + break; + case 77: //Freccia destra + if(map[player_x+1][player_y] == EMPTY) + { + map[player_x][player_y] = EMPTY; + map[player_x+1][player_y] = PLAYER; + player_x++; + waiting = false; + } + break; + } + } + } + player[0] = player_x; + player[1] = player_y; +} //Aggiorna la console con la situazione corrente del gioco. -void draw(char map[X_MAX][Y_MAX]) +void draw(unsigned char map[X_MAX][Y_MAX]) { for(int y=0; y