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
b582de90
Commit
b582de90
authored
Apr 09, 2021
by
Timothy LAIRD
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modifs Networld; recrutement soldiers successifs
parent
e0e3846b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
19 deletions
+55
-19
main-viewer.c
src/main-viewer.c
+30
-16
networld.c
src/networld.c
+3
-1
networld.h
src/networld.h
+7
-1
player.c
src/player.c
+13
-1
player.h
src/player.h
+2
-0
No files found.
src/main-viewer.c
View file @
b582de90
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include "networld.h"
#include "networld.h"
#include "player.h"
#include "player.h"
...
@@ -20,7 +21,7 @@ const int screenWidth = 800;
...
@@ -20,7 +21,7 @@ const int screenWidth = 800;
const
int
screenHeight
=
600
;
const
int
screenHeight
=
600
;
const
int
targetFPS
=
60
;
const
int
targetFPS
=
60
;
void
game_update
(
NetWorld
*
world
,
Player
*
players
,
Player
*
currentPlayer
,
int
playerCount
);
void
game_update
(
NetWorld
*
world
,
Player
*
players
);
// Game attributes
// Game attributes
//-----------------
//-----------------
...
@@ -31,7 +32,8 @@ int main(int nbArg, char ** arg)
...
@@ -31,7 +32,8 @@ int main(int nbArg, char ** arg)
// Game Initialization
// Game Initialization
//--------------------
//--------------------
game_end
=
false
;
game_end
=
false
;
NetWorld
*
world
=
NetWorld_new
(
3
);
int
playerCount
=
3
;
NetWorld
*
world
=
NetWorld_new
(
3
,
playerCount
);
Node_set
(
&
(
world
->
nodes
[
0
]),
(
Vector2
){
1
.
4
f
,
1
.
28
f
},
RED
);
Node_set
(
&
(
world
->
nodes
[
0
]),
(
Vector2
){
1
.
4
f
,
1
.
28
f
},
RED
);
Node_set
(
&
(
world
->
nodes
[
1
]),
(
Vector2
){
21
.
0
f
,
22
.
8
f
},
MAGENTA
);
Node_set
(
&
(
world
->
nodes
[
1
]),
(
Vector2
){
21
.
0
f
,
22
.
8
f
},
MAGENTA
);
Node_set
(
&
(
world
->
nodes
[
2
]),
(
Vector2
){
18
.
4
f
,
-
12
.
2
f
},
GRAY
);
Node_set
(
&
(
world
->
nodes
[
2
]),
(
Vector2
){
18
.
4
f
,
-
12
.
2
f
},
GRAY
);
...
@@ -44,7 +46,6 @@ int main(int nbArg, char ** arg)
...
@@ -44,7 +46,6 @@ int main(int nbArg, char ** arg)
Panel_initialize
(
panel
,
world
);
Panel_initialize
(
panel
,
world
);
Color
colors
[]
=
{
BLACK
,
RED
,
BLUE
};
Color
colors
[]
=
{
BLACK
,
RED
,
BLUE
};
int
playerCount
=
3
;
Player
*
players
=
Player_newArray
(
playerCount
,
colors
);
Player
*
players
=
Player_newArray
(
playerCount
,
colors
);
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
]));
...
@@ -65,8 +66,8 @@ int main(int nbArg, char ** arg)
...
@@ -65,8 +66,8 @@ int main(int nbArg, char ** arg)
printf
(
"[%.2f,%.2f]
\n
"
,
position
.
x
,
position
.
y
);
printf
(
"[%.2f,%.2f]
\n
"
,
position
.
x
,
position
.
y
);
// Main game loop
// Main game loop
Player
*
currentPlayer
=
&
(
players
[
0
])
;
world
->
currentPlayer
=
0
;
Player_start_turn
(
currentPlayer
);
Player_start_turn
(
&
(
players
[
world
->
currentPlayer
])
);
while
(
!
game_end
&&
!
WindowShouldClose
())
// Detect window close button or ESC key
while
(
!
game_end
&&
!
WindowShouldClose
())
// Detect window close button or ESC key
{
{
DrawFPS
(
10
,
10
);
DrawFPS
(
10
,
10
);
...
@@ -76,7 +77,7 @@ int main(int nbArg, char ** arg)
...
@@ -76,7 +77,7 @@ int main(int nbArg, char ** arg)
world
->
nodes
[
index
].
collisionHitbox
.
y
=
screenPosition
.
y
-
24
;
world
->
nodes
[
index
].
collisionHitbox
.
y
=
screenPosition
.
y
-
24
;
}
}
Panel_control
(
panel
);
Panel_control
(
panel
);
game_update
(
world
,
players
,
currentPlayer
,
playerCount
);
game_update
(
world
,
players
);
Panel_draw
(
panel
);
Panel_draw
(
panel
);
}
}
...
@@ -89,19 +90,32 @@ int main(int nbArg, char ** arg)
...
@@ -89,19 +90,32 @@ int main(int nbArg, char ** arg)
return
0
;
return
0
;
}
}
void
game_update
(
NetWorld
*
world
,
Player
*
players
,
Player
*
currentPlayer
,
int
playerCount
)
void
game_update
(
NetWorld
*
world
,
Player
*
players
)
{
{
if
(
IsMouseButtonPressed
(
MOUSE_LEFT_BUTTON
)){
Player
*
currentPlayer
=
&
(
players
[
world
->
currentPlayer
]);
Vector2
mousePosition
=
GetMousePosition
();
int
playerCount
=
world
->
playerCount
;
for
(
int
nodeIndex
=
0
;
nodeIndex
<
currentPlayer
->
nodeCount
;
nodeIndex
++
){
switch
(
currentPlayer
->
turnPhase
){
Node
*
currentNode
=
currentPlayer
->
nodes
[
nodeIndex
];
case
1
:
if
(
CheckCollisionPointRec
(
mousePosition
,
currentNode
->
collisionHitbox
)){
if
(
IsMouseButtonPressed
(
MOUSE_LEFT_BUTTON
)){
printf
(
"click
\n
"
);
Vector2
mousePosition
=
GetMousePosition
();
for
(
int
nodeIndex
=
0
;
nodeIndex
<
currentPlayer
->
nodeCount
;
nodeIndex
++
){
Node
*
currentNode
=
currentPlayer
->
nodes
[
nodeIndex
];
if
(
CheckCollisionPointRec
(
mousePosition
,
currentNode
->
collisionHitbox
)){
currentNode
->
soldiers
++
;
currentPlayer
->
soldiers
--
;
}
}
}
}
}
if
(
currentPlayer
->
soldiers
==
0
){
currentPlayer
->
turnPhase
=
-
1
;
}
break
;
default:
;
}
}
if
(
false
){
if
(
currentPlayer
->
turnPhase
==
-
1
){
Player_end_turn
(
currentPlayer
);
Player_end_turn
(
currentPlayer
);
currentPlayer
=
&
(
players
[(
currentPlayer
->
ID
+
1
)
%
playerCount
]);
world
->
currentPlayer
=
(
world
->
currentPlayer
+
1
)
%
playerCount
;
Player_start_turn
(
&
(
players
[
world
->
currentPlayer
]));
}
}
}
}
src/networld.c
View file @
b582de90
...
@@ -185,11 +185,13 @@ void Edge_copy( Edge * copy, Edge * model )
...
@@ -185,11 +185,13 @@ void Edge_copy( Edge * copy, Edge * model )
// Constructor / Destructor
// Constructor / Destructor
NetWorld
*
NetWorld_new
(
int
size
)
NetWorld
*
NetWorld_new
(
int
size
,
int
playerCount
)
{
{
NetWorld
*
p
=
malloc
(
sizeof
(
NetWorld
)
);
NetWorld
*
p
=
malloc
(
sizeof
(
NetWorld
)
);
p
->
size
=
size
;
p
->
size
=
size
;
p
->
nodes
=
Node_newArray
(
p
->
size
);
p
->
nodes
=
Node_newArray
(
p
->
size
);
p
->
currentPlayer
=
-
1
;
p
->
playerCount
=
playerCount
;
return
p
;
return
p
;
}
}
...
...
src/networld.h
View file @
b582de90
...
@@ -216,6 +216,10 @@ struct Str_NetWorld {
...
@@ -216,6 +216,10 @@ struct Str_NetWorld {
int
size
;
int
size
;
//! Array of 'size' nodes
//! Array of 'size' nodes
Node
*
nodes
;
Node
*
nodes
;
//! Current Player ID
int
currentPlayer
;
//! Total Player count;
int
playerCount
;
};
};
typedef
struct
Str_NetWorld
NetWorld
;
typedef
struct
Str_NetWorld
NetWorld
;
...
@@ -227,7 +231,9 @@ typedef struct Str_NetWorld NetWorld;
...
@@ -227,7 +231,9 @@ typedef struct Str_NetWorld NetWorld;
*/
*/
NetWorld
*
NetWorld_new
(
NetWorld
*
NetWorld_new
(
//! the number of Nodes composing the new NetWorld
//! the number of Nodes composing the new NetWorld
int
aSize
int
aSize
,
//! the number of players in the game
int
playerCount
);
);
/**
/**
...
...
src/player.c
View file @
b582de90
#include "player.h"
#include "player.h"
#include <math.h>
#include <math.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
void
Player_construct
(
Player
*
self
,
int
i
,
Color
color
)
void
Player_construct
(
Player
*
self
,
int
i
,
Color
color
)
{
{
self
->
ID
=
i
;
self
->
ID
=
i
;
self
->
nodes
=
malloc
(
sizeof
(
Node
*
));
self
->
nodes
=
malloc
(
sizeof
(
Node
*
));
self
->
nodeCount
=
0
;
self
->
nodeCount
=
0
;
self
->
color
=
color
;
self
->
color
=
color
;
self
->
turnPhase
=
0
;
self
->
soldiers
=
0
;
}
}
Player
*
Player_new
()
Player
*
Player_new
()
...
@@ -44,6 +46,7 @@ void Player_add_Node( Player * self, Node * node )
...
@@ -44,6 +46,7 @@ void Player_add_Node( Player * self, Node * node )
node
->
color
=
self
->
color
;
node
->
color
=
self
->
color
;
node
->
playerID
=
self
->
ID
;
node
->
playerID
=
self
->
ID
;
newNodes
[
self
->
nodeCount
]
=
node
;
newNodes
[
self
->
nodeCount
]
=
node
;
free
(
self
->
nodes
);
self
->
nodes
=
newNodes
;
self
->
nodes
=
newNodes
;
self
->
nodeCount
+=
1
;
self
->
nodeCount
+=
1
;
}
}
...
@@ -59,12 +62,21 @@ void Player_remove_Node( Player * self, Node * node )
...
@@ -59,12 +62,21 @@ void Player_remove_Node( Player * self, Node * node )
}
}
}
}
node
->
playerID
=
-
1
;
node
->
playerID
=
-
1
;
free
(
self
->
nodes
);
self
->
nodes
=
newNodes
;
self
->
nodes
=
newNodes
;
self
->
nodeCount
-=
1
;
self
->
nodeCount
-=
1
;
}
}
void
Player_start_turn
(
Player
*
self
){
void
Player_start_turn
(
Player
*
self
){
int
totalSoldierCount
=
0
;
for
(
int
nodeIndex
=
0
;
nodeIndex
<
self
->
nodeCount
;
nodeIndex
++
){
totalSoldierCount
+=
self
->
nodes
[
nodeIndex
]
->
soldiers
;
}
self
->
soldiers
=
fmax
(
1
,
totalSoldierCount
/
3
);
self
->
turnPhase
=
1
;
printf
(
"Current player soldiers : %i
\n
"
,
self
->
soldiers
);
}
}
void
Player_end_turn
(
Player
*
self
){
void
Player_end_turn
(
Player
*
self
){
self
->
turnPhase
=
0
;
}
}
\ No newline at end of file
src/player.h
View file @
b582de90
...
@@ -8,6 +8,8 @@ struct Str_Player{
...
@@ -8,6 +8,8 @@ struct Str_Player{
Node
**
nodes
;
Node
**
nodes
;
int
nodeCount
;
int
nodeCount
;
Color
color
;
Color
color
;
int
turnPhase
;
int
soldiers
;
};
};
typedef
struct
Str_Player
Player
;
typedef
struct
Str_Player
Player
;
...
...
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