-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
185 lines (159 loc) · 4.31 KB
/
main.c
File metadata and controls
185 lines (159 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "guilib.h"
#include "struct.h"
#include "strlib.h"
#include "mapping.h"
#include "dumbMd.h"
#include "manualMd.h"
#include "randMd.h"
#include "astarMd.h"
#include "cleverMd.h"
/*! \file main.c
\brief Main file to run the different modes and GUI options.
\author Maeva Arlandis et Alexis Devillard
\version 6.2
\date 10 janvier 2017
*/
extern int debug;
int main()
{
debug=0;
time_t t;
/* Intializes random number generator */
srand((unsigned) time(&t));
Map *L=initMap();
initGUI(L);
//t_move* move=(t_move*) malloc(sizeof(t_move));
printf("MOVE_UP= %d\tMOVE_DOWN= %d\tMOVE_LEFT= %d\tMOVE_RIGHT= %d\t \n ",MOVE_UP,MOVE_DOWN,MOVE_LEFT,MOVE_RIGHT);
int choice=53,i;
addStr(L->infoP1[5]," Select your mode.","");
while(choice!=-1)
{
dispInfo(L);
choice=GUI(L,choice);
switch(choice)
{
case 30:
addStr(L->PlayerName,selectL(L,3,L->guiWins[3]->posButt[0][0],L->guiWins[3]->posButt[0][1]+8,L->listPlrName),"");
choice++;
break;
case 31:
addStr(L->ServerName,selectL(L,3,L->guiWins[3]->posButt[1][0],L->guiWins[3]->posButt[1][1]+8,L->listSvrName),"");
choice++;
break;
case 32:
addStr(L->TimeOut," timeout=",selectL(L,3,L->guiWins[3]->posButt[2][0],L->guiWins[3]->posButt[2][1]+9,L->listTimeOut));
choice++;
break;
case 33:
addStr(L->PortName,selectL(L,3,L->guiWins[3]->posButt[3][0],L->guiWins[3]->posButt[3][1]+7,L->listPrtName),"");
choice++;
break;
case 34://connection to the server
addStr(L->infoP1[5]," ","");
eraseMap(L);
freeMap(L);
getMap(L);//switch of the value getmap return to lauched the game mode
do
{
if(L->players[0]->mode==0)//we are dumb
dumbMode(L);
else if(L->players[0]->mode==1)//we play manual
manualMode(L);
else if(L->players[0]->mode==2)//we play random
randMode(L);
else if(L->players[0]->mode==3)//we play astar
astarMode(L);
else if(L->players[0]->mode==4)//we play clver
{
cleverMode(L);
//return 0;
}
for(i=3;i<7;i++)
{
addStr(L->infoP1[i]," ","");
addStr(L->infoP2[i]," ","");
}
eraseMap(L);
freeMap(L);
}while(contestMode(L));
addStr(L->infoP1[5]," Select your mode.","");
choice=50;
break;
case 35://connection to the server
while(true){
addStr(L->infoP1[5]," ","");
eraseMap(L);
freeMap(L);
getMap(L);//switch of the value getmap return to lauched the game mode
if(L->players[0]->mode==0)//we are dumb
dumbMode(L);
else if(L->players[0]->mode==1)//we play manual
manualMode(L);
else if(L->players[0]->mode==2)//we play random
randMode(L);
else if(L->players[0]->mode==3)//we play astar
astarMode(L);
else if(L->players[0]->mode==4)//we play clever
cleverMode(L);
/*Pause l'application pour i milliseconds*/
clock_t start,end;
start=clock();
int i=50;
while(((end=clock())-start)<=((i*CLOCKS_PER_SEC)/1000));
}
for(i=3;i<7;i++)
{
addStr(L->infoP1[i]," ","");
addStr(L->infoP2[i]," ","");
}
addStr(L->infoP1[5]," Select your mode.","");
choice=50;
break;
/*MANUAL MOVES
case 40:
move->type=MOVE_LEFT;
moveP(L,0,move);
break;
case 41:
move->type=MOVE_UP;
moveP(L,0,move);
break;
case 42:
move->type=MOVE_DOWN;
moveP(L,0,move);
break;
case 43:
move->type=MOVE_RIGHT;
moveP(L,0,move);
break;*/
/*PLAYER MODES*/
case 50://DO NOTHING
case 51://MANUAL
case 52://RANDOM
case 53://ASTAR
case 54://CLEVER
L->players[0]->mode=choice%10;
addStr(L->infoP1[5]," Select the mode of your opponent.","");
choice+=10;
break;
/*OPONENT MODES*/
case 60://DO NOTHING
case 61://MANUAL
case 62://RANDOM MOVEP
case 63://RANDOM MOVEP&M
case 64://ASTAR
case 65://Match
case 66://CONTEST
L->players[1]->mode=choice%10;
addStr(L->infoP1[5]," Select <ENTER> to get a map","");
choice=30;
break;
}
}
//freeMap(L);
freeGUI(L);
return 0;
}