Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NetWorld
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LAIRD Timothy
NetWorld
Commits
2d0a1477
Commit
2d0a1477
authored
3 years ago
by
ewen.madec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments + cleaning
parent
2135e79f
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
333 additions
and
349 deletions
+333
-349
graphical-aspect.c
src/graphical-aspect.c
+284
-321
graphical-aspect.h
src/graphical-aspect.h
+19
-2
main-viewer.c
src/main-viewer.c
+1
-1
random-map.c
src/random-map.c
+19
-22
random-map.h
src/random-map.h
+10
-3
No files found.
src/graphical-aspect.c
View file @
2d0a1477
This diff is collapsed.
Click to expand it.
src/graphical-aspect.h
View file @
2d0a1477
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
src/main-viewer.c
View file @
2d0a1477
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
src/random-map.c
View file @
2d0a1477
...
...
@@ -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
This diff is collapsed.
Click to expand it.
src/random-map.h
View file @
2d0a1477
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment