瀏覽代碼

:tada: Ajout structure object

Arthur Brandao 6 年之前
父節點
當前提交
a3e9b437d6
共有 3 個文件被更改,包括 158 次插入4 次删除
  1. 6 4
      Serveur/makefile
  2. 102 0
      Serveur/object.c
  3. 50 0
      Serveur/object.h

+ 6 - 4
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 player.o game.o delay.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 game.o delay.o object.o
 NOM_PROJET = Projet Reseau
 
 #
@@ -103,16 +103,18 @@ arraylist.o: arraylist.c str.h arraylist.h constante.h server.h json.h
 server_tcp.o: server_tcp.c error.h server.h constante.h
 server_udp.o: server_udp.c error.h server.h constante.h
 bomberstudent_server.o: bomberstudent_server.c arraylist.h constante.h \
- server.h json.h str.h bomberstudent_server.h client.h error.h
+ server.h json.h str.h bomberstudent_server.h client.h error.h handler.h \
+ game.h player.h
 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 error.h bomberstudent_server.h constante.h server.h \
- json.h str.h client.h player.h handler.h
+ json.h str.h client.h player.h handler.h game.h
 player.o: player.c player.h constante.h client.h server.h json.h str.h
 game.o: game.c error.h str.h file.h constante.h game.h player.h client.h \
- server.h json.h
+ server.h json.h bomberstudent_server.h
 delay.o: delay.c error.h delay.h constante.h game.h player.h client.h \
  server.h json.h str.h
+object.o: object.c object.h constante.h
 main.o: main.c error.h bomberstudent_server.h constante.h server.h json.h \
  str.h client.h main.h handler.h game.h player.h
 test.o: test.c json.h str.h constante.h arraylist.h server.h error.h \

+ 102 - 0
Serveur/object.c

@@ -0,0 +1,102 @@
+/* 
+ * File:   object.c
+ * Author: Arthur Brandao
+ *
+ * Created on 7 décembre 2018
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "object.h"
+
+/* --- Fonctions publiques --- */
+void object_ini(Object* this){
+    this->first = NULL;
+    this->last = NULL;
+    this->size = 0;
+}
+
+obj_node* object_add(Object* this, int type, int x, int y){
+    obj_node* objn;
+    //Ajout des vthiseurs
+    objn = malloc(sizeof(obj_node));
+    objn->type = type;
+    objn->x = x;
+    objn->y = y;
+    //Lien entre les noeuds
+    objn->next = NULL;
+    if (this->first == NULL) {
+        objn->prev = NULL;
+        this->first = objn;
+        this->last = objn;
+    } else {
+        objn->prev = this->last;
+        this->last->next = objn;
+        this->last = objn;
+    }
+    this->size++;
+    return objn;
+}
+
+obj_node* object_search(Object* this, int type, int x, int y){
+    //Si liste vide
+    if(this->size == 0){
+        return NULL;
+    }
+    //Recherche
+    obj_node* objn = this->first;
+    while(objn != NULL){
+        if(objn->type == type && objn->x == x && objn->y == y){
+            return objn;
+        }
+        objn = objn->next;
+    }
+    return NULL;
+}
+
+void object_delete(Object* this, obj_node* objn){
+    //Liste vide
+    if(this->first == NULL){
+        return;
+    }
+    //Si 1er et seul
+    if (objn->prev == NULL && objn->next == NULL) {
+        this->first = NULL;
+        this->last = NULL;
+    }        
+    //Si 1er et non seul
+    else if (objn->prev == NULL && objn->next != NULL) {
+        objn->next->prev = NULL;
+        this->first = objn->next;
+    }        
+    //Si dernier
+    else if (objn->next == NULL) {
+        objn->prev->next = NULL;
+        this->last = objn->prev;
+    }        
+    //Sinon si il est au milieu
+    else {
+        objn->prev->next = objn->next;
+        objn->next->prev = objn->prev;
+    }
+    //Free
+    free(objn);
+    this->size--;
+}
+
+void object_clean(Object* this){
+    //Liste vide
+    if(this->first == NULL){
+        return;
+    }
+    //Vide liste
+    obj_node* tmp, * objn = this->first;
+    while (objn != NULL) {
+        tmp = objn->next;
+        object_delete(this, objn);
+        objn = tmp;
+    }
+    this->first = NULL;
+    this->last = NULL;
+    this->size = 0;
+}

+ 50 - 0
Serveur/object.h

@@ -0,0 +1,50 @@
+/* 
+ * File:   object.h
+ * Author: Arthur Brandao
+ *
+ * Created on 7 décembre 2018
+ */
+
+#ifndef OBJECT_H
+#define OBJECT_H
+
+/* --- Include --- */
+#include "constante.h"
+
+/* --- Constante --- */
+#define OBJ_BCLASSIC 0
+#define OBJ_BMINE 1
+#define OBJ_BREMOTE 2
+#define OBJ_BOMBUP 3
+#define OBJ_BOMBDOWN 4
+#define OBJ_FIREPOWER 5
+#define OBJ_SCOOTER 6
+#define OBJ_BROKENLEG 7
+#define OBJ_LIFEUP 8
+#define OBJ_LIFEMAX 9
+#define OBJ_MAJOR 10
+
+/* --- Structure --- */
+typedef struct obj_node obj_node;
+struct obj_node{
+    int type;
+    int x;
+    int y;
+    obj_node* prev;
+    obj_node* next;
+};
+typedef struct{
+    obj_node* first;
+    obj_node* last;
+    int size;
+}Object;
+
+/* --- Fonctions --- */
+void object_ini(Object*);
+obj_node* object_add(Object*, int, int, int);
+obj_node* object_search(Object*, int, int, int);
+void object_delete(Object*, obj_node*);
+void object_clean(Object*);
+
+#endif /* OBJECT_H */
+