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) ...@@ -18,7 +18,7 @@ include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src)
include_directories( ${PROJECT_SOURCE_DIR}/dpd/include ) include_directories( ${PROJECT_SOURCE_DIR}/dpd/include )
link_directories( ${PROJECT_SOURCE_DIR}/dpd ) 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) target_link_libraries(risk raylib pthread dl rt X11 m)
......
...@@ -95,15 +95,18 @@ void Panel_drawRules(Panel * self, Main_Menu * rules){ ...@@ -95,15 +95,18 @@ void Panel_drawRules(Panel * self, Main_Menu * rules){
EndDrawing(); EndDrawing();
} }
void Panel_drawWin(Panel * self, Player * player){ void Panel_drawWin(Panel * self, Player * player, Mission * mission){
BeginDrawing(); BeginDrawing();
Font font = GetFontDefault(); Font font = GetFontDefault();
DrawText("VICTORY", (self->screenWidth*35)/100 , (self->screenHeight*15)/100 , (self->screenWidth*5)/100,BLACK); 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); UnloadFont(font);
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
EndDrawing(); EndDrawing();
...@@ -127,7 +130,7 @@ void Panel_drawGame(Panel * self) ...@@ -127,7 +130,7 @@ void Panel_drawGame(Panel * self)
{ {
Panel_drawNode( self, &(self->world->nodes[i]) ); Panel_drawNode( self, &(self->world->nodes[i]) );
} }
Panel_drawBasis(self); //Panel_drawBasis(self);
EndDrawing(); EndDrawing();
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "main-menu.h" #include "main-menu.h"
#include "options-menu.h" #include "options-menu.h"
#include "player.h" #include "player.h"
#include "mission.h"
// Tools // Tools
void printVector2( Vector2 v ); void printVector2( Vector2 v );
...@@ -50,7 +51,7 @@ void Panel_drawOptionsMenu(Panel * self, Options_Menu * menu); ...@@ -50,7 +51,7 @@ void Panel_drawOptionsMenu(Panel * self, Options_Menu * menu);
void Panel_drawRules(Panel * self, Main_Menu * rules); void Panel_drawRules(Panel * self, Main_Menu * rules);
//Rendering the victory screen //Rendering the victory screen
void Panel_drawWin(Panel * self, Player * player); void Panel_drawWin(Panel * self, Player * player, Mission * mission);
// Control // Control
void Panel_control(Panel * self); 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
...@@ -12,17 +12,17 @@ ...@@ -12,17 +12,17 @@
#include "raylib.h" #include "raylib.h"
void Graphic_ShowPlayerInfo(Player *player, int screenWidth, int screenHeight, Font font) void Graphic_ShowPlayerInfo(Player *player, int screenWidth, int screenHeight, Font *font)
{ {
Rectangle rec = {0, screenHeight - 250, 250, 250}; //Draw current player number on the bottom left Rectangle rec = {0, screenHeight - 250, 250, 250}; //Draw current player number on the bottom left
DrawRectangleLinesEx(rec, 10, player->color); DrawRectangleLinesEx(rec, 10, player->color);
char *playerNumber = malloc(20 * sizeof(char)); char *playerNumber = malloc(20 * sizeof(char));
sprintf(playerNumber, "Player %d", player->ID); sprintf(playerNumber, "Player %d", player->ID);
DrawTextEx(font, playerNumber, (Vector2){35, screenHeight - 240}, 30.0, 3.0, player->color); DrawTextEx(*font, playerNumber, (Vector2){35, screenHeight - 240}, 30.0, 3.0, player->color);
char *soldierNumber = malloc(40 * sizeof(char)); //Draw current player number of soldiers char *soldierNumber = malloc(40 * sizeof(char)); //Draw current player number of soldiers
sprintf(soldierNumber, "Soldiers left %d", player->soldiers); sprintf(soldierNumber, "Soldiers left %d", player->soldiers);
DrawTextEx(font, soldierNumber, (Vector2){15, screenHeight - 180}, 24.0, 3.0, player->color); DrawTextEx(*font, soldierNumber, (Vector2){15, screenHeight - 180}, 24.0, 3.0, player->color);
int totalTroops = 0; int totalTroops = 0;
for (int i = 0; i < player->nodeCount; i++) for (int i = 0; i < player->nodeCount; i++)
...@@ -31,11 +31,11 @@ void Graphic_ShowPlayerInfo(Player *player, int screenWidth, int screenHeight, F ...@@ -31,11 +31,11 @@ void Graphic_ShowPlayerInfo(Player *player, int screenWidth, int screenHeight, F
} }
char *str_totalTroops = malloc(40 * sizeof(char)); //Draw current player number of total troops owned char *str_totalTroops = malloc(40 * sizeof(char)); //Draw current player number of total troops owned
sprintf(str_totalTroops, "Total Troops %d", totalTroops); sprintf(str_totalTroops, "Total Troops %d", totalTroops);
DrawTextEx(font, str_totalTroops, (Vector2){15, screenHeight - 150}, 24.0, 3.0, player->color); DrawTextEx(*font, str_totalTroops, (Vector2){15, screenHeight - 150}, 24.0, 3.0, player->color);
char *str_nodeCount = malloc(40 * sizeof(char)); //Draw current player number of nodes owned char *str_nodeCount = malloc(40 * sizeof(char)); //Draw current player number of nodes owned
sprintf(str_nodeCount, "Nodes owned %d", player->nodeCount); sprintf(str_nodeCount, "Nodes owned %d", player->nodeCount);
DrawTextEx(font, str_nodeCount, (Vector2){15, screenHeight - 120}, 24.0, 3.0, player->color); DrawTextEx(*font, str_nodeCount, (Vector2){15, screenHeight - 120}, 24.0, 3.0, player->color);
free(playerNumber); free(playerNumber);
free(soldierNumber); free(soldierNumber);
...@@ -43,38 +43,38 @@ void Graphic_ShowPlayerInfo(Player *player, int screenWidth, int screenHeight, F ...@@ -43,38 +43,38 @@ void Graphic_ShowPlayerInfo(Player *player, int screenWidth, int screenHeight, F
free(str_nodeCount); free(str_nodeCount);
} }
void Graphic_RecrutementPhase(Player *player, int screenWidth, int screenHeight, Font font) void Graphic_RecrutementPhase(Player *player, int screenWidth, int screenHeight, Font *font)
{ {
Rectangle rec = {screenWidth - 300, 100, 300, 400}; //Display recruitment phase rules Rectangle rec = {screenWidth - 300, 100, 300, 400}; //Display recruitment phase rules
DrawRectangleLinesEx(rec, 10, player->color); DrawRectangleLinesEx(rec, 10, player->color);
DrawTextEx(font, "Recrutement Phase", (Vector2){screenWidth - 275, 120}, 23.0, 3.0, player->color); DrawTextEx(*font, "Recrutement Phase", (Vector2){screenWidth - 275, 120}, 23.0, 3.0, player->color);
DrawTextRec(font, " LEFT click on one of your node to recruit a soldier", (Rectangle){screenWidth - 285, 175, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(*font, " LEFT click on one of your node to recruit a soldier", (Rectangle){screenWidth - 285, 175, 270, 100}, 20.0, 3.0, true, player->color);
DrawTextRec(font, " RIGHT click on the same node to remove the soldier", (Rectangle){screenWidth - 285, 295, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(*font, " RIGHT click on the same node to remove the soldier", (Rectangle){screenWidth - 285, 295, 270, 100}, 20.0, 3.0, true, player->color);
DrawTextRec(font, " click Confirm once finished", (Rectangle){screenWidth - 285, 415, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(*font, " click Confirm once finished", (Rectangle){screenWidth - 285, 415, 270, 100}, 20.0, 3.0, true, player->color);
} }
void Graphic_AttackPhase(Player *player, int screenWidth, int screenHeight, Font font) void Graphic_AttackPhase(Player *player, int screenWidth, int screenHeight, Font *font)
{ {
Rectangle rec = {screenWidth - 300, 100, 300, 450}; //Display attack phase rules Rectangle rec = {screenWidth - 300, 100, 300, 450}; //Display attack phase rules
DrawRectangleLinesEx(rec, 10, player->color); DrawRectangleLinesEx(rec, 10, player->color);
DrawTextEx(font, "Attack Phase", (Vector2){screenWidth - 265, 120}, 23.0, 3.0, player->color); DrawTextEx(*font, "Attack Phase", (Vector2){screenWidth - 265, 120}, 23.0, 3.0, player->color);
DrawTextRec(font, " FIRST click on the node you want to attack from", (Rectangle){screenWidth - 285, 175, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(*font, " FIRST click on the node you want to attack from", (Rectangle){screenWidth - 285, 175, 270, 100}, 20.0, 3.0, true, player->color);
DrawTextRec(font, " THEN click on one of neighbouring node you want to attack", (Rectangle){screenWidth - 285, 295, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(*font, " THEN click on one of neighbouring node you want to attack", (Rectangle){screenWidth - 285, 295, 270, 100}, 20.0, 3.0, true, player->color);
DrawTextRec(font, " click Next Turn once finished all your attacks", (Rectangle){screenWidth - 285, 415, 270, 100}, 20.0, 3.0, true, player->color); DrawTextRec(*font, " click Next Turn once finished all your attacks", (Rectangle){screenWidth - 285, 415, 270, 100}, 20.0, 3.0, true, player->color);
} }
void Graphic_WhoseTurnIsIt(Player *player, int screenWidth, int screenHeight, Font font) void Graphic_WhoseTurnIsIt(Player *player, int screenWidth, int screenHeight, Font *font)
{ {
char *whoseTurn = malloc(20 * sizeof(char)); //Display whose turn is it char *whoseTurn = malloc(20 * sizeof(char)); //Display whose turn is it
sprintf(whoseTurn, "Player %d Turn", player->ID); sprintf(whoseTurn, "Player %d Turn", player->ID);
DrawTextEx(font, whoseTurn, (Vector2){screenWidth / 2 - (MeasureTextEx(font, whoseTurn, 50.0, 3.0).x) / 2, 30}, 50.0, 3.0, player->color); DrawTextEx(*font, whoseTurn, (Vector2){screenWidth / 2 - (MeasureTextEx(*font, whoseTurn, 50.0, 3.0).x) / 2, 30}, 50.0, 3.0, player->color);
free(whoseTurn); free(whoseTurn);
} }
Rectangle Graphic_ConfirmButton(Font font) Rectangle Graphic_ConfirmButton(Font *font)
{ //Confirm button for the recruitment phase { //Confirm button for the recruitment phase
Rectangle nextPhase = {200, 200, 220, 55}; Rectangle nextPhase = {200, 200, 220, 55};
DrawRectangleRec(nextPhase, GREEN); DrawRectangleRec(nextPhase, GREEN);
DrawTextEx(font, "Confirm", (Vector2){220, 210}, 40.0, 3.0, BLACK); DrawTextEx(*font, "Confirm", (Vector2){220, 210}, 40.0, 3.0, BLACK);
return nextPhase; return nextPhase;
} }
...@@ -135,7 +135,7 @@ void Graphic_MouseHoverNodeChooseTarget(Node *originNode, Vector2 mousePosition, ...@@ -135,7 +135,7 @@ void Graphic_MouseHoverNodeChooseTarget(Node *originNode, Vector2 mousePosition,
} }
} }
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)
{ {
const int screenWidth = 1700; const int screenWidth = 1700;
const int screenHeight = 800; const int screenHeight = 800;
...@@ -158,16 +158,16 @@ int Graphic_ChooseNumberOfAttackers(Player *attacker, Player *defender, Node *or ...@@ -158,16 +158,16 @@ int Graphic_ChooseNumberOfAttackers(Player *attacker, Player *defender, Node *or
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
Vector2 mousePosition = GetMousePosition(); Vector2 mousePosition = GetMousePosition();
DrawTextEx(font, whoseTurnToAttack, (Vector2){screenWidth / 2 - (MeasureTextEx(font, whoseTurnToAttack, 50.0, 3.0).x) + 100, 70}, 50.0, 3.0, attacker->color); DrawTextEx(*font, whoseTurnToAttack, (Vector2){screenWidth / 2 - (MeasureTextEx(*font, whoseTurnToAttack, 50.0, 3.0).x) + 100, 70}, 50.0, 3.0, attacker->color);
DrawTextEx(font, whoseTurnToDefend, (Vector2){screenWidth / 2 + 100, 70}, 50.0, 3.0, defender->color); DrawTextEx(*font, whoseTurnToDefend, (Vector2){screenWidth / 2 + 100, 70}, 50.0, 3.0, defender->color);
DrawText("How many dices do you want to involve in the fight ?", screenWidth / 2 - (MeasureTextEx(font, "How many dice do you want to involve in the fight ?", 30.0, 3.0).x) / 2 + 50, 150, 30, attacker->color); DrawText("How many dices do you want to involve in the fight ?", screenWidth / 2 - (MeasureTextEx(*font, "How many dice do you want to involve in the fight ?", 30.0, 3.0).x) / 2 + 50, 150, 30, attacker->color);
for (int i = 1; i < originNode->soldiersToAdd + originNode->soldiers; i++) for (int i = 1; i < originNode->soldiersToAdd + originNode->soldiers; i++)
{ {
DrawRectangleRec(nbAttackerRectangle[i], BLACK); DrawRectangleRec(nbAttackerRectangle[i], BLACK);
char str_i[5]; char str_i[5];
sprintf(str_i, "%d", i); sprintf(str_i, "%d", i);
DrawTextEx(font, str_i, (Vector2){nbAttackerRectangle[i].x + 55, nbAttackerRectangle[i].y + 5}, 70.0, 3.0, WHITE); DrawTextEx(*font, str_i, (Vector2){nbAttackerRectangle[i].x + 55, nbAttackerRectangle[i].y + 5}, 70.0, 3.0, WHITE);
if (CheckCollisionPointRec(mousePosition, nbAttackerRectangle[i])) if (CheckCollisionPointRec(mousePosition, nbAttackerRectangle[i]))
{ {
DrawRectangleLinesEx(nbAttackerRectangle[i], 5, GREEN); DrawRectangleLinesEx(nbAttackerRectangle[i], 5, GREEN);
...@@ -185,7 +185,7 @@ int Graphic_ChooseNumberOfAttackers(Player *attacker, Player *defender, Node *or ...@@ -185,7 +185,7 @@ int Graphic_ChooseNumberOfAttackers(Player *attacker, Player *defender, Node *or
} }
} }
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)
{ {
const int screenWidth = 1700; const int screenWidth = 1700;
...@@ -251,12 +251,12 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N ...@@ -251,12 +251,12 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTextEx(font, whoseTurnToAttack, (Vector2){250, 100}, 40.0, 3.0, attacker->color); DrawTextEx(*font, whoseTurnToAttack, (Vector2){250, 100}, 40.0, 3.0, attacker->color);
DrawTextEx(font, whoseTurnToDefend, (Vector2){screenWidth - 700, 100}, 40.0, 3.0, defender->color); DrawTextEx(*font, whoseTurnToDefend, (Vector2){screenWidth - 700, 100}, 40.0, 3.0, defender->color);
DrawTextEx(font, " attacker", (Vector2){250, 150}, 30.0, 3.0, attacker->color); DrawTextEx(*font, " attacker", (Vector2){250, 150}, 30.0, 3.0, attacker->color);
DrawTextEx(font, " defender", (Vector2){screenWidth - 700, 150}, 30.0, 3.0, defender->color); DrawTextEx(*font, " defender", (Vector2){screenWidth - 700, 150}, 30.0, 3.0, defender->color);
DrawRectangleRec(skipAnimation, BLUE); DrawRectangleRec(skipAnimation, BLUE);
DrawTextEx(font, "Skip Animation", (Vector2){screenWidth / 2 - 115, 210}, 18.0, 3.0, BLACK); DrawTextEx(*font, "Skip Animation", (Vector2){screenWidth / 2 - 115, 210}, 18.0, 3.0, BLACK);
for (int i = 0; i < nbOfAttackers; i++) for (int i = 0; i < nbOfAttackers; i++)
{ {
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
...@@ -302,12 +302,12 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N ...@@ -302,12 +302,12 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTextEx(font, whoseTurnToAttack, (Vector2){250, 100}, 40.0, 3.0, attacker->color); DrawTextEx(*font, whoseTurnToAttack, (Vector2){250, 100}, 40.0, 3.0, attacker->color);
DrawTextEx(font, whoseTurnToDefend, (Vector2){screenWidth - 700, 100}, 40.0, 3.0, defender->color); DrawTextEx(*font, whoseTurnToDefend, (Vector2){screenWidth - 700, 100}, 40.0, 3.0, defender->color);
DrawTextEx(font, " attacker", (Vector2){250, 150}, 30.0, 3.0, attacker->color); DrawTextEx(*font, " attacker", (Vector2){250, 150}, 30.0, 3.0, attacker->color);
DrawTextEx(font, " defender", (Vector2){screenWidth - 700, 150}, 30.0, 3.0, defender->color); DrawTextEx(*font, " defender", (Vector2){screenWidth - 700, 150}, 30.0, 3.0, defender->color);
DrawRectangleRec(skipResult, BLUE); DrawRectangleRec(skipResult, BLUE);
DrawTextEx(font, "Skip Result", (Vector2){screenWidth / 2 - 100, 210}, 18.0, 3.0, BLACK); DrawTextEx(*font, "Skip Result", (Vector2){screenWidth / 2 - 100, 210}, 18.0, 3.0, BLACK);
for (int i = 0; i < nbOfAttackers; i++) for (int i = 0; i < nbOfAttackers; i++)
{ {
switch (listOfDices[i]) switch (listOfDices[i])
...@@ -315,32 +315,32 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N ...@@ -315,32 +315,32 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N
case 1: case 1:
frameRec.y = 9 * (float)diceTexture.height / 9; frameRec.y = 9 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
DrawTextEx(font, "1", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "1", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 2: case 2:
frameRec.y = 1 * (float)diceTexture.height / 9; frameRec.y = 1 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
DrawTextEx(font, "2", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "2", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 3: case 3:
frameRec.y = 2 * (float)diceTexture.height / 9; frameRec.y = 2 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
DrawTextEx(font, "3", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "3", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 4: case 4:
frameRec.y = 3 * (float)diceTexture.height / 9; frameRec.y = 3 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
DrawTextEx(font, "4", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "4", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 5: case 5:
frameRec.y = 4 * (float)diceTexture.height / 9; frameRec.y = 4 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
DrawTextEx(font, "5", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "5", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 6: case 6:
frameRec.y = 5 * (float)diceTexture.height / 9; frameRec.y = 5 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceAttacker[i], WHITE);
DrawTextEx(font, "6", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "6", (Vector2){positionDiceAttacker[i].x + 30, positionDiceAttacker[i].y + 100}, 50.0, 3.0, BLACK);
break; break;
default: default:
...@@ -354,32 +354,32 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N ...@@ -354,32 +354,32 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N
case 1: case 1:
frameRec.y = 9 * (float)diceTexture.height / 9; frameRec.y = 9 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
DrawTextEx(font, "1", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "1", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 2: case 2:
frameRec.y = 1 * (float)diceTexture.height / 9; frameRec.y = 1 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
DrawTextEx(font, "2", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "2", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 3: case 3:
frameRec.y = 2 * (float)diceTexture.height / 9; frameRec.y = 2 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
DrawTextEx(font, "3", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "3", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 4: case 4:
frameRec.y = 3 * (float)diceTexture.height / 9; frameRec.y = 3 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
DrawTextEx(font, "4", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "4", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 5: case 5:
frameRec.y = 4 * (float)diceTexture.height / 9; frameRec.y = 4 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
DrawTextEx(font, "5", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "5", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
break; break;
case 6: case 6:
frameRec.y = 5 * (float)diceTexture.height / 9; frameRec.y = 5 * (float)diceTexture.height / 9;
DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE); DrawTextureRec(diceTexture, frameRec, positionDiceDefender[i - nbOfAttackers], WHITE);
DrawTextEx(font, "6", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK); DrawTextEx(*font, "6", (Vector2){positionDiceDefender[i - nbOfAttackers].x + 30, positionDiceDefender[i - nbOfAttackers].y + 100}, 50.0, 3.0, BLACK);
break; break;
default: default:
...@@ -392,17 +392,17 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N ...@@ -392,17 +392,17 @@ void Graphic_diceRolling(Player *attacker, Player *defender, Node *originNode, N
{ {
if (listOfDices[index] > listOfDices[index + attackersCount]) if (listOfDices[index] > listOfDices[index + attackersCount])
{ {
DrawTextEx(font, "Defenders lose a soldier", (Vector2){screenWidth / 2 - MeasureTextEx(font, "Defenders lose a soldier", 50.0, 3.0).x / 2 - 50, 600}, 50.0, 3.0, BLACK); DrawTextEx(*font, "Defenders lose a soldier", (Vector2){screenWidth / 2 - MeasureTextEx(*font, "Defenders lose a soldier", 50.0, 3.0).x / 2 - 50, 600}, 50.0, 3.0, BLACK);
} }
else else
{ {
DrawTextEx(font, "Attackers lose a soldier", (Vector2){screenWidth / 2 - MeasureTextEx(font, "Attackers lose a soldier", 50.0, 3.0).x / 2 - 50, 600}, 50.0, 3.0, BLACK); DrawTextEx(*font, "Attackers lose a soldier", (Vector2){screenWidth / 2 - MeasureTextEx(*font, "Attackers lose a soldier", 50.0, 3.0).x / 2 - 50, 600}, 50.0, 3.0, BLACK);
} }
} }
if (targetNode->soldiers <= 0) if (targetNode->soldiers <= 0)
{ {
DrawTextEx(font, "Node has been conquered", (Vector2){screenWidth / 2 - MeasureTextEx(font, "Node has been conquered", 50.0, 3.0).x / 2 - 50, 700}, 50.0, 3.0, BLACK); DrawTextEx(*font, "Node has been conquered", (Vector2){screenWidth / 2 - MeasureTextEx(*font, "Node has been conquered", 50.0, 3.0).x / 2 - 50, 700}, 50.0, 3.0, BLACK);
} }
EndDrawing(); EndDrawing();
......
...@@ -9,19 +9,19 @@ ...@@ -9,19 +9,19 @@
//Graphical view //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 //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 //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 //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 //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 //Confirm button for the recruitment phase
Rectangle Graphic_ConfirmButton(Font font); Rectangle Graphic_ConfirmButton(Font * font);
//Animation when mouse hover node during recruitment phase //Animation when mouse hover node during recruitment phase
void Graphic_MouseHoverNodeRecrutement(Player * self, Vector2 mousePosition, Panel * panel); void Graphic_MouseHoverNodeRecrutement(Player * self, Vector2 mousePosition, Panel * panel);
...@@ -33,10 +33,10 @@ void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition ...@@ -33,10 +33,10 @@ void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition
void Graphic_MouseHoverNodeChooseTarget(Node * originNode, Vector2 mousePosition, Panel * panel); 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 //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 //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 @@ ...@@ -3,14 +3,14 @@
#include <stdio.h> #include <stdio.h>
#include <string.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)); Int_Input * self = malloc(sizeof(Int_Input));
self->name = name; self->name = name;
self->targetInt = targetInt; self->targetInt = targetInt;
self->value = malloc(sizeof(char) * 32); self->value = malloc(sizeof(char)*50);
sprintf(self->value, "%d", *targetInt); sprintf(self->value, "%d", *targetInt);
self->valueLength = strlen(self->value); self->valueLength = strlen(self->value);
self->inputBox = inputBox; self->inputBox = *inputBox;
self->inputActive = false; self->inputActive = false;
return self; return self;
...@@ -24,6 +24,7 @@ void Int_Input_delete(Int_Input * self){ ...@@ -24,6 +24,7 @@ void Int_Input_delete(Int_Input * self){
void Int_Input_add_char(Int_Input * self, int * key){ void Int_Input_add_char(Int_Input * self, int * key){
self->value[self->valueLength] = (char) *key; self->value[self->valueLength] = (char) *key;
self->valueLength++; self->valueLength++;
self->value[self->valueLength] = '\0';
} }
void Int_Input_remove_char(Int_Input * self){ void Int_Input_remove_char(Int_Input * self){
......
...@@ -26,7 +26,7 @@ typedef struct Str_Int_Input Int_Input; ...@@ -26,7 +26,7 @@ typedef struct Str_Int_Input Int_Input;
* @param inputBox panel input box * @param inputBox panel input box
* @return The pointer to the new Int_Input. * @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 * @brief Free an Int_Input
......
...@@ -10,25 +10,25 @@ Main_Menu * Main_Menu_init(const int screenWidth, const int screenHeight){ ...@@ -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 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 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}; 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 //Init of the options btn
Rectangle optionsBtn = {(screenWidth*32)/100, (screenHeight*45)/100, (screenWidth*30)/100, (screenHeight*5)/100}; 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 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}; 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 //Init of the rules btn
Rectangle rulesBtn = {(screenWidth*32)/100, (screenHeight*55)/100, (screenWidth*30)/100, (screenHeight*5)/100}; 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 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}; 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 //Init of the exit btn
Rectangle exitBtn = {0, (screenHeight*95)/100, (screenWidth*10)/100, (screenHeight*10)/100}; 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 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}; 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->buttonCount = 4;
self->buttons = malloc(sizeof(Menu_Button) * self->buttonCount); self->buttons = malloc(sizeof(Menu_Button) * self->buttonCount);
...@@ -48,13 +48,13 @@ Main_Menu * Rules_Menu_init(const int screenWidth, const int screenHeight){ ...@@ -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 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 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}; 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 //Init of the rules text box
Rectangle rulesBox = {(screenWidth*25)/100, (screenHeight*30)/100, (screenWidth*50)/100, (screenHeight*60)/100}; 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 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}; 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.", "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); rules);
......
...@@ -27,7 +27,7 @@ const int screenWidth = 1700; ...@@ -27,7 +27,7 @@ const int screenWidth = 1700;
const int screenHeight = 800; const int screenHeight = 800;
const int targetFPS = 60; 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 // Game attributes
//----------------- //-----------------
...@@ -61,27 +61,29 @@ int main(int nbArg, char ** arg) ...@@ -61,27 +61,29 @@ int main(int nbArg, char ** arg)
Window_Manager * manager = Window_Manager_new(panel, menu, rulesMenu, optionsMenu); Window_Manager * manager = Window_Manager_new(panel, menu, rulesMenu, optionsMenu);
Rectangle gameReturnBtn = {0,0, (screenWidth*13)/100, (screenHeight*5)/100}; Rectangle gameReturnBtn = {0,0, (screenWidth*13)/100, (screenHeight*5)/100};
Rectangle smallerGameReturnBtn = {3,3, -6 +(screenWidth*13)/100, -6 +(screenHeight*5)/100}; Rectangle gameReturnTextBox = {3,3, -6 +(screenWidth*13)/100, -6 +(screenHeight*5)/100};
Menu_Button* gameReturn = Menu_Button_init(gameReturnBtn, smallerGameReturnBtn, smallerGameReturnBtn, "Main Menu", main_menu); Menu_Button* gameReturn = Menu_Button_init(&gameReturnBtn, &gameReturnTextBox, "Main Menu", main_menu);
while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key
{ {
DrawFPS(screenWidth - 100,screenHeight - 50); DrawFPS(screenWidth - 100,screenHeight - 50);
Window_Manager_display(manager, world, players); Window_Manager_display(manager, world, players, missions);
Vector2 mousePos; Vector2 mousePos;
int key;
switch (manager->display) switch (manager->display)
{ {
case main_menu: case main_menu:
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Vector2 mousePos = GetMousePosition(); mousePos = GetMousePosition();
manager->display = Main_Menu_detect_click(menu, &mousePos); manager->display = Main_Menu_detect_click(menu, &mousePos);
if(manager->display == game_ui){ if(manager->display == game_ui){
//Initialising a new game with inputted parameters //Initialising a new game with inputted parameters
*world = *NetWorld_new(nodeCount, playerCount); *world = *NetWorld_new(nodeCount, playerCount);
Random_map(world); Random_map(world);
Color colors[] = {BLACK, RED, BLUE, BROWN, PURPLE, PINK, YELLOW}; Color colors[] = {BLACK, RED, BLUE, BROWN, PURPLE, PINK, YELLOW};
players = Player_newArray(playerCount, colors); char* names[] = {"Black", "Red", "Blue", "Brown", "Purple", "Pink", "Yellow"};
missions = Mission_newArray(playerCount, world); players = Player_newArray(playerCount, colors, names);
missions = Mission_newArray(playerCount, world, players);
//Distribute nodes to players evenly //Distribute nodes to players evenly
for(int index = 0; index < world->size; index++){ for(int index = 0; index < world->size; index++){
Player_add_Node(&(players[index % playerCount]), &(world->nodes[index])); Player_add_Node(&(players[index % playerCount]), &(world->nodes[index]));
...@@ -92,12 +94,13 @@ int main(int nbArg, char ** arg) ...@@ -92,12 +94,13 @@ int main(int nbArg, char ** arg)
} }
break; break;
case game_ui: case game_ui:
BeginDrawing();
Panel_control(panel); Panel_control(panel);
mousePos = GetMousePosition();
Menu_Button_draw(gameReturn, &gameFont, screenWidth, screenHeight, RED, (screenHeight*4)/100, (screenWidth/400), true); Menu_Button_draw(gameReturn, &gameFont, screenWidth, screenHeight, RED, (screenHeight*4)/100, (screenWidth/400), true);
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mousePos, gameReturn->button)){ if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
manager->display = gameReturn->displayOnClick; mousePos = GetMousePosition();
if(CheckCollisionPointRec(mousePos, gameReturn->button)){
manager->display = gameReturn->displayOnClick;
}
} }
//Draw the hitboxes for each node //Draw the hitboxes for each node
for(int index = 0; index < world->size; index++){ for(int index = 0; index < world->size; index++){
...@@ -106,7 +109,7 @@ int main(int nbArg, char ** arg) ...@@ -106,7 +109,7 @@ int main(int nbArg, char ** arg)
world->nodes[index].collisionHitbox.y = screenPosition.y - 24; 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){ if(world->hasWinner){
manager->display = win; manager->display = win;
} }
...@@ -114,7 +117,7 @@ int main(int nbArg, char ** arg) ...@@ -114,7 +117,7 @@ int main(int nbArg, char ** arg)
case options: case options:
//Activate/Deactivate inputs on click and detect click on the save btn //Activate/Deactivate inputs on click and detect click on the save btn
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Vector2 mousePos = GetMousePosition(); mousePos = GetMousePosition();
if(Options_Menu_check_save_click(optionsMenu, &mousePos)){ if(Options_Menu_check_save_click(optionsMenu, &mousePos)){
manager->display = main_menu; manager->display = main_menu;
for(int index = 0; index < optionsMenu->inputCount; index++){ for(int index = 0; index < optionsMenu->inputCount; index++){
...@@ -123,15 +126,12 @@ int main(int nbArg, char ** arg) ...@@ -123,15 +126,12 @@ int main(int nbArg, char ** arg)
} }
Options_Menu_check_input_click(optionsMenu, &mousePos); Options_Menu_check_input_click(optionsMenu, &mousePos);
} }
key = GetKeyPressed();
//Check key inputs for active input fields (only accepts numerical characters) //Check key inputs for active input fields (only accepts numerical characters)
for(int index = 0; index < optionsMenu->inputCount; index++){ for(int index = 0; index < optionsMenu->inputCount; index++){
if(optionsMenu->inputs[index]->inputActive){ if(optionsMenu->inputs[index]->inputActive){
int key = GetKeyPressed(); if ((key >= 48) && (key <= 57) && (optionsMenu->inputCount < 3)){
while (key > 0){ Int_Input_add_char(optionsMenu->inputs[index], &key);
if ((key >= 48) && (key <= 57) && (optionsMenu->inputCount < 3)){
Int_Input_add_char(optionsMenu->inputs[index], &key);
}
key = GetCharPressed();
} }
if (IsKeyPressed(KEY_BACKSPACE)){ if (IsKeyPressed(KEY_BACKSPACE)){
Int_Input_remove_char(optionsMenu->inputs[index]); Int_Input_remove_char(optionsMenu->inputs[index]);
...@@ -141,19 +141,22 @@ int main(int nbArg, char ** arg) ...@@ -141,19 +141,22 @@ int main(int nbArg, char ** arg)
break; break;
case rules: case rules:
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Vector2 mousePos = GetMousePosition(); mousePos = GetMousePosition();
manager->display = Main_Menu_detect_click(rulesMenu, &mousePos); manager->display = Main_Menu_detect_click(rulesMenu, &mousePos);
} }
break; break;
case win: case win:
Menu_Button_draw(gameReturn, &gameFont, screenWidth, screenHeight, RED, (screenHeight*4)/100, (screenWidth/400), true); Menu_Button_draw(gameReturn, &gameFont, screenWidth, screenHeight, RED, (screenHeight*4)/100, (screenWidth/400), true);
mousePos = GetMousePosition(); if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mousePos, gameReturn->button)){ mousePos = GetMousePosition();
manager->display = gameReturn->displayOnClick; if(CheckCollisionPointRec(mousePos, gameReturn->button)){
manager->display = gameReturn->displayOnClick;
}
} }
break; break;
case exitRoute: case exitRoute:
game_end = true; game_end = true;
break;
default: default:
break; break;
} }
...@@ -178,7 +181,7 @@ int main(int nbArg, char ** arg) ...@@ -178,7 +181,7 @@ int main(int nbArg, char ** arg)
return 0; 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 //Game frame init
int winner = 0; int winner = 0;
...@@ -191,7 +194,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon ...@@ -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 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}; 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){ switch(currentPlayer->turnPhase){
case recruitment: case recruitment:
...@@ -199,7 +202,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon ...@@ -199,7 +202,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
Graphic_MouseHoverNodeRecrutement(currentPlayer, mousePosition, panel); Graphic_MouseHoverNodeRecrutement(currentPlayer, mousePosition, panel);
if(currentPlayer->soldiers > 0){ if(currentPlayer->soldiers > 0){
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Player_add_soldier(currentPlayer, mousePosition); Player_add_soldier(currentPlayer, &mousePosition);
} }
}else{ }else{
//Finish the recruitment phase //Finish the recruitment phase
...@@ -212,7 +215,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon ...@@ -212,7 +215,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
} }
} }
if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)){ if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)){
Player_remove_soldier(currentPlayer, mousePosition); Player_remove_soldier(currentPlayer, &mousePosition);
} }
break; break;
case attack: case attack:
...@@ -221,7 +224,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon ...@@ -221,7 +224,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
if(currentPlayer->hasSelectedNode){ if(currentPlayer->hasSelectedNode){
Graphic_MouseHoverNodeChooseTarget(currentPlayer->selectedNode, mousePosition, panel); Graphic_MouseHoverNodeChooseTarget(currentPlayer->selectedNode, mousePosition, panel);
if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)){ if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)){
Player_unselect_Node(currentPlayer, mousePosition); Player_unselect_Node(currentPlayer, &mousePosition);
} }
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Node * originNode = currentPlayer->selectedNode; Node * originNode = currentPlayer->selectedNode;
...@@ -254,13 +257,13 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon ...@@ -254,13 +257,13 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
} }
}else{ }else{
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
Player_select_Node(currentPlayer, mousePosition); Player_select_Node(currentPlayer, &mousePosition);
} }
} }
//End turn btn //End turn btn
Rectangle nextPhase = {200, 200, 270, 55}; Rectangle nextPhase = {200, 200, 270, 55};
DrawRectangleRec(nextPhase, GREEN); 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 (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
if(CheckCollisionPointRec(mousePosition, nextPhase)){ if(CheckCollisionPointRec(mousePosition, nextPhase)){
currentPlayer->turnPhase = init; currentPlayer->turnPhase = init;
......
...@@ -2,19 +2,17 @@ ...@@ -2,19 +2,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.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)); Menu_Button * self = malloc(sizeof(Menu_Button));
self->button = button; self->button = *button;
self->smallerButton = smallerButton; self->textBox = *textBox;
self->textBox = textBox;
self->displayText = displayText; self->displayText = displayText;
self->displayOnClick = display; self->displayOnClick = display;
return self; 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){ 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); DrawRectangleLinesEx(self->button, 3, colour);
DrawRectangleRec(self->smallerButton, WHITE);
DrawTextRec(*font, self->displayText, self->textBox, fontSize, spacing, wordWrap, BLACK); DrawTextRec(*font, self->displayText, self->textBox, fontSize, spacing, wordWrap, BLACK);
} }
......
...@@ -9,7 +9,6 @@ typedef enum displays Display; ...@@ -9,7 +9,6 @@ typedef enum displays Display;
struct Str_Menu_Button{ struct Str_Menu_Button{
//! Panel elements //! Panel elements
Rectangle button; Rectangle button;
Rectangle smallerButton;
Rectangle textBox; Rectangle textBox;
//! Text to display in the button //! Text to display in the button
char* displayText; char* displayText;
...@@ -23,13 +22,12 @@ typedef struct Str_Menu_Button Menu_Button; ...@@ -23,13 +22,12 @@ typedef struct Str_Menu_Button Menu_Button;
/** /**
* @brief Init a Menu_Button * @brief Init a Menu_Button
* @param button Button hitbox * @param button Button hitbox
* @param smallerButton White layer
* @param textBox Container for displayText * @param textBox Container for displayText
* @param displayText Text to display * @param displayText Text to display
* @param Display Enum element referencing to a screen display * @param Display Enum element referencing to a screen display
* @return A pointer to the new button * @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 * @brief Draw the Menu_Button
......
#include "mission.h" #include "mission.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
bool Player_conquer_threshold(NetWorld * world, Player * players, const int playerID, const int threshold){ bool Player_conquer_threshold(NetWorld * world, Player * players, const int playerID, const int threshold){
return players[playerID].nodeCount >= threshold; return players[playerID].nodeCount >= threshold;
...@@ -11,7 +12,7 @@ bool Player_eliminated(NetWorld * world, Player * players, const int playerID, c ...@@ -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); char* displayText = malloc(sizeof(char)*50);
self->playerID = playerID; self->playerID = playerID;
...@@ -20,7 +21,7 @@ void Mission_init(Mission * self, const int playerID, NetWorld * world){ ...@@ -20,7 +21,7 @@ void Mission_init(Mission * self, const int playerID, NetWorld * world){
case 0: case 0:
self->mission = &Player_conquer_threshold; self->mission = &Player_conquer_threshold;
self->target = world->size/2 + ((rand()%(world->size/5)) + (world->size/10)); 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; self->displayText = displayText;
break; break;
case 1: case 1:
...@@ -29,17 +30,18 @@ void Mission_init(Mission * self, const int playerID, NetWorld * world){ ...@@ -29,17 +30,18 @@ void Mission_init(Mission * self, const int playerID, NetWorld * world){
while(self->target == self->playerID){ while(self->target == self->playerID){
self->target = rand()%world->playerCount; 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; self->displayText = displayText;
break; break;
} }
//return self; //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); Mission * missionArray = malloc(sizeof(Mission) * playerCount);
for(int i = 0; i < playerCount; i++){ for(int i = 0; i < playerCount; i++){
Mission_init((missionArray+i),i ,world); Mission_init((missionArray+i),i ,world, players);
} }
return missionArray; return missionArray;
} }
...@@ -51,8 +53,5 @@ bool Mission_check(Mission * self, NetWorld * world, Player * players){ ...@@ -51,8 +53,5 @@ bool Mission_check(Mission * self, NetWorld * world, Player * players){
} }
void Mission_deleteArray(Mission * array, int playerCount){ void Mission_deleteArray(Mission * array, int playerCount){
for(int i = 0 ; i<playerCount; i++){
free((array+i)->displayText);
}
free(array); free(array);
} }
\ No newline at end of file
...@@ -5,20 +5,39 @@ ...@@ -5,20 +5,39 @@
#include "player.h" #include "player.h"
struct Str_Mission{ struct Str_Mission{
//! Boolean function to check if the mission is accomplished
bool (*mission)(NetWorld*, Player*, const int, const int); bool (*mission)(NetWorld*, Player*, const int, const int);
//! Player needing to accomplish the mission
int playerID; int playerID;
//! Relevant target int for mission (node count, player ID, ...)
int target; int target;
//! Mission Description
char* displayText; char* displayText;
}; };
typedef struct Str_Mission Mission; 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); bool Mission_check(Mission * self, NetWorld * world, Player * players);
/**
* @brief Void a mission array
*/
void Mission_deleteArray(Mission * array, int playerCount); 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 #endif
\ No newline at end of file
...@@ -7,11 +7,11 @@ Options_Menu * Options_Menu_init(int * playerCount, int * nodeCount, const int s ...@@ -7,11 +7,11 @@ Options_Menu * Options_Menu_init(int * playerCount, int * nodeCount, const int s
//Input for the player count //Input for the player count
Rectangle playerCountInputBox = {(screenWidth*32)/100, (screenHeight*35)/100, (screenWidth*30)/100, (screenHeight*5)/100}; 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 //Input for the node count
Rectangle nodeCountInputBox = {(screenWidth*32)/100, (screenHeight*45)/100, (screenWidth*30)/100, (screenHeight*5)/100}; 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->inputCount = 2;
self->inputs = malloc(sizeof(Int_Input) * self->inputCount); self->inputs = malloc(sizeof(Int_Input) * self->inputCount);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.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->ID = i;
self->nodes = malloc(sizeof(Node*)); self->nodes = malloc(sizeof(Node*));
...@@ -13,32 +13,29 @@ void Player_construct(Player * self, int i, Color color) ...@@ -13,32 +13,29 @@ void Player_construct(Player * self, int i, Color color)
self->soldiers = 0; self->soldiers = 0;
self->selectedNode = malloc(sizeof(Node)); self->selectedNode = malloc(sizeof(Node));
self->hasSelectedNode = false; self->hasSelectedNode = false;
self->name = name;
} }
Player * Player_new() Player * Player_new()
{ {
Player * player= malloc( sizeof(Player) ); Player * player= malloc( sizeof(Player) );
Player_construct(player, 0, BLACK); Player_construct(player, 0, BLACK, "Black");
return player; return player;
} }
Player * Player_newArray(int size, Color color[]) Player * Player_newArray(int size, Color color[], char* names[])
{ {
size= fmaxf(1, size); size= fmaxf(1, size);
Player * p= malloc( sizeof(Player)*size ); Player * p= malloc( sizeof(Player)*size );
for(int i=0 ; i < size ; ++i ) 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; return p;
} }
void Players_delete(Player * player, int size) void Players_delete(Player * player, int size)
{ {
for(int i = 0 ; i < size ; i++){
//free((player+i)->nodes);
//free((player+i)->selectedNode);
}
free(player); free(player);
} }
...@@ -101,10 +98,10 @@ void Player_end_turn(Player * self){ ...@@ -101,10 +98,10 @@ void Player_end_turn(Player * self){
self->turnPhase = init; 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++){ for(int nodeIndex = 0; nodeIndex < self->nodeCount; nodeIndex++){
Node* currentNode = self->nodes[nodeIndex]; Node* currentNode = self->nodes[nodeIndex];
if(CheckCollisionPointRec(mousePos, currentNode->collisionHitbox)){ if(CheckCollisionPointRec(*mousePos, currentNode->collisionHitbox)){
currentNode->soldiersToAdd++; currentNode->soldiersToAdd++;
self->soldiers--; self->soldiers--;
break; break;
...@@ -112,10 +109,10 @@ void Player_add_soldier(Player * self, Vector2 mousePos){ ...@@ -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++){ for(int nodeIndex = 0; nodeIndex < self->nodeCount; nodeIndex++){
Node* currentNode = self->nodes[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){ if(currentNode->soldiersToAdd > 0){
currentNode->soldiersToAdd--; currentNode->soldiersToAdd--;
self->soldiers++; self->soldiers++;
...@@ -125,10 +122,10 @@ void Player_remove_soldier(Player * self, Vector2 mousePos){ ...@@ -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++){ for(int nodeIndex = 0; nodeIndex < self->nodeCount; nodeIndex++){
Node* currentNode = self->nodes[nodeIndex]; Node* currentNode = self->nodes[nodeIndex];
if(CheckCollisionPointRec(mousePos, currentNode->collisionHitbox)){ if(CheckCollisionPointRec(*mousePos, currentNode->collisionHitbox)){
if(currentNode->soldiers > 1){ if(currentNode->soldiers > 1){
self->hasSelectedNode = true; self->hasSelectedNode = true;
self->selectedNode = currentNode; self->selectedNode = currentNode;
...@@ -138,10 +135,10 @@ void Player_select_Node(Player * self, Vector2 mousePos){ ...@@ -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++){ for(int nodeIndex = 0; nodeIndex < self->nodeCount; nodeIndex++){
Node* currentNode = self->nodes[nodeIndex]; Node* currentNode = self->nodes[nodeIndex];
if(CheckCollisionPointRec(mousePos, currentNode->collisionHitbox)){ if(CheckCollisionPointRec(*mousePos, currentNode->collisionHitbox)){
self->hasSelectedNode = false; self->hasSelectedNode = false;
} }
} }
...@@ -155,9 +152,8 @@ void Player_confirm_recrutement(Player * self){ ...@@ -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 * listOfDices = malloc(20*sizeof(int));
int attackersCount = numberOfAttackers;
int defendersCount = targetNode->soldiers; int defendersCount = targetNode->soldiers;
int attDiceRolls[attackersCount]; int attDiceRolls[attackersCount];
int defDiceRolls[defendersCount]; int defDiceRolls[defendersCount];
......
...@@ -22,6 +22,7 @@ struct Str_Player{ ...@@ -22,6 +22,7 @@ struct Str_Player{
//! Player's selected node for the attack phase //! Player's selected node for the attack phase
Node * selectedNode; Node * selectedNode;
bool hasSelectedNode; bool hasSelectedNode;
char* name;
}; };
typedef struct Str_Player Player; typedef struct Str_Player Player;
...@@ -32,7 +33,7 @@ typedef struct Str_Player Player; ...@@ -32,7 +33,7 @@ typedef struct Str_Player Player;
* @param self an empty Player not yet constructed. * @param self an empty Player not yet constructed.
* @return The pointer to the new Player. * @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 * @brief Allocate the memory to store a Player
...@@ -44,7 +45,7 @@ Player * Player_new(); ...@@ -44,7 +45,7 @@ Player * Player_new();
* @brief Allocate 'size' Players. * @brief Allocate 'size' Players.
* @return The pointer to the new array of 'size' Player. * @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. * @brief Destructor.
...@@ -93,28 +94,28 @@ void Player_end_turn(Player * self); ...@@ -93,28 +94,28 @@ void Player_end_turn(Player * self);
* @param self The player context * @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked * @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 * @brief Remove a soldier from a player's node
* @param self The player context * @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked * @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 * @brief A player selects a node
* @param self The player context * @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked * @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 * @brief A player unselects a node
* @param self The player context * @param self The player context
* @param mousePos the position of the mouse to detect which node has been clicked * @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 * @brief Attack declaration
...@@ -124,7 +125,7 @@ void Player_unselect_Node(Player * self, Vector2 mousePos); ...@@ -124,7 +125,7 @@ void Player_unselect_Node(Player * self, Vector2 mousePos);
* @param targetNode The defender's node * @param targetNode The defender's node
* @param numberOfAttackers Number of attacking soldiers * @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 * @brief Confirm placement of soldiers
......
...@@ -17,7 +17,7 @@ void Window_Manager_delete(Window_Manager * manager){ ...@@ -17,7 +17,7 @@ void Window_Manager_delete(Window_Manager * manager){
free(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){ switch(self->display){
case main_menu: case main_menu:
Panel_drawMainMenu(self->panel, self->menu); Panel_drawMainMenu(self->panel, self->menu);
...@@ -32,7 +32,7 @@ void Window_Manager_display(Window_Manager * self, NetWorld * world, Player * pl ...@@ -32,7 +32,7 @@ void Window_Manager_display(Window_Manager * self, NetWorld * world, Player * pl
Panel_drawRules(self->panel, self->rules); Panel_drawRules(self->panel, self->rules);
break; break;
case win: case win:
Panel_drawWin(self->panel, &players[world->winner]); Panel_drawWin(self->panel, players+world->winner, missions+world->winner);
break; break;
default: default:
break; break;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "networld.h" #include "networld.h"
#include "controlpanel.h" #include "controlpanel.h"
#include "mission.h"
struct Str_Window_Manager{ struct Str_Window_Manager{
//! frame to display //! frame to display
...@@ -38,6 +39,6 @@ void Window_Manager_delete(Window_Manager * manager); ...@@ -38,6 +39,6 @@ void Window_Manager_delete(Window_Manager * manager);
* @brief Displays the appropriate frame * @brief Displays the appropriate frame
* @param self The manager context * @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 #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