mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 18:03:14 +02:00
Penguins Restoration Project 1%: Making it work under Linux
This commit is contained in:
parent
a1de1a93d7
commit
33150ba9d8
BIN
EPFU/src/a.out
Executable file
BIN
EPFU/src/a.out
Executable file
Binary file not shown.
@ -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
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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++)
|
||||
{
|
||||
|
||||
@ -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 <windows.h>
|
||||
//#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)
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
#include "game_struct.h"
|
||||
#include <windows.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user