-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlateau.java
More file actions
465 lines (401 loc) · 12.5 KB
/
Plateau.java
File metadata and controls
465 lines (401 loc) · 12.5 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
import java.util.Scanner;
import java.util.Random;
import java.lang.Math;
public class Plateau {
private int maxLig = 18;
private int maxCol = 45;
private char[][] plateau = new char[maxLig][maxCol];
private Player p;
public Plateau() {
}
public void setItem(int lig, int col, String element) {
if (element == "sword") {
this.plateau[lig][col] = '\u2694'; // E
}
else if (element == "shield") {
this.plateau[lig][col] = '\u25C9'; // B
}
else if (element == "bow") {
this.plateau[lig][col] = '\u21DD';// A
}
else if (element == "armor") {
this.plateau[lig][col] = '\u265E';
}
else if (element == "molotovPotion"){
this.plateau[lig][col] = '\u2620';
}
else if (element == "healPotion") {
this.plateau[lig][col] = '\u2665';
}
else {
System.out.println("L'Item/entité que vous essayez de placer n'existe pas !");
}
}
public void setPlayer1(int lig, int col) {
this.plateau[lig][col] = '\u261D';
}
public void setPlayer2(int lig, int col) {
this.plateau[lig][col] = '\u0032';
}
public void setMonster(int lig, int col, String element) {
if (element == "monster") {
this.plateau[lig][col] = '\u2639';
}
else {
System.out.println("L'Item/entité que vous essayez de placer n'existe pas !");
}
}
public void setWall(int lig, int col, String element) {
if (element == "wall") {
this.plateau[lig][col] = '\u002B';
}
else {
System.out.println("L'Item/entité que vous essayez de placer n'existe pas !");
}
}
public int getItem(int lig, int col) throws InterruptedException {
if ((char) (this.plateau[lig][col]) == '\u2694') {
return 1;
}
else {
if ((char) (this.plateau[lig][col]) == '\u25C9') {
return 2;
}
else {
if ((char) (this.plateau[lig][col]) == '\u21DD') {
return 3;
}
else {
if ((char)(this.plateau[lig][col]) == '\u265E') {
return 4;
}
else {
if ((char)(this.plateau[lig][col]) == '\u2620') {
return 5;
}
else {
if ((char) (this.plateau[lig][col]) == '\u2665') {
return 6;
}
}
}
}
}
System.out.println("In n'y a pas d'item ici !" + "\n");
Thread.sleep(2000);
return 0;
}
}
public void getStatsItem(int x, int y,Player p, Item i, Item i2, Item i3, Item i4, Item i5, Item i6) throws InterruptedException {
switch(this.getItem(x,y)) {
case(1):
p.addInventaire(i3);
this.disparait(x, y);
break;
case(2):
p.addInventaire(i5);
this.disparait(x, y);
break;
case(3):
p.addInventaire(i4);
this.disparait(x, y);
break;
case(4):
p.addInventaire(i6);
this.disparait(x, y);
break;
case(5):
p.addInventaire(i2);
this.disparait(x, y);
break;
case(6):
p.addInventaire(i);
this.disparait(x, y);
break;
default:
break;
}
}
public int getEnnemi(int lig, int col) {
if ((char) (this.plateau[lig][col]) == '\u2639') {
return 1;
}
else if((char) (this.plateau[lig][col]) == '\u0032') {
return 2;
}
return 0;
}
public void getStatsEnnemi(int x, int y,Player p, Player p2, Monster m) throws InterruptedException{
switch(this.getEnnemi(x,y)) {
case(1):
p.attackEnnemi(m);
if (m.checkLevelDmg() == "Mort") {
this.disparait(x, y);
}
break;
case(2):
p.attackEnnemi(p2);
break;
default:
System.out.println("Il n'y a pas d'ennemi ici !" + "\n");
Thread.sleep(2000);
break;
}
}
public void disparait(int x, int y) {
this.plateau[x][y] = ' ';
}
public int[] getPlayerPos() {
int positionX = 0;
int positionY = 0;
boolean exit = false;
for (int i=0; i<this.maxLig && exit == false; i++) {
for (int j=0; j<this.maxCol && exit == false; j++) {
if (this.plateau[i][j] == '\u261D'){
exit = true;
}
positionY = j;
}
positionX = i;
}
return new int[] {positionX,positionY};
}
public int[] getMonsterPos() {
int positionX = 0;
int positionY = 0;
boolean exit = false;
for (int i=0; i<this.maxLig && exit == false; i++) {
for (int j=0; j<this.maxCol && exit == false; j++) {
if (this.plateau[i][j] == '\u2639'){
exit = true;
}
positionY = j;
}
positionX = i;
}
return new int[] {positionX,positionY};
}
public void movePlayer(char direction, int x, int y) throws InterruptedException {
if (direction == 'b') {
if (isCaseEmpty(x+1,y)) {
this.plateau[x][y] = ' '; //on efface l'ancienne position du player
this.plateau[x+1][y] = '\u261D'; //on place le player au nouvel coordonnées
}
else {
System.out.println("Vous ne pouvez pas vous déplacer ici !");
Thread.sleep(3000);
}
}
else if (direction == 'h'){
if (isCaseEmpty(x-1,y)) {
this.plateau[x][y] = ' '; //on efface l'ancienne position du player
this.plateau[x-1][y] = '\u261D'; //on place le player au nouvel coordonnées
}
else {
System.out.println("Vous ne pouvez pas vous déplacer ici !");
Thread.sleep(3000);
}
}
else if (direction == 'd'){
if (isCaseEmpty(x,y+1)) {
this.plateau[x][y] = ' '; //on efface l'ancienne position du player
this.plateau[x][y+1] = '\u261D'; //on place le player au nouvel coordonnées
}
else {
System.out.println("Vous ne pouvez pas vous déplacer ici !");
Thread.sleep(3000);
}
}
else if (direction == 'g'){
if (isCaseEmpty(x,y-1)) {
this.plateau[x][y] = ' '; //on efface l'ancienne position du player
this.plateau[x][y-1] = '\u261D'; //on place le player au nouvel coordonnées
}
else {
System.out.println("Vous ne pouvez pas vous déplacer ici !");
Thread.sleep(3000);
}
}
}
public char[][] initPlateau() {
for(int lig = 0; lig < this.maxLig; lig++){
for(int col = 0; col < this.maxCol; col++) {
if (lig == 0 || lig == this.maxLig-1 || col == 0 || col == this.maxCol-1) {
plateau[lig][col] = '\u002B';
}
else {
plateau[lig][col] = ' ';
}
}
}
return plateau;
}
public void dispPlateau() {
for (int i=0; i<this.maxLig;i++) {
for (int j=0;j<this.maxCol;j++) {
System.out.print(this.plateau[i][j]);
}
System.out.println("");
}
}
public void playerRangeItem(int x, int y, Player p, Item i, Item i2, Item i3, Item i4, Item i5, Item i6) throws InterruptedException {
Scanner reader = new Scanner(System.in);
System.out.println("Où voulez vous ramasser l'objet : "+"\n"+"1-En haut ?"+"\n"+
"2-En bas ?"+"\n"+
"3-A gauche?"+"\n"+
"4-A droite ?"+"\n"+
"5-En haut, à gauche ?"+"\n"+
"6-En haut, à droite ?"+"\n"+
"7-En bas, à gauche ?"+"\n"+
"8-En bas, à droite ?");
int choix = reader.nextInt();
if (choix == 1) {
int h = x-1;
this.getStatsItem(h,y,p,i,i2,i3,i4,i5,i6);
}
else if (choix == 2) {
int b = x+1;
this.getStatsItem(b,y,p,i,i2,i3,i4,i5,i6);
}
else if (choix == 3) {
int g = y-1;
this.getStatsItem(x,g,p,i,i2,i3,i4,i5,i6);
}
else if (choix == 4) {
int d = y+1;
this.getStatsItem(x,d,p,i,i2,i3,i4,i5,i6);
}
else if(choix == 5){
int diag1 = x-1;
int diag2 = y-1;
this.getStatsItem(diag1,diag2,p,i,i2,i3,i4,i5,i6);
}
else if(choix == 6){
int diag1 = x-1;
int diag2 = y+1;
this.getStatsItem(diag1,diag2,p,i,i2,i3,i4,i5,i6);
}
else if(choix == 7){
int diag1 = x+1;
int diag2 = y+1;
this.getStatsItem(diag1,diag2,p,i,i2,i3,i4,i5,i6);
}
else if(choix == 8){
int diag1 = x+1;
int diag2 = y+1;
this.getStatsItem(diag1,diag2,p,i,i2,i3,i4,i5,i6);
}
else {
System.out.println("Erreur");
}
}
public void playerRangeEnnemi(int x, int y, Player p, Player p2, Monster m) throws InterruptedException {
Scanner sc = new Scanner(System.in);
System.out.println("Où se situe le monstre : "+"\n"+"1-En haut ?"+"\n"+
"2-En bas ?"+"\n"+
"3-A gauche?"+"\n"+
"4-A droite ?"+"\n"+
"5-En haut, à gauche ?"+"\n"+
"6-En haut, à droite ?"+"\n"+
"7-En bas, à gauche ?"+"\n"+
"8-En bas, à droite ?");
int choix = sc.nextInt();
if (choix == 1) {
int h = x-1;
this.getStatsEnnemi(h,y, p, p2, m);
}
else if (choix == 2) {
int b = x+1;
this.getStatsEnnemi(b,y, p, p2, m);
}
else if (choix == 3) {
int g = y-1;
this.getStatsEnnemi(g,y, p, p2, m);
}
else if (choix == 4) {
int d = y+1;
this.getStatsEnnemi(d,y, p, p2, m);
}
else if(choix == 5){
int diag1 = x-1;
int diag2 = y-1;
this.getStatsEnnemi(diag1,diag2, p, p2, m);
}
else if(choix == 6){
int diag1 = x-1;
int diag2 = y+1;
this.getStatsEnnemi(diag1,diag2, p, p2, m);
}
else if(choix == 7){
int diag1 = x+1;
int diag2 = y+1;
this.getStatsEnnemi(diag1,diag2, p, p2, m);
}
else if(choix == 8){
int diag1 = x+1;
int diag2 = y+1;
this.getStatsEnnemi(diag1,diag2, p, p2, m);
}
else {
System.out.println("Erreur");
}
}
public void randomMove(int x, int y) {
Random r = new Random();
this.plateau[x][y] = ' ';
int newX = r.nextInt(3)-1;
int newY = r.nextInt(3)-1;
this.plateau[x+newX][y+newY] = '\u004D';
}
public boolean isCaseEmpty(int x, int y) {
if (this.plateau[x][y] == ' ') {
return true;
}
else {
return false;
}
}
public void setRandomWall(Plateau p) {
for (int i=0; i<6; i++) {
int x = (int) ((((this.maxLig)-3)-3)*Math.random()) + 3; //(int) ((max-min)*Math.random()) + min;
int y = (int) ((((this.maxCol)-3)-3)*Math.random()) + 3;
int x2 = (int) ((((this.maxLig)-3)-3)*Math.random()) + 3; //(int) ((max-min)*Math.random()) + min;
int y2 = (int) ((((this.maxCol)-3)-3)*Math.random()) + 3;
if (isCaseEmpty(x,y)) {
//HORIZONTALEMENT
p.setWall(x, y, "wall");
p.setWall(x, y+1, "wall");
p.setWall(x, y+2, "wall");
p.setWall(x, y+3, "wall");
//VERTICALEMENT
p.setWall(x2, y2, "wall");
p.setWall(x2+1, y2, "wall");
}
}
}
public void setRandomPlayer(Plateau p) {
int x = (int) ((((this.maxLig)-1)-1)*Math.random()) + 1; //(int) ((max-min)*Math.random()) + min;
int y = (int) ((((this.maxCol)-1)-1)*Math.random()) + 1;
if (isCaseEmpty(x,y)) {
p.setPlayer1(x, y);
}
}
public void setRandomItem(Plateau p) {
String item[] = {"sword","shield","bow","armor","molotovPotion","healPotion","sword","shield","bow","armor","molotovPotion","healPotion"};
for (int i=0; i<10; i++) {
int x = (int) ((((this.maxLig)-1)-1)*Math.random()) + 1; //(int) ((max-min)*Math.random()) + min;
int y = (int) ((((this.maxCol)-1)-1)*Math.random()) + 1;
if (isCaseEmpty(x,y)) {
p.setItem(x, y, item[i]);
}
}
}
public Monster setRandomMonster() {
int x = (int) ((((this.maxLig)-1)-1)*Math.random()) + 1; //(int) ((max-min)*Math.random()) + min;
int y = (int) ((((this.maxCol)-1)-1)*Math.random()) + 1;
if (isCaseEmpty(x,y)) {
this.setMonster(x, y, "monster");
}
return new Monster();
}
}