diff --git a/EPFU/src/a.out b/EPFU/src/a.out new file mode 100755 index 00000000..fea9187b Binary files /dev/null and b/EPFU/src/a.out differ diff --git a/EPFU/src/checkmove.c b/EPFU/src/checkmove.c index 672719e3..bcc331fb 100644 --- a/EPFU/src/checkmove.c +++ b/EPFU/src/checkmove.c @@ -191,7 +191,11 @@ int checkMovement(Movement_coordinates c, GameState Game) printf("You can't move the penguin diagonally!\n"); return 0; } + + printf("Something went really bad in function checkMovement()"); + return 0; } + int ourPenguins(GameState Game) { int i, j; // This function checks how many penguins we have and returns this number diff --git a/EPFU/src/command_line_parameters.c b/EPFU/src/command_line_parameters.c index 1df8f028..faa9d09b 100644 --- a/EPFU/src/command_line_parameters.c +++ b/EPFU/src/command_line_parameters.c @@ -23,7 +23,7 @@ int isItBoardParameter(GameState Game, int command_number) { int len = strlen(Game.command_line[command_number]); int j = 0, i; - char extension[4]; + char extension[4] = ""; int answer = 0; memset(extension, 0, strlen(extension)); for(i = len - 4; i < len; i++) @@ -40,7 +40,7 @@ int isItBoardParameter(GameState Game, int command_number) char** handlingParameters(int argc, char *argv[], GameState Game) { - int i, j; + int i; for(i = 1; i < argc; i++) { strcpy(Game.command_line[i - 1], argv[i]); @@ -76,7 +76,6 @@ int checkParameterType(GameState *Game, int command_number) if(Game -> file_type == 0) // First file is input board file { printf("It is an input board file!\n"); - char line[255]; Game -> file_type = Game -> file_type + 1; printf("%s", Game -> command_line[command_number]); Game -> input_board_command_number = command_number; @@ -85,7 +84,6 @@ int checkParameterType(GameState *Game, int command_number) }else if(Game -> file_type == 1) // Second file is output board file { printf("It is an output board file!\n"); - char line[255]; if(!strcmp(Game -> command_line[Game -> input_board_command_number], Game -> command_line[command_number])) // If the input and board file are the same // then we open it in r+ mode { diff --git a/EPFU/src/generate.c b/EPFU/src/generate.c index 9f3f32f9..5a0bfe49 100644 --- a/EPFU/src/generate.c +++ b/EPFU/src/generate.c @@ -39,9 +39,9 @@ Field** randomizeFields(GameState Game) return Game.board; } -char** generateCommandLine(GameState Game, int argc, char *argv[]) +char** generateCommandLine(GameState Game, int argc) { - int i, j; + int i; Game.command_line = (char **)malloc(argc * sizeof(char*)); for(i = 0; i < argc; i++) { diff --git a/EPFU/src/main.c b/EPFU/src/main.c index 978644fb..7da9dea4 100644 --- a/EPFU/src/main.c +++ b/EPFU/src/main.c @@ -9,9 +9,11 @@ #include "movement.c" #include "command_line_parameters.c" #include "game_struct.h" // Header file for file where we store all our structures -#include -//#define INTERACTIVE -#define AUTOMATIC +#ifdef _WIN32 +#include "windows.h" +#endif +#define INTERACTIVE +//#define AUTOMATIC int interactive_mode(GameState Game) { @@ -68,7 +70,12 @@ int interactive_mode(GameState Game) }else printf("It's a tie!\n"); return 0; } -int main(int argc, char *argv[]) +int main( + #ifdef AUTOMATIC + int argc, + char *argv[] + #endif + ) { GameState Game; #ifdef AUTOMATIC @@ -77,7 +84,7 @@ int main(int argc, char *argv[]) if(argc != 1) { // Creating a Game variable that will hold informations needed to run the program - Game.command_line = generateCommandLine(Game, argc, argv); // Generates 2D dynamic array of strings + Game.command_line = generateCommandLine(Game, argc); // Generates 2D dynamic array of strings handlingParameters(argc, argv, Game); // Stores all commands inside Game.command_line array Game.file_type = 0; // We use this variable to check if the file we open is inputboardfile or outputboardfile Game.phase = 0; // We use this variable to check if current game phase is placement (1) or movement(2) diff --git a/EPFU/src/printing.c b/EPFU/src/printing.c index 3e588445..94186eb1 100644 --- a/EPFU/src/printing.c +++ b/EPFU/src/printing.c @@ -1,8 +1,11 @@ #include "game_struct.h" -#include +#ifdef _WIN32 +#include "windows.h" +#endif int printBoard(GameState Game) { + #ifdef _WIN32 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO consoleInfo; WORD saved_attributes; @@ -46,6 +49,39 @@ int printBoard(GameState Game) printf("\n"); } printf("\n"); + #else + system("clear || cls"); + printf("\nCurrent board status:\n"); + printf(" "); + + for (int i = 0; i < Game.board_width; i++) + { + printf("%d ", i); // Here we print the number of columns + } + printf("\n"); + for(int i = 0; i < Game.board_height; i++) + { + printf("%d ", i); // Here we print the number of rows + for(int j = 0; j < Game.board_width; j++) + { + if ((Game.board[i][j].fish_no == 0) && (Game.board[i][j].player_no == 0)) + { + printf("~ "); // If there are no penguins and fish on the field we print the 'wave' + } + else if(Game.board[i][j].fish_no == 0) + { + printf("P%d ",Game.board[i][j].player_no); + } + else + { + printf("F%d ",Game.board[i][j].fish_no); + } + } + printf("\n"); + } + printf("\n"); + + #endif ScoreBoard(Game); return 0; } diff --git a/EPFU/src/userinteraction.c b/EPFU/src/userinteraction.c index fc1553c3..66303f69 100644 --- a/EPFU/src/userinteraction.c +++ b/EPFU/src/userinteraction.c @@ -1,5 +1,9 @@ #include "game_struct.h" + +#ifdef _WIN32 #include "windows.h" +#endif + void welcome() { printf("Hey there! Lets play ''HEY THAT'S MY FISH'' \n"); @@ -18,6 +22,7 @@ END */ int ScoreBoard(GameState Game) { + #ifdef _WIN32 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO consoleInfo; WORD saved_attributes; @@ -32,6 +37,11 @@ int ScoreBoard(GameState Game) SetConsoleTextAttribute(hConsole, 6); printf("Player number 2 score: %d\n\n", Game.player_data[1].score); SetConsoleTextAttribute(hConsole, saved_attributes); + #else + printf("Player number 1 score: %d\n", Game.player_data[0].score); + printf("Player number 2 score: %d\n\n", Game.player_data[1].score); + + #endif return 1; }