Commit 2d0a1477 authored by ewen.madec's avatar ewen.madec

comments + cleaning

parent 2135e79f
This diff is collapsed.
......@@ -8,18 +8,35 @@
//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);
//Display recrutement phase rules on the right of the screen
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);
//Display whose turn is it on the top of the screen
void Graphic_WhoseTurnIsIt(Player * player, const int screenWidth, const int screenHeight, Font font);
//Confirm button for the recruitment phase
Rectangle Graphic_ConfirmButton(Font font);
//Animation when mouse hover node during recruitment phase
void Graphic_MouseHoverNodeRecrutement(Player * self, Vector2 mousePosition, Panel * panel);
//Animation when mouse hover node when choosing attacker node during attack phase
void Graphic_MouseHoverNodeChooseAttacker(Player * player, Vector2 mousePosition, Panel * panel);
//Animation when mouse hover node when choosing target node during attack phase
void Graphic_MouseHoverNodeChooseTarget(Node * originNode, Vector2 mousePosition, Panel * panel);
void Graphic_RectuementBeginTurn(int screenWidth, int screenHeight, Font font);
//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);
void diceRolling(Player * attacker, Player * defender, Node * originNode, Node * targetNode, int nbOfAttackers, int nbOfDefenders, int * listOfDices, 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);
......
......@@ -242,7 +242,7 @@ int game_update(NetWorld * world, Player * players, Mission * missions, Font fon
for(int i = 0; i< nbOfDefenders+nbOfAttackers; i++){
printf("listOfdices3 [%d] : %d \n",i,listOfDices[i]);
}
diceRolling(currentPlayer, &(players[nodePlayerID]), originNode, currentNode, nbOfAttackers ,nbOfDefenders, listOfDices ,font);
Graphic_diceRolling(currentPlayer, &(players[nodePlayerID]), originNode, currentNode, nbOfAttackers ,nbOfDefenders, listOfDices, font);
currentPlayer->hasSelectedNode = false;
free(listOfDices);
}else{
......
......@@ -11,6 +11,7 @@
#include "raylib.h"
double randfrom(double min, double max)
{
double range = (max - min);
......@@ -22,43 +23,47 @@ double dist(Vector2 vector1, Vector2 vector2)
{
return (sqrt((vector2.x - vector1.x) * (vector2.x - vector1.x) + (vector2.y - vector1.y) * (vector2.y - vector1.y)));
}
double distNode(Node node1, Node node2)
{
return (dist(node1.position, node2.position));
}
const double rangeForXcoordinates = 30.0;
const double rangeForYcoordinates = 30.0;
const double minimumDistance = 8.0;
void Random_map(NetWorld *world)
{
int nbNode = world->size;
float randomX, randomY;
/* Intializes random number generator */
srand(time(NULL));
/* Generate nbNode*2 random numbers from -15.00 to 15.00 */
/* Generate nbNode*2 random numbers for y-coordinates and x-coordinates of the nodes*/
for (int i = 0; i < nbNode; i++)
{
if (i > 0)
{
bool continueLoop = true;
while (continueLoop)
bool continueLoop = true;
while (continueLoop) //loop until the minimum distance between the new node and the others is respected
{
continueLoop = false;
randomX = randfrom(-30.0, 30.0);
randomY = randfrom(-30.0, 30.0);
randomX = randfrom(-rangeForXcoordinates, rangeForXcoordinates);
randomY = randfrom(-rangeForYcoordinates, rangeForYcoordinates);
Vector2 newPosition = (Vector2){randomX, randomY};
for (int j = 0; j < i; j++)
{
//printf("positionComparee %d %f\n", j, dist(world->nodes[j].position, newPosition));
if (dist(world->nodes[j].position, newPosition) < 8.0)
if (dist(world->nodes[j].position, newPosition) < minimumDistance)
{
continueLoop = true;
}
}
}
//randomX = randfrom(-15.0, 15.0);
//randomY = randfrom(-15.0, 15.0);
char *name;
name = malloc(20*sizeof(char));
sprintf(name, "name : %d", i);
char *name; name = malloc(20*sizeof(char)); sprintf(name, "name : %d", i);
Node_set(&(world->nodes[i]), (Vector2){randomX, randomY}, RED, name);
free(name);
}
......@@ -66,13 +71,9 @@ void Random_map(NetWorld *world)
{
randomX = randfrom(-15.0, 15.0);
randomY = randfrom(-15.0, 15.0);
char *name;
name = malloc(20*sizeof(char));
sprintf(name, "name : %d", i);
char *name; name = malloc(20*sizeof(char)); sprintf(name, "name : %d", i);
Node_set(&(world->nodes[i]), (Vector2){randomX, randomY}, RED, name);
free(name);
printf("%f\n", randomX);
printf("%f\n", randomY);
}
}
//Gabriel graph sort
......@@ -85,21 +86,17 @@ void Random_map(NetWorld *world)
float ym = 0.5 * (world->nodes[i].position.y + world->nodes[j].position.y);
Vector2 M = {xm, ym};
float distNodeCenterOfij = dist(world->nodes[i].position, M);
//printf("distNode %d%d : %f\n", i, j, distNode((world->nodes[i]), world->nodes[j]));
for (int k = 0; k < nbNode; k++)
{
//printf(" distNode center - Node k %f\n", dist(world->nodes[k].position, M));
if (dist(world->nodes[k].position, M) < distNodeCenterOfij - 0.05)
{
compteurPointDansLeCercle++;
}
}
//printf("compteurPointDansLeCercle : %i\n", compteurPointDansLeCercle);
if (compteurPointDansLeCercle == 0)
{
NetWorld_biconnect(world, i, j);
}
}
}
}
}
\ No newline at end of file
......@@ -4,11 +4,18 @@
#include "raylib.h"
#include "networld.h"
void Random_map(NetWorld * world);
double randfrom(double min, double max);
double dist(Vector2 vector1, Vector2 vector2);
//random function
double randfrom(double min, double max);
//distance between 2 points(Vector2)
double dist(Vector2 vector1, Vector2 vector2);
//distance between 2 nodes
double distNode(Node node1, Node node2);
//generation of a random map following Gabriel Graph theory
void Random_map(NetWorld * world);
#endif
\ No newline at end of file
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