Commit c913cde8 authored by Timothy LAIRD's avatar Timothy LAIRD

bugfix

parent 4afeeea5
......@@ -18,7 +18,7 @@ include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src)
include_directories( ${PROJECT_SOURCE_DIR}/dpd/include )
link_directories( ${PROJECT_SOURCE_DIR}/dpd )
add_executable(risk src/main-viewer.c src/networld.c src/controlpanel.c src/entity.c src/player.c src/random-map.c src/graphical-aspect.c src/window-manager.c src/menu-button.c src/main-menu.c src/int-input.c src/options-menu.c src/mission.c)
add_executable(risk src/main-viewer.c src/networld.c src/controlpanel.c src/player.c src/random-map.c src/graphical-aspect.c src/window-manager.c src/menu-button.c src/main-menu.c src/int-input.c src/options-menu.c src/mission.c)
target_link_libraries(risk raylib pthread dl rt X11 m)
......
......@@ -95,15 +95,18 @@ void Panel_drawRules(Panel * self, Main_Menu * rules){
EndDrawing();
}
void Panel_drawWin(Panel * self, Player * player){
void Panel_drawWin(Panel * self, Player * player, Mission * mission){
BeginDrawing();
Font font = GetFontDefault();
DrawText("VICTORY", (self->screenWidth*35)/100 , (self->screenHeight*15)/100 , (self->screenWidth*5)/100,BLACK);
char * victoryText = malloc(50*sizeof(char));
sprintf(victoryText, "Player %d has completed his mission and won the game", player->ID);
DrawText(victoryText, (self->screenWidth*20)/100, (self->screenHeight*45)/100, (self->screenWidth*2)/100, BLACK);
char * victoryText = malloc(sizeof(char)*100);
sprintf(victoryText, "Player %d has completed their mission and won the game\nTheir mission was : ", player->ID);
strcat(victoryText, mission->displayText);
DrawText(victoryText, (self->screenWidth*20)/100, (self->screenHeight*45)/100, (self->screenWidth*2)/100, BLACK);
free(victoryText);
UnloadFont(font);
ClearBackground(RAYWHITE);
EndDrawing();
......@@ -127,7 +130,7 @@ void Panel_drawGame(Panel * self)
{
Panel_drawNode( self, &(self->world->nodes[i]) );
}
Panel_drawBasis(self);
//Panel_drawBasis(self);
EndDrawing();
}
......
......@@ -5,6 +5,7 @@
#include "main-menu.h"
#include "options-menu.h"
#include "player.h"
#include "mission.h"
// Tools
void printVector2( Vector2 v );
......@@ -50,7 +51,7 @@ void Panel_drawOptionsMenu(Panel * self, Options_Menu * menu);
void Panel_drawRules(Panel * self, Main_Menu * rules);
//Rendering the victory screen
void Panel_drawWin(Panel * self, Player * player);
void Panel_drawWin(Panel * self, Player * player, Mission * mission);
// Control
void Panel_control(Panel * self);
......
#include "entity.h"
#ifndef ENTITY_H
#define ENTITY_H
#include "raylib.h"
//-----------------------------------//
//-- Entity Descriptor --//
//-----------------------------------//
struct Str_EntityDsc {
Color color;
};
typedef struct Str_EntityDsc EntityDsc;
struct Str_Entity {
//! Owner of the Entity (classically the player Id)
int owner;
EntityDsc descriptor;
};
typedef struct Str_Entity Entity;
#endif // ENTITY_H
\ No newline at end of file
This diff is collapsed.
......@@ -9,19 +9,19 @@
//Graphical view
//Display players' number of nodes owned, number of total troops and number of soldier to place on the bottom left of the screen
void Graphic_ShowPlayerInfo(Player * player, const int screenWidth, const int screenHeight, Font font);
void Graphic_ShowPlayerInfo(Player * player, const int screenWidth, const int screenHeight, Font * font);
//Display recrutement phase rules on the right of the screen
void Graphic_RecrutementPhase(Player * player, const int screenWidth, const int screenHeight, Font font);
void Graphic_RecrutementPhase(Player * player, const int screenWidth, const int screenHeight, Font * font);
//Display attack phase rules on the right of the screen
void Graphic_AttackPhase(Player * player, const int screenWidth, const int screenHeight, Font font);
void Graphic_AttackPhase(Player * player, const int screenWidth, const int screenHeight, Font * font);
//Display whose turn is it on the top of the screen
void Graphic_WhoseTurnIsIt(Player * player, const int screenWidth, const int screenHeight, Font font);
void Graphic_WhoseTurnIsIt(Player * player, const int screenWidth, const int screenHeight, Font * font);
//Confirm button for the recruitment phase
Rectangle Graphic_ConfirmButton(Font font);
Rectangle Graphic_ConfirmButton(Font * font);
//Animation when mouse hover node during recruitment phase
void Graphic_MouseHoverNodeRecrutement(Player * self, Vector2 mousePosition, Panel * panel);
......@@ -33,10 +33,10 @@ void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition
void Graphic_MouseHoverNodeChooseTarget(Node * originNode, Vector2 mousePosition, Panel * panel);
//Display a window to choose number of dices to involve in a fight + return the number chosen
int Graphic_ChooseNumberOfAttackers(Player * attacker, Player * defender, Node * originNode, Node * targetNode, Font font);
int Graphic_ChooseNumberOfAttackers(Player * attacker, Player * defender, Node * originNode, Node * targetNode, Font * font);
//Display animation of dice rolling + results of the dice rolling
void Graphic_diceRolling(Player * attacker, Player * defender, Node * originNode, Node * targetNode, int nbOfAttackers, int nbOfDefenders, int * listOfDices, Font font);
void Graphic_diceRolling(Player * attacker, Player * defender, Node * originNode, Node * targetNode, int nbOfAttackers, int nbOfDefenders, int * listOfDices, Font * font);
......
......@@ -3,14 +3,14 @@
#include <stdio.h>
#include <string.h>
Int_Input * Int_Input_init(char* name, int * targetInt, Rectangle inputBox){
Int_Input * Int_Input_init(char* name, int * targetInt, Rectangle * inputBox){
Int_Input * self = malloc(sizeof(Int_Input));
self->name = name;
self->targetInt = targetInt;
self->value = malloc(sizeof(char) * 32);
self->value = malloc(sizeof(char)*50);
sprintf(self->value, "%d", *targetInt);
self->valueLength = strlen(self->value);
self->inputBox = inputBox;
self->inputBox = *inputBox;
self->inputActive = false;
return self;
......@@ -24,6 +24,7 @@ void Int_Input_delete(Int_Input * self){
void Int_Input_add_char(Int_Input * self, int * key){
self->value[self->valueLength] = (char) *key;
self->valueLength++;
self->value[self->valueLength] = '\0';
}
void Int_Input_remove_char(Int_Input * self){
......
......@@ -26,7 +26,7 @@ typedef struct Str_Int_Input Int_Input;
* @param inputBox panel input box
* @return The pointer to the new Int_Input.
*/
Int_Input * Int_Input_init(char* name, int * targetInt, Rectangle inputBox);
Int_Input * Int_Input_init(char* name, int * targetInt, Rectangle *inputBox);
/**
* @brief Free an Int_Input
......
......@@ -10,25 +10,25 @@ Main_Menu * Main_Menu_init(const int screenWidth, const int screenHeight){
Rectangle playGameBtn = {(screenWidth*32)/100, (screenHeight*35)/100, (screenWidth*30)/100, (screenHeight*5)/100};
Rectangle smallPlayGameBtn = {3 + (screenWidth*32/100), 3 + (screenHeight*35/100), (screenWidth*30/100) - 6, (screenHeight*5/100) - 6};
Rectangle playGameTextBox = {smallPlayGameBtn.x + smallPlayGameBtn.width/3, smallPlayGameBtn.y, smallPlayGameBtn.width, smallPlayGameBtn.height};
Menu_Button * playGame = Menu_Button_init(playGameBtn, smallPlayGameBtn,playGameTextBox, "PLAY", game_ui);
Menu_Button * playGame = Menu_Button_init(&playGameBtn, &playGameTextBox, "PLAY", game_ui);
//Init of the options btn
Rectangle optionsBtn = {(screenWidth*32)/100, (screenHeight*45)/100, (screenWidth*30)/100, (screenHeight*5)/100};
Rectangle smallOptionsBtn = {3 + (screenWidth*32/100), 3 + (screenHeight*45/100), (screenWidth*30/100) - 6, (screenHeight*5/100) - 6};
Rectangle optionsTextBox = {smallOptionsBtn.x + smallOptionsBtn.width/4, smallOptionsBtn.y, smallOptionsBtn.width, smallOptionsBtn.height};
Menu_Button * optionsMenu = Menu_Button_init(optionsBtn, smallOptionsBtn,optionsTextBox, "OPTIONS", options);
Menu_Button * optionsMenu = Menu_Button_init(&optionsBtn, &optionsTextBox, "OPTIONS", options);
//Init of the rules btn
Rectangle rulesBtn = {(screenWidth*32)/100, (screenHeight*55)/100, (screenWidth*30)/100, (screenHeight*5)/100};
Rectangle smallRulesBtn = {3 + (screenWidth*32/100), 3 + (screenHeight*55/100), (screenWidth*30/100) - 6, (screenHeight*5/100) - 6};
Rectangle rulesTextBox = {smallRulesBtn.x + smallRulesBtn.width*4/13, smallRulesBtn.y, smallRulesBtn.width, smallRulesBtn.height};
Menu_Button * rulesMenu = Menu_Button_init(rulesBtn, smallRulesBtn,rulesTextBox, "RULES", rules);
Menu_Button * rulesMenu = Menu_Button_init(&rulesBtn, &rulesTextBox, "RULES", rules);
//Init of the exit btn
Rectangle exitBtn = {0, (screenHeight*95)/100, (screenWidth*10)/100, (screenHeight*10)/100};
Rectangle smallerExitBtn = {3, 3 +(screenHeight*95)/100, -6 + (screenWidth*10)/100, -6 + (screenHeight*10)/100};
Rectangle exitTextBox = {smallerExitBtn.x + smallerExitBtn.width/10, smallerExitBtn.y, smallerExitBtn.width, smallerExitBtn.height};
Menu_Button * terminateBtn = Menu_Button_init(exitBtn, smallerExitBtn, exitTextBox, "EXIT", exitRoute);
Menu_Button * terminateBtn = Menu_Button_init(&exitBtn, &exitTextBox, "EXIT", exitRoute);
self->buttonCount = 4;
self->buttons = malloc(sizeof(Menu_Button) * self->buttonCount);
......@@ -48,13 +48,13 @@ Main_Menu * Rules_Menu_init(const int screenWidth, const int screenHeight){
Rectangle returnBtn = {0, (screenHeight*95)/100, (screenWidth*15)/100, (screenHeight*10)/100};
Rectangle smallerReturnBtn = {3, 3 +(screenHeight*95)/100, -6 + (screenWidth*15)/100, -6 + (screenHeight*10)/100};
Rectangle returnTextBox = {smallerReturnBtn.x + smallerReturnBtn.width/7, smallerReturnBtn.y, smallerReturnBtn.width, smallerReturnBtn.height};
Menu_Button * rulesMenu = Menu_Button_init(returnBtn, smallerReturnBtn, returnTextBox, "Main Menu", main_menu);
Menu_Button * rulesMenu = Menu_Button_init(&returnBtn, &returnTextBox, "Main Menu", main_menu);
//Init of the rules text box
Rectangle rulesBox = {(screenWidth*25)/100, (screenHeight*30)/100, (screenWidth*50)/100, (screenHeight*60)/100};
Rectangle smallerRulesBox = {3 + (screenWidth*25)/100, 3 +(screenHeight*30)/100, -6 + (screenWidth*50)/100, -6 + (screenHeight*60)/100};
Rectangle rulesTextBox = {5 + (screenWidth*25)/100, 5 +(screenHeight*30)/100, -10 + (screenWidth*50)/100, -10 + (screenHeight*60)/100};
Menu_Button * rulesText = Menu_Button_init(rulesBox, smallerRulesBox, rulesTextBox,
Menu_Button * rulesText = Menu_Button_init(&rulesBox, &rulesTextBox,
"This game is an adapted and computerized version of the board game Risk.\nEach player will be given a set of territories (nodes) and a mission to win the game.\nSuccessively, each player will play their turns which happens in 2 phases :\n-\tThe recruitment phase, in which a player is given reinforcements to place on his node, and move existing soldiers, although any given nodes needs at least 1 soldier at all times.\n-\tThe attack phase, in which a player may attack neighboring nodes that he doesnt own. He will have to engage up to 3 soldiers in a fight, which resolves in throwing one die per soldier engage. The outcome will be determined by the head to head comparison of the results from the attacker and the defender.\nA player wins by accomplishing their mission.",
rules);
......
......@@ -27,7 +27,7 @@ const int screenWidth = 1700;
const int screenHeight = 800;
const int targetFPS = 60;
int game_update(NetWorld * world, Player * players, Mission * missions, Font font, Panel * panel);
int game_update(NetWorld * world, Player * players, Mission * missions, Font *font, Panel * panel);
// Game attributes
//-----------------
......@@ -61,27 +61,29 @@ int main(int nbArg, char ** arg)
Window_Manager * manager = Window_Manager_new(panel, menu, rulesMenu, optionsMenu);
Rectangle gameReturnBtn = {0,0, (screenWidth*13)/100, (screenHeight*5)/100};
Rectangle smallerGameReturnBtn = {3,3, -6 +(screenWidth*13)/100, -6 +(screenHeight*5)/100};
Menu_Button* gameReturn = Menu_Button_init(gameReturnBtn, smallerGameReturnBtn, smallerGameReturnBtn, "Main Menu", main_menu);
Rectangle gameReturnTextBox = {3,3, -6 +(screenWidth*13)/100, -6 +(screenHeight*5)/100};
Menu_Button* gameReturn = Menu_Button_init(&gameReturnBtn, &gameReturnTextBox, "Main Menu", main_menu);
while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key
{
DrawFPS(screenWidth - 100,screenHeight - 50);
Window_Manager_display(manager, world, players);
Window_Manager_display(manager, world, players, missions);
Vector2 mousePos;
int key;
switch (manager->display)
{
case main_menu:
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Vector2 mousePos = GetMousePosition();
mousePos = GetMousePosition();
manager->display = Main_Menu_detect_click(menu, &mousePos);
if(manager->display == game_ui){
//Initialising a new game with inputted parameters
*world = *NetWorld_new(nodeCount, playerCount);
Random_map(world);
Color colors[] = {BLACK, RED, BLUE, BROWN, PURPLE, PINK, YELLOW};
players = Player_newArray(playerCount, colors);
missions = Mission_newArray(playerCount, world);
char* names[] = {"Black", "Red", "Blue", "Brown", "Purple", "Pink", "Yellow"};
players = Player_newArray(playerCount, colors, names);
missions = Mission_newArray(playerCount, world, players);
//Distribute nodes to players evenly
for(int index = 0; index < world->size; index++){
Player_add_Node(&(players[index % playerCount]), &(world->nodes[index]));
......@@ -92,12 +94,13 @@ int main(int nbArg, char ** arg)
}
break;
case game_ui:
BeginDrawing();
Panel_control(panel);
mousePos = GetMousePosition();
Menu_Button_draw(gameReturn, &gameFont, screenWidth, screenHeight, RED, (screenHeight*4)/100, (screenWidth/400), true);
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mousePos, gameReturn->button)){
manager->display = gameReturn->displayOnClick;
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
mousePos = GetMousePosition();
if(CheckCollisionPointRec(mousePos, gameReturn->button)){
manager->display = gameReturn->displayOnClick;
}
}
//Draw the hitboxes for each node
for(int index = 0; index < world->size; index++){
......@@ -106,7 +109,7 @@ int main(int nbArg, char ** arg)
world->nodes[index].collisionHitbox.y = screenPosition.y - 24;
}
world->winner = game_update(world, players, missions, gameFont, panel);
world->winner = game_update(world, players, missions, &gameFont, panel);
if(world->hasWinner){
manager->display = win;
}
......@@ -114,7 +117,7 @@ int main(int nbArg, char ** arg)
case options:
//Activate/Deactivate inputs on click and detect click on the save btn
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Vector2 mousePos = GetMousePosition();
mousePos = GetMousePosition();
if(Options_Menu_check_save_click(optionsMenu, &mousePos)){
manager->display = main_menu;
for(int index = 0; index < optionsMenu->inputCount; index++){
......@@ -123,15 +126,12 @@ int main(int nbArg, char ** arg)
}
Options_Menu_check_input_click(optionsMenu, &mousePos);
}
key = GetKeyPressed();
//Check key inputs for active input fields (only accepts numerical characters)
for(int index = 0; index < optionsMenu->inputCount; index++){
if(optionsMenu->inputs[index]->inputActive){
int key = GetKeyPressed();
while (key > 0){
if ((key >= 48) && (key <= 57) && (optionsMenu->inputCount < 3)){
Int_Input_add_char(optionsMenu->inputs[index], &key);
}
key = GetCharPressed();
if ((key >= 48) && (key <= 57) && (optionsMenu->inputCount < 3)){
Int_Input_add_char(optionsMenu->inputs[index], &key);
}
if (IsKeyPressed(KEY_BACKSPACE)){
Int_Input_remove_char(optionsMenu->inputs[index]);
......@@ -141,19 +141,22 @@ int main(int nbArg, char ** arg)
break;
case rules:
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Vector2 mousePos = GetMousePosition();
mousePos = GetMousePosition();
manager->display = Main_Menu_detect_click(rulesMenu, &mousePos);
}
break;
case win:
Menu_Button_draw(gameReturn, &gameFont, screenWidth, screenHeight, RED, (screenHeight*4)/100, (screenWidth/400), true);
mousePos = GetMousePosition();
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mousePos, gameReturn->button)){
manager->display = gameReturn->displayOnClick;
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
mousePos = GetMousePosition();
if(CheckCollisionPointRec(mousePos, gameReturn->button)){
manager->display = gameReturn->displayOnClick;
}
}
break;
case exitRoute:
game_end = true;
break;
default:
break;
}
......@@ -178,7 +181,7 @@ int main(int nbArg, char ** arg)
return 0;
}
int game_update(NetWorld * world, Player * players, Mission * missions, Font font, Panel * panel)
int game_update(NetWorld * world, Player * players, Mission * missions, Font* font, Panel * panel)
{
//Game frame init
int winner = 0;
......@@ -191,7 +194,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
Rectangle missionDisplay = {screenWidth*30/100, screenHeight*95/100, screenWidth*40/100, screenHeight*10/100};
Rectangle missionTextBox = {missionDisplay.x + missionDisplay.width/5, missionDisplay.y, missionDisplay.width, missionDisplay.height};
DrawTextRec(font, missions[currentPlayer->ID].displayText, missionTextBox, (screenHeight*4)/100, (screenWidth/400), true, BLACK);
DrawTextRec(*font, missions[currentPlayer->ID].displayText, missionTextBox, (screenHeight*4)/100, (screenWidth/400), true, BLACK);
switch(currentPlayer->turnPhase){
case recruitment:
......@@ -199,7 +202,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
Graphic_MouseHoverNodeRecrutement(currentPlayer, mousePosition, panel);
if(currentPlayer->soldiers > 0){
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Player_add_soldier(currentPlayer, mousePosition);
Player_add_soldier(currentPlayer, &mousePosition);
}
}else{
//Finish the recruitment phase
......@@ -212,7 +215,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
}
}
if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)){
Player_remove_soldier(currentPlayer, mousePosition);
Player_remove_soldier(currentPlayer, &mousePosition);
}
break;
case attack:
......@@ -221,7 +224,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
if(currentPlayer->hasSelectedNode){
Graphic_MouseHoverNodeChooseTarget(currentPlayer->selectedNode, mousePosition, panel);
if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)){
Player_unselect_Node(currentPlayer, mousePosition);
Player_unselect_Node(currentPlayer, &mousePosition);
}
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Node * originNode = currentPlayer->selectedNode;
......@@ -254,13 +257,13 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
}
}else{
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Player_select_Node(currentPlayer, mousePosition);
Player_select_Node(currentPlayer, &mousePosition);
}
}
//End turn btn
Rectangle nextPhase = {200, 200, 270, 55};
DrawRectangleRec(nextPhase, GREEN);
DrawTextEx(font, "Next Turn",(Vector2){220 , 210} , 40.0, 3.0, BLACK);
DrawTextEx(*font, "Next Turn",(Vector2){220 , 210} , 40.0, 3.0, BLACK);
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
if(CheckCollisionPointRec(mousePosition, nextPhase)){
currentPlayer->turnPhase = init;
......
......@@ -2,19 +2,17 @@
#include <stdlib.h>
#include <stdio.h>
Menu_Button * Menu_Button_init(Rectangle button, Rectangle smallerButton, Rectangle textBox, char* displayText, Display display){
Menu_Button * Menu_Button_init(Rectangle* button, Rectangle* textBox, char* displayText, Display display){
Menu_Button * self = malloc(sizeof(Menu_Button));
self->button = button;
self->smallerButton = smallerButton;
self->textBox = textBox;
self->button = *button;
self->textBox = *textBox;
self->displayText = displayText;
self->displayOnClick = display;
return self;
}
void Menu_Button_draw(Menu_Button * self, Font * font, const int screenWidth, const int screenHeight, Color colour,int fontSize, int spacing, bool wordWrap){
DrawRectangleRec(self->button, colour);
DrawRectangleRec(self->smallerButton, WHITE);
DrawRectangleLinesEx(self->button, 3, colour);
DrawTextRec(*font, self->displayText, self->textBox, fontSize, spacing, wordWrap, BLACK);
}
......
......@@ -9,7 +9,6 @@ typedef enum displays Display;
struct Str_Menu_Button{
//! Panel elements
Rectangle button;
Rectangle smallerButton;
Rectangle textBox;
//! Text to display in the button
char* displayText;
......@@ -23,13 +22,12 @@ typedef struct Str_Menu_Button Menu_Button;
/**
* @brief Init a Menu_Button
* @param button Button hitbox
* @param smallerButton White layer
* @param textBox Container for displayText
* @param displayText Text to display
* @param Display Enum element referencing to a screen display
* @return A pointer to the new button
*/
Menu_Button * Menu_Button_init(Rectangle button, Rectangle smallerButton, Rectangle textBox, char* displayText, Display display);
Menu_Button * Menu_Button_init(Rectangle* button, Rectangle* textBox, char* displayText, Display display);
/**
* @brief Draw the Menu_Button
......
#include "mission.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
bool Player_conquer_threshold(NetWorld * world, Player * players, const int playerID, const int threshold){
return players[playerID].nodeCount >= threshold;
......@@ -11,7 +12,7 @@ bool Player_eliminated(NetWorld * world, Player * players, const int playerID, c
}
void Mission_init(Mission * self, const int playerID, NetWorld * world){
void Mission_init(Mission * self, const int playerID, NetWorld * world, Player * players){
char* displayText = malloc(sizeof(char)*50);
self->playerID = playerID;
......@@ -20,7 +21,7 @@ void Mission_init(Mission * self, const int playerID, NetWorld * world){
case 0:
self->mission = &Player_conquer_threshold;
self->target = world->size/2 + ((rand()%(world->size/5)) + (world->size/10));
sprintf(displayText, "\tConquer %d nodes", self->target);
sprintf(displayText, "Conquer %d nodes", self->target);
self->displayText = displayText;
break;
case 1:
......@@ -29,17 +30,18 @@ void Mission_init(Mission * self, const int playerID, NetWorld * world){
while(self->target == self->playerID){
self->target = rand()%world->playerCount;
}
sprintf(displayText, "Eliminate Player %d", self->target);
sprintf(displayText, "Eliminate Player ");
strcat(displayText, (players[self->target].name));
self->displayText = displayText;
break;
}
//return self;
}
Mission * Mission_newArray(const int playerCount, NetWorld * world){
Mission * Mission_newArray(const int playerCount, NetWorld * world, Player * players){
Mission * missionArray = malloc(sizeof(Mission) * playerCount);
for(int i = 0; i < playerCount; i++){
Mission_init((missionArray+i),i ,world);
Mission_init((missionArray+i),i ,world, players);
}
return missionArray;
}
......@@ -51,8 +53,5 @@ bool Mission_check(Mission * self, NetWorld * world, Player * players){
}
void Mission_deleteArray(Mission * array, int playerCount){
for(int i = 0 ; i<playerCount; i++){
free((array+i)->displayText);
}
free(array);
}
\ No newline at end of file
......@@ -5,20 +5,39 @@
#include "player.h"
struct Str_Mission{
//! Boolean function to check if the mission is accomplished
bool (*mission)(NetWorld*, Player*, const int, const int);
//! Player needing to accomplish the mission
int playerID;
//! Relevant target int for mission (node count, player ID, ...)
int target;
//! Mission Description
char* displayText;
};
typedef struct Str_Mission Mission;
void Mission_init(Mission * self, const int playerID, NetWorld * world);
/**
* @brief Initialise a new Mission.
* @return The pointer to the new Mission.
*/
void Mission_init(Mission * self, const int playerID, NetWorld * world, Player * players);
/**
* @brief Check if the missions is completed.
* @return A boolean.
*/
bool Mission_check(Mission * self, NetWorld * world, Player * players);
/**
* @brief Void a mission array
*/
void Mission_deleteArray(Mission * array, int playerCount);
Mission * Mission_newArray(const int playerCount, NetWorld * world);
/**
* @brief Initialise a new Mission array
* @return The pointer to the new Mission array.
*/
Mission * Mission_newArray(const int playerCount, NetWorld * world, Player * players);
#endif
\ No newline at end of file
......@@ -7,11 +7,11 @@ Options_Menu * Options_Menu_init(int * playerCount, int * nodeCount, const int s
//Input for the player count
Rectangle playerCountInputBox = {(screenWidth*32)/100, (screenHeight*35)/100, (screenWidth*30)/100, (screenHeight*5)/100};
Int_Input * playerCountInput = Int_Input_init("Nb. of Players : ", playerCount, playerCountInputBox);
Int_Input * playerCountInput = Int_Input_init("Nb. of Players : ", playerCount, &playerCountInputBox);
//Input for the node count
Rectangle nodeCountInputBox = {(screenWidth*32)/100, (screenHeight*45)/100, (screenWidth*30)/100, (screenHeight*5)/100};
Int_Input * nodeCountInput = Int_Input_init("Nb. of Nodes : ", nodeCount, nodeCountInputBox);
Int_Input * nodeCountInput = Int_Input_init("Nb. of Nodes : ", nodeCount, &nodeCountInputBox);
self->inputCount = 2;
self->inputs = malloc(sizeof(Int_Input) * self->inputCount);
......
......@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <stdio.h>
void Player_construct(Player * self, int i, Color color)
void Player_construct(Player * self, int i, Color color, char* name)
{
self->ID = i;
self->nodes = malloc(sizeof(Node*));
......@@ -13,32 +13,29 @@ void Player_construct(Player * self, int i, Color color)
self->soldiers = 0;
self->selectedNode = malloc(sizeof(Node));
self->hasSelectedNode = false;
self->name = name;
}
Player * Player_new()
{
Player * player= malloc( sizeof(Player) );
Player_construct(player, 0, BLACK);
Player_construct(player, 0, BLACK, "Black");
return player;
}
Player * Player_newArray(int size, Color color[])
Player * Player_newArray(int size, Color color[], char* names[])
{
size= fmaxf(1, size);
Player * p= malloc( sizeof(Player)*size );
for(int i=0 ; i < size ; ++i )
{
Player_construct( &(p[i]), i, color[i]);
Player_construct( &(p[i]), i, color[i], names[i]);
}
return p;
}
void Players_delete(Player * player, int size)
{
for(int i = 0 ; i < size ; i++){
//free((player+i)->nodes);
//free((player+i)->selectedNode);
}
free(player);
}
......@@ -101,10 +98,10 @@ void Player_end_turn(Player * self){
self->turnPhase = init;
}
void Player_add_soldier(Player * self, Vector2 mousePos){
void Player_add_soldier(Player * self, Vector2 * mousePos){
for(int nodeIndex = 0; nodeIndex < self->nodeCount; nodeIndex++){
Node* currentNode = self->nodes[nodeIndex];
if(CheckCollisionPointRec(mousePos, currentNode->collisionHitbox)){
if(CheckCollisionPointRec(*mousePos, currentNode->collisionHitbox)){
currentNode->soldiersToAdd++;
self->soldiers--;
break;
......@@ -112,10 +109,10 @@ void Player_add_soldier(Player * self, Vector2 mousePos){
}
}
void Player_remove_soldier(Player * self, Vector2 mousePos){
void Player_remove_soldier(Player * self, Vector2 * mousePos){
for(int nodeIndex = 0; nodeIndex < self->nodeCount; nodeIndex++){
Node* currentNode = self->nodes[nodeIndex];
if(CheckCollisionPointRec(mousePos, currentNode->collisionHitbox) && currentNode->soldiers > 0){
if(CheckCollisionPointRec(*mousePos, currentNode->collisionHitbox) && currentNode->soldiers > 0){
if(currentNode->soldiersToAdd > 0){
currentNode->soldiersToAdd--;
self->soldiers++;
......@@ -125,10 +122,10 @@ void Player_remove_soldier(Player * self, Vector2 mousePos){
}
}
void Player_select_Node(Player * self, Vector2 mousePos){
void Player_select_Node(Player * self, Vector2 * mousePos){
for(int nodeIndex = 0; nodeIndex < self->nodeCount; nodeIndex++){
Node* currentNode = self->nodes[nodeIndex];
if(CheckCollisionPointRec(mousePos, currentNode->collisionHitbox)){
if(CheckCollisionPointRec(*mousePos, currentNode->collisionHitbox)){
if(currentNode->soldiers > 1){
self->hasSelectedNode = true;
self->selectedNode = currentNode;
......@@ -138,10 +135,10 @@ void Player_select_Node(Player * self, Vector2 mousePos){
}
}
void Player_unselect_Node(Player * self, Vector2 mousePos){
void Player_unselect_Node(Player * self, Vector2 * mousePos){
for(int nodeIndex = 0; nodeIndex < self->nodeCount; nodeIndex++){
Node* currentNode = self->nodes[nodeIndex];
if(CheckCollisionPointRec(mousePos, currentNode->collisionHitbox)){
if(CheckCollisionPointRec(*mousePos, currentNode->collisionHitbox)){
self->hasSelectedNode = false;
}
}
......@@ -155,9 +152,8 @@ void Player_confirm_recrutement(Player * self){
};
int * Player_attack_Node(Player * self, Player * defender, Node * originNode, Node * targetNode, int numberOfAttackers){
int * Player_attack_Node(Player * self, Player * defender, Node * originNode, Node * targetNode, const int attackersCount){
int * listOfDices = malloc(20*sizeof(int));
int attackersCount = numberOfAttackers;
int defendersCount = targetNode->soldiers;
int attDiceRolls[attackersCount];
int defDiceRolls[defendersCount];
......
......@@ -22,6 +22,7 @@ struct Str_Player{
//! Player's selected node for the attack phase
Node * selectedNode;
bool hasSelectedNode;
char* name;
};
typedef struct Str_Player Player;
......@@ -32,7 +33,7 @@ typedef struct Str_Player Player;
* @param self an empty Player not yet constructed.
* @return The pointer to the new Player.
*/
void Player_construct(Player * self, int id, Color color);
void Player_construct(Player * self, int id, Color color, char* name);
/**
* @brief Allocate the memory to store a Player
......@@ -44,7 +45,7 @@ Player * Player_new();
* @brief Allocate 'size' Players.
* @return The pointer to the new array of 'size' Player.
*/
Player * Player_newArray(int size, Color colors[]);
Player * Player_newArray(int size, Color colors[], char* names[]);
/**
* @brief Destructor.
......@@ -93,28 +94,28 @@ void Player_end_turn(Player * self);
* @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked
*/
void Player_add_soldier(Player * self, Vector2 mousePos);
void Player_add_soldier(Player * self, Vector2 * mousePos);
/**
* @brief Remove a soldier from a player's node
* @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked
*/
void Player_remove_soldier(Player * self, Vector2 mousePos);
void Player_remove_soldier(Player * self, Vector2 * mousePos);
/**
* @brief A player selects a node
* @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked
*/
void Player_select_Node(Player * self, Vector2 mousePos);
void Player_select_Node(Player * self, Vector2 * mousePos);
/**
* @brief A player unselects a node
* @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked
*/
void Player_unselect_Node(Player * self, Vector2 mousePos);
void Player_unselect_Node(Player * self, Vector2 * mousePos);
/**
* @brief Attack declaration
......@@ -124,7 +125,7 @@ void Player_unselect_Node(Player * self, Vector2 mousePos);
* @param targetNode The defender's node
* @param numberOfAttackers Number of attacking soldiers
*/
int * Player_attack_Node(Player * self, Player * defender, Node * originNode, Node * targetNode, int numberOfAttackers);
int * Player_attack_Node(Player * self, Player * defender, Node * originNode, Node * targetNode, const int attackersCount);
/**
* @brief Confirm placement of soldiers
......
......@@ -17,7 +17,7 @@ void Window_Manager_delete(Window_Manager * manager){
free(manager);
}
void Window_Manager_display(Window_Manager * self, NetWorld * world, Player * players){
void Window_Manager_display(Window_Manager * self, NetWorld * world, Player * players, Mission * missions){
switch(self->display){
case main_menu:
Panel_drawMainMenu(self->panel, self->menu);
......@@ -32,7 +32,7 @@ void Window_Manager_display(Window_Manager * self, NetWorld * world, Player * pl
Panel_drawRules(self->panel, self->rules);
break;
case win:
Panel_drawWin(self->panel, &players[world->winner]);
Panel_drawWin(self->panel, players+world->winner, missions+world->winner);
break;
default:
break;
......
......@@ -3,6 +3,7 @@
#include "networld.h"
#include "controlpanel.h"
#include "mission.h"
struct Str_Window_Manager{
//! frame to display
......@@ -38,6 +39,6 @@ void Window_Manager_delete(Window_Manager * manager);
* @brief Displays the appropriate frame
* @param self The manager context
*/
void Window_Manager_display(Window_Manager * self, NetWorld * world, Player * players);
void Window_Manager_display(Window_Manager * self, NetWorld * world, Player * players, Mission * missions);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment