Bläddra i källkod

:tada: Ajout fichier gestion des joueurs

Arthur Brandao 6 år sedan
förälder
incheckning
b11c9ac832
4 ändrade filer med 92 tillägg och 1 borttagningar
  1. 2 0
      Serveur/constante.h
  2. 2 1
      Serveur/makefile
  3. 35 0
      Serveur/player.c
  4. 53 0
      Serveur/player.h

+ 2 - 0
Serveur/constante.h

@@ -32,6 +32,8 @@
 #define GET 1
 #define POST 2
 #define NBERRORRESET 3 //Nombre d'erreur avant de considérer que la connexion comme fermée 
+#define MAXGAME 5 //Nombre maximum de parti autorisé en simultané
+#define MAXPLAYER 4 //Nombre max de joueur par parti
 
 /* --- Reseaux --- */
 #define PORT_UDP 18624

+ 2 - 1
Serveur/makefile

@@ -3,7 +3,7 @@
 #
 
 EXEC = main test
-OBJETS = str.o json_parser.o json_encoder.o json_array.o error.o arraylist.o server_tcp.o server_udp.o bomberstudent_server.o client.o file.o handler.o
+OBJETS = str.o json_parser.o json_encoder.o json_array.o error.o arraylist.o server_tcp.o server_udp.o bomberstudent_server.o client.o file.o handler.o player.o
 NOM_PROJET = Projet Reseau
 
 #
@@ -108,6 +108,7 @@ client.o: client.c client.h constante.h server.h
 file.o: file.c error.h str.h file.h constante.h
 handler.o: handler.c bomberstudent_server.h constante.h server.h json.h \
  str.h client.h handler.h
+player.o: player.c player.h constante.h client.h server.h
 main.o: main.c error.h bomberstudent_server.h constante.h server.h json.h \
  str.h client.h main.h handler.h
 test.o: test.c json.h str.h constante.h arraylist.h server.h error.h \

+ 35 - 0
Serveur/player.c

@@ -0,0 +1,35 @@
+/* 
+ * File:   player.c
+ * Author: Arthur Brandao
+ *
+ * Created on 28 novembre 2018
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "player.h"
+
+void create_player(Player* p, Client* c){
+    //Initialisation valeurs
+    p->id = c->id;
+    p->cli = c;
+    p->life = 100;
+    p->maxLife = 100;
+    p->speed = 1;
+    p->classicBomb = 1;
+    p->mine = 0;
+    p->remoteBomb = 0;
+    p->maxBomb = 2;
+    p->bombUp = 0;
+    p->bombDown = 0;
+    p->firePower = 0;
+    p->scooter = 0;
+    p->brokenLeg = 0;
+    p->lifeMax = 0;
+    p->lifeUp = 0;
+    p->major = false;
+}
+
+void delete_player(Player* p){
+    //Rien a faire actuellement
+}

+ 53 - 0
Serveur/player.h

@@ -0,0 +1,53 @@
+/* 
+ * File:   player.h
+ * Author: Arthur Brandao
+ *
+ * Created on 28 novembre 2018
+ */
+
+#ifndef PLAYER_H
+#define PLAYER_H
+
+/* --- Include --- */
+#include "constante.h"
+#include "client.h"
+
+/* --- Structure --- */
+typedef struct{
+    /* Stats basique */
+    int id; //Id du joueur <=> id du Client
+    Client* cli; //Client pour communiquer avec le joueur
+    int life; //Vie
+    int maxLife; //Vie max
+    int speed; //Vitesse de deplacement
+    int classicBomb; //Nombre de bombe classique
+    int mine; //Nombre de mine
+    int remoteBomb; //Nombre de bombe télécommandée
+    int maxBomb; //Nombre max de bombe simultané sur le terrain
+    /* Bonus (Nombre de fois ou le bonus est pris). Les modifications sont toujours calculées par le serveur */
+    int bombUp;
+    int bombDown;
+    int firePower;
+    int scooter;
+    int brokenLeg;
+    int lifeMax;
+    int lifeUp;
+    boolean major; //Seul exception boolean si actif ou non
+}Player;
+
+/* --- Fonctions --- */
+/**
+ * Création d'un joueur
+ * @param Player* La structure à initialiser
+ * @param Client* La structure pour communiquer avec le joueur
+ */
+void create_player(Player*, Client*);
+
+/**
+ * Supprime un joueur
+ * @param Player* La structure à supprimer
+ */
+void delete_player(Player*);
+
+#endif /* PLAYER_H */
+