-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJeu.cpp
More file actions
793 lines (663 loc) · 30 KB
/
Jeu.cpp
File metadata and controls
793 lines (663 loc) · 30 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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
//
// Created by lucas on 24/03/2023.
//
#include <iostream>
#include "Jeu.h"
#include "Schotten_Totten.h"
#include "Pioche.h"
#include "defausse.h"
using namespace std;
Jeu::Jeu(string mode, string v, int nb_p, int nb_joueurs_h, vector<string>& noms_j, int nb_max_j) {
mode_jeu = mode;
variante = v;
nb_parties_jouees = 0;
joueur_actuel = 1;
//schottenTotten = new Schotten_Totten();
nb_max_joueurs = nb_max_j;
variantes.push_back("normal");
variantes.push_back("tactique");
//setNb_parties();
noms_joueurs = noms_j;
nb_parties = nb_p;
nb_joueurs_humains = nb_joueurs_h;
choix_jeu();
//setNb_joueurs_humains();
resume();
cout << "resume fait" << endl;
creation_joueurs();
distribution_cartes();
cout << "cartes distribuees" << endl;
}
void Jeu::setNb_parties() {
cout << "Nombre de parties : " << endl;
cin >> nb_parties;
cout << "Nombre de parties qui sera joue : " << nb_parties << endl;
}
void Jeu::choix_jeu() {
if (mode_jeu == "Schotten Totten") {
if (variante == "normal") {
cout << "Schotten Totten normal " << endl;
schottenTotten = new Schotten_Totten();
cout << "Schotten Totten cree" << endl;
Pioche* pioche = new Pioche(schottenTotten->getCartesClan());
pioches["pioche clan"] = pioche;
cout << "Pioche et jeu crees" << endl;
}
else {
cout << "Schotten Totten tactique " << endl;
schottenTotten = new Tactique();
pioches["pioche tactique"] = new Pioche(schottenTotten->getCartesTactique());
pioches["pioche clan"] = new Pioche(schottenTotten->getCartesClan());
defausse = new Defausse();
}
}
affichageConsole = new Affichage_console(variante);
/*
for (int i = 0; i < schottenTotten->getNb_Cartes_clan(); i++) {
cout << schottenTotten->getCarte_clan(i) << endl;
cout << i << endl;
}
*/
cout << "jeu cree" << endl;
}
void Jeu::changer_joueur() {
if (joueur_actuel == 1) {
joueur_actuel = 2;
}
else {
joueur_actuel = 1;
}
if (nb_joueurs_humains == 2) { //Partie avec une IA
cout << "\n\n\n\n\n\n\n\n\n\n\nChangez de joueur et appuyez sur entree ";
cin.ignore();
cin.get();
}
}
bool Jeu::action_carte_ruse(Carte& carte_ruse) {
int choix;
int choix_pioche;
int nb_cartes_clan;
int nb_cartes_tactique;
int carte_supp;
int choix_borne;
int choix2;
cout << carte_ruse.getId() << endl;
/* ========================Chasseur de Tete======================== */
if (carte_ruse.getId() == "Chasseur de Tête") {
//proposition();
cout << "Les choix : " << endl;
cout << "1. Piochez trois cartes d'une pioche" << endl;
cout << "2. Piochez trois cartes de deux pioches" << endl;
cout << "Choisissez ce que vous voulez faire (entrez 1 ou 2):" << endl;
if (joueurs[joueur_actuel-1]->getIa()) choix = IA::choix_entier(1, 2);
else cin >> choix;
if (choix == 1) {
cout << "1. Piochez dans la pioche clan" << endl;
cout << "2. Piochez dans la pioche tactique" << endl;
if (joueurs[joueur_actuel-1]->getIa()) choix = IA::choix_entier(1, 2);
else cin >> choix;
if (choix_pioche == 1) {
//Pioche 3 cartes dans la pioche clan
for (int i = 0; i < carte_ruse.getNb_cartes(); i++) {
joueurs[joueur_actuel-1]->ajout_carte(&pioches["pioche clan"]->piocher_carte());
}
}
else if (choix_pioche == 2){
//Pioche 3 cartes dans la pioche tactique
for (int i = 0; i < carte_ruse.getNb_cartes(); i++) {
joueurs[joueur_actuel-1]->ajout_carte(&pioches["pioche tactique"]->piocher_carte());
}
}
else {
//Erreur de choix
cout << "erreur de choix" << endl;
return false;
}
}
if (choix == 2) {
//3 cartes dans deux pioches;
cout << "Combien de cartes de la pioche clan" << endl;
if (joueurs[joueur_actuel-1]->getIa()) nb_cartes_clan = IA::choix_entier(1, 2);
else cin >> nb_cartes_clan;
if (nb_cartes_clan >= carte_ruse.getNb_cartes()) {
cout << "erreur trop de cartes ont été piochees." << endl;
}
for (int i = 0; i < nb_cartes_clan; i++) {
joueurs[joueur_actuel-1]->ajout_carte(&pioches["pioche clan"]->piocher_carte());
}
cout << "cela fait donc " << to_string(carte_ruse.getNb_cartes() - nb_cartes_clan) << "cartes tactique à piocher" << endl;
for (int i = 0; i < carte_ruse.getNb_cartes() - nb_cartes_clan; i++) {
joueurs[joueur_actuel-1]->ajout_carte(&pioches["pioche tactique"]->piocher_carte());
}
}
else {
//Erreur de choix
cout << "erreur de choix" << endl;
return false;
}
if (!joueurs[joueur_actuel-1]->getIa()) {
cout << "voici vos cartes" << endl;
affichageConsole->afficher_cartes_joueur(joueurs[joueur_actuel - 1]->getCartes());
cout << "vous devez en enlever deux cartes" << endl;
}
Carte& c1 = joueurs[joueur_actuel-1]->choix_carte();
Carte& c2 = joueurs[joueur_actuel-1]->choix_carte();
if (c1.getType() == "clan") {
pioches["pioche clan"]->ajoutcarte(&c1);
}
else {
pioches["pioche tactique"]->ajoutcarte(&c1);
}
if (c2.getType() == "clan") {
pioches["pioche clan"]->ajoutcarte(&c2);
}
else {
pioches["pioche tactique"]->ajoutcarte(&c2);
}
return true;
}
/* ========================Stratege======================== */
else if (carte_ruse.getId() == "Stratège") {
cout << "choisissez la borne où vous voulez retirer une de vos cartes (entre 1 et 9)" << endl;
if (joueurs[joueur_actuel-1]->getIa()) choix_borne = IA::choix_entier(1, 9);
else cin >> choix_borne;
if (schottenTotten->bornes[choix_borne-1]->GetPossesseur()) {
cout << "borne revendiquee" << endl;
return false;
}
if (joueur_actuel == 1) {
cout << "carte que vous pouvez prendre : " << endl;
if (schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1().empty()) {
cout << "rien n'a prendre ici" << endl;
return false;
}
for (int i = 0; i < schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1().size(); i++) {
cout << to_string(i+1) << *schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1()[i] << endl;
}
cin >> carte_supp;
if (carte_supp < 1 || carte_supp > schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1().size()) {
cout << "erreur valeur" << endl;
return false;
}
}
else {
cout << "carte que vous pouvez prendre : " << endl;
if (schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().empty()) {
cout << "rien n'a prendre ici" << endl;
return false;
}
for (int i = 0; i < schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().size(); i++) {
cout << to_string(i+1) << *schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2()[i] << endl;
}
if (joueurs[joueur_actuel-1]->getIa())
carte_supp = IA::choix_entier(1, schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().size());
else cin >> carte_supp;
if (carte_supp < 1 || carte_supp > schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().size()) {
cout << "erreur valeur" << endl;
return false;
}
}
Carte& carte = schottenTotten->bornes[choix_borne-1]->supprimer_carte(joueur_actuel, carte_supp-1);
cout << "Que souhaitez vous faire avec cette carte ?" << endl;
cout << "1. La mettre sur une autre borne" << endl;
cout << "2. La défausser" << endl;
cout << "Entrez 1 ou 2 : " << endl;
if (joueurs[joueur_actuel-1]->getIa()) choix2 = IA::choix_entier(1, 2);
else cin >> choix2;
if (choix2 == 1) {
//Demander sur quelle borne mettre la carte et ajouter la carte + vérifier la borne
cout << "sur quelle borne entre (1 et 9) vous voulez mettre cette carte" << endl;
if (joueurs[joueur_actuel-1]->getIa()) choix_borne = IA::choix_entier(1, 9);
else cin >> choix_borne;
if (choix_borne < 1 || choix_borne > 9) {
cout << "erreur nombre" << endl;
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, joueur_actuel);
return false;
}
if (schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, joueur_actuel)) {
cout << "carte ajoutee" << endl;
return true;
}
else {
cout << "erreur ajout carte" << endl;
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, joueur_actuel);
return false;
}
}
else if (choix2 == 2) {
defausse->ajout_defausse(&carte);
return true;
}
}// Stratege
/* ========================Banshee======================== */
else if (carte_ruse.getId() == "Banshee") {
cout << "choisissez la borne (entre 1 et 9) ou vous voulez supprimer une carte de votre adversaire" << endl;
if (joueurs[joueur_actuel-1]->getIa()) choix_borne = IA::choix_entier(1, 9);
else cin >> choix_borne;
if (choix_borne < 1 || choix_borne > 9) {
return false;
}
if (schottenTotten->bornes[choix_borne-1]->GetPossesseur()) {
cout << "borne revendiquee" << endl;
return false;
}
cout << "choisissez la carte à supp" << endl;
if (joueur_actuel == 2) {
for (int i = 0; i < schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1().size(); i++) {
cout << to_string(i+1) << " " << *schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1()[i] << endl;
}
if (joueurs[joueur_actuel - 1]->getIa())
carte_supp = IA::choix_entier(1, schottenTotten->bornes[choix_borne - 1]->getCartes_joueur_1().size());
else cin >> carte_supp;
if (carte_supp < 1 || carte_supp > schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1().size()) {
cout << "carte invalide" << endl;
return false;
}
Carte& carte = schottenTotten->bornes[choix_borne-1]->supprimer_carte(1, carte_supp-1);
defausse->ajout_defausse(&carte);
return true;
}
if (joueur_actuel == 1) {
for (int i = 0; i < schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().size(); i++) {
cout << to_string(i+1) << " " << *schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2()[i] << endl;
}
cin >> carte_supp;
if (carte_supp < 1 || carte_supp > schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().size()) {
cout << "carte invalide" << endl;
return false;
}
Carte& carte = schottenTotten->bornes[choix_borne-1]->supprimer_carte(2, carte_supp-1);
defausse->ajout_defausse(&carte);
return true;
}
}// Banshee
/* ========================Traitre======================== */
else if (carte_ruse.getId() == "Traitre") {
cout << "choisissez la borne (entre 1 et 9) ou vous voulez supprimer une carte de votre adversaire (et la mettre de votre cote)" << endl;
if (joueurs[joueur_actuel-1]->getIa()) choix_borne = IA::choix_entier(1, 9);
else cin >> choix_borne;
if (choix_borne < 1 || choix_borne > 9) {
return false;
}
if (schottenTotten->bornes[choix_borne-1]->GetPossesseur()) {
cout << "borne revendiquee" << endl;
return false;
}
cout << "choisissez la carte à supp" << endl;
if (joueur_actuel == 2) {
for (int i = 0; i < schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1().size(); i++) {
cout << to_string(i+1) << " " << schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1()[i] << endl;
}
if (joueurs[joueur_actuel-1]->getIa())
choix_borne = IA::choix_entier(1, carte_supp = schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1().size());
else cin >> carte_supp;
if (carte_supp < 1 || carte_supp > schottenTotten->bornes[choix_borne-1]->getCartes_joueur_1().size()) {
cout << "carte invalide" << endl;
return false;
}
Carte& carte = schottenTotten->bornes[choix_borne-1]->supprimer_carte(1, carte_supp-1);
cout << "sur quelle borne vous souhaitez ajouter la carte (entre 1 et 9)" << endl;
if (joueurs[joueur_actuel-1]->getIa()) choix_borne = IA::choix_entier(1, 9);
else cin >> choix_borne;
if (choix_borne < 1 || choix_borne > 9) {
cout << "erreur borne invalide";
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, 1);
return false;
}
if (schottenTotten->bornes[choix_borne-1]->GetPossesseur()) {
cout << "erreur borne revendiquee" << endl;
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, 1);
return false;
}
if (joueur_actuel == 2 and schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().size() == schottenTotten->bornes[choix_borne-1]->getNbMaxCartes()) {
cout << "borne pleine" << endl;
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, 1);
return false;
}
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, 2);
defausse->ajout_defausse(&carte_ruse);
return true;
}
if (joueur_actuel == 1) {
for (int i = 0; i < schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().size(); i++) {
cout << to_string(i+1) << " " << schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2()[i] << endl;
}
cin >> carte_supp;
if (carte_supp < 1 || carte_supp > schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().size()) {
cout << "carte invalide" << endl;
return false;
}
Carte& carte = schottenTotten->bornes[choix_borne-1]->supprimer_carte(2, carte_supp-1);
cout << "sur quelle borne vous souhaitez ajouter la carte (entre 1 et 9)" << endl;
cin >> choix_borne;
if (choix_borne < 1 || choix_borne > 9) {
cout << "erreur borne invalide";
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, 2);
return false;
}
if (schottenTotten->bornes[choix_borne-1]->GetPossesseur()) {
cout << "erreur borne revendiquee" << endl;
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, 2);
return false;
}
if (joueur_actuel == 2 and schottenTotten->bornes[choix_borne-1]->getCartes_joueur_2().size() == schottenTotten->bornes[choix_borne-1]->getNbMaxCartes()) {
cout << "borne pleine" << endl;
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, 2);
return false;
}
schottenTotten->bornes[choix_borne-1]->ajout_Carte(&carte, 1);
defausse->ajout_defausse(&carte_ruse);
return true;
}
}// Traitre
//defausse->ajout_defausse(&carte_ruse);
return true;
}
bool Jeu::verifPioche(string pioche) {
if (pioches[pioche]->est_vide()) {
cout << "pioche vide" << endl;
return false;
}
return true;
}
void Jeu::choixPioche() {
int choix_pioche;
if (variante == "normal" && verifPioche("pioche clan")) {
cout << "carte piochee automatiquement dans la pioche";
joueurs[joueur_actuel-1]->ajout_carte(&pioches["pioche clan"]->piocher_carte());
}
else {
if (!verifPioche("pioche clan") && !verifPioche("pioche tactique")) {
cout << "pioches vides" << endl;
}
affichageConsole->choix_pioche();
if (joueurs[joueur_actuel-1]->getIa()) choix_pioche = IA::choix_entier(1, 2);
else cin >> choix_pioche;
if (choix_pioche == 1 && verifPioche("pioche clan")) {
joueurs[joueur_actuel-1]->ajout_carte(&pioches["pioche clan"]->piocher_carte());
}
else if (choix_pioche == 2 && verifPioche("pioche tactique")) {
joueurs[joueur_actuel-1]->ajout_carte(&pioches["pioche tactique"]->piocher_carte());
}
else {
cout << "mauvais nombre entree" << endl;
return;
}
}
}
int Jeu::autreJoueur() {
if (joueur_actuel == 2) {
return 0;
}
return 1;
}
void Jeu::jouer_tour() {
if (verif_partie()) {
cout << "partie terminee" << endl;
nb_parties_jouees++;
return;
}
if (gagnant()) {
cout << "Partie terminee" << endl;
nb_parties_jouees++;
return;
}
int borne;
int choix;
int choix_pioche;
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
cout << "----------------------------------------------------" << endl;
cout << "\t\t\tDebut du tour" << endl;
cout << "Joueur actuel : " << joueurs[joueur_actuel-1]->getNom() << endl;
cout << "----------------------------------------------------" << endl;
affichageConsole->afficher_cartes_bornes(schottenTotten->bornes, joueur_actuel);
affichageConsole->afficher_cartes_joueur(joueurs[joueur_actuel-1]->getCartes());
affichageConsole->Afficher_proposition();
if (joueurs[joueur_actuel-1]->getIa() == true) {
cout << "true\n";
choix = IA::choix_entier(1, 1);
cout << choix << "\n";
}
else {
//cout << "false\n";
cin >> choix;
}
if (choix == 1) {
Carte& carte = joueurs[joueur_actuel-1]->choix_carte();
//vérifier que la carte peut-être posée sur une borne ou pas.
//cout << "on a la carte" << endl;
cout << "carte : " << carte.getType() << endl;
if (carte.getType() != "Clan" && joueurs[joueur_actuel-1]->getNbTactiqueJouees() > joueurs[autreJoueur()]->getNbTactiqueJouees())
{
cout << "vous avez jouez plus de cartes tactique que votre adversaire" << endl;
joueurs[joueur_actuel-1]->ajout_carte(&carte);
return;
}
if (carte.getType() == "Combat") {
//Cas ou la carte est une carte tactique de combat
cout << "Choisissez la borne ou voulez poser la carte Combat (nombre entre 1 et 9, 1 etant la borne la plus a gauche)" << endl;
if (joueurs[joueur_actuel-1]->getIa()) borne = IA::choix_entier(1, schottenTotten->getNb_bornes());
else cin >> borne;
if (borne < 1 || borne > 9) {
cout << "mauvaise borne" << endl;
joueurs[joueur_actuel-1]->ajout_carte(&carte);
return;
}
if (schottenTotten->bornes[borne-1]->GetPossesseur()) {
cout << "borne déjà revendiquee" << endl;
return;
}
schottenTotten->bornes[borne-1]->ajoutRegle(carte.getRegle());
joueurs[joueur_actuel-1]->carteTactiqueJouee();
choixPioche();
changer_joueur();
return;
}
if (carte.getType() == "Ruse") {
if (action_carte_ruse(carte)) {
defausse->ajout_defausse(&carte);
choixPioche();
joueurs[joueur_actuel-1]->carteTactiqueJouee();
changer_joueur();
return;
}
joueurs[joueur_actuel-1]->ajout_carte(&carte);
return;
}
borne = joueurs[joueur_actuel-1]->choix_borne();
if (schottenTotten->bornes[borne-1]->ajout_Carte(&carte, joueur_actuel)) {
choixPioche();
//joueurs[joueur_actuel-1]->carteTactiqueJouee();
//Regarder revendication
//Regarder s'il y a un gagnant pour la partie et regarder si toutes les parties ont été jouées.
if (carte.getType() == "Elite") {
joueurs[joueur_actuel-1]->carteTactiqueJouee();
}
changer_joueur();
}
else {
cout << "pas possible de poser une carte sur cette borne " << endl;
joueurs[joueur_actuel-1]->ajout_carte(&carte);
}
}
if (choix == 2 && variante == variantes[1]) {
//consulter défausse. Fonctionne uniquement en mode tactique.
affichageConsole->afficher_défausse(*defausse);
}
//Revendication de bornes
for (int i = 0; i < schottenTotten->bornes.size(); i++) {
revendication_borne(i);
}
}
bool Jeu::verif_partie() {
//Vérifie si une partie
if (variante == "normal") {
if (pioches["pioche clan"]->est_vide()) {
cout << "plus possible de piocher des cartes" << endl;
return true;
}
}
if (variante == "tactique")
if (pioches["pioche tactique"]->est_vide() && pioches["pioche clan"]->est_vide()) {
cout << "plus possible de piocher des cartes" << endl;
return true;
}
return false;
}
void Jeu::designe_premier_joueur() {
cout << "Lequel des deux joueurs a voyagé le plus récemment le plus près de l'Ecosse (Joueur 1 ou Joueur 2) ?";
cin >> joueur_actuel;
if (joueur_actuel != 1 && joueur_actuel != 2) {
throw "erreur : valeur invalide";
}
}
void Jeu::setNb_joueurs_humains() {
cout << "Nombre de joueurs humains : " << endl;
cin >> nb_joueurs_humains;
if (nb_joueurs_humains < 0 || nb_joueurs_humains > nb_max_joueurs) {
throw "erreur : valeur invalide";
}
}
void Jeu::creation_joueurs() {
string nom;
string nom2;
if (nb_joueurs_humains == 2) {
cout << "2 joueurs humains" << endl;
//cout << "nom joueur 1 : " << endl;
//cin >> nom;
joueurs.push_back(new Joueur(noms_joueurs[0], schottenTotten->getNb_Cartes_par_joueur()));
cout << "nom joueur 2 : " << endl;
//cin >> nom2;
joueurs.push_back(new Joueur(noms_joueurs[1], schottenTotten->getNb_Cartes_par_joueur()));
}
else if (nb_joueurs_humains == 1) {
cout << "1 joueurs humains" << endl;
cout << "Entrez le nom du joueur : " << endl;
//cin >> nom;
joueurs.push_back(new Joueur(noms_joueurs[0], schottenTotten->getNb_Cartes_par_joueur()));
joueurs.push_back(new IA("Alfred l'IA", schottenTotten->getNb_Cartes_par_joueur()));
}
}
void Jeu::resume() {
cout << "Nombre de parties : " << nb_parties << " Nombre de joueurs humains : " << nb_joueurs_humains << " mode : " << mode_jeu << " variante : " << variante << endl;
}
void Jeu::distribution_cartes() {
//cout << "distribution cartes" << endl;
for (int i = 0; i < schottenTotten->getNb_Cartes_par_joueur() * 2; i++) {
//Distribuer cartes
//cout << "distribue carte" << to_string(i) << endl;
if (i%2 == 0) {
cout << "dans i%2" << endl;
Carte& c = pioches["pioche clan"]->piocher_carte();
joueurs[0]->ajout_carte(&c);
}
else {
joueurs[1]->ajout_carte(&pioches["pioche clan"]->piocher_carte());
}
}
}
bool Jeu::gagnant() {
int bornes_j1 = 0;
int bornes_j2 = 0;
for (int i = 0; i < schottenTotten->bornes.size(); i++) {
if (schottenTotten->bornes[i]->GetPossesseur() == 1) {
bornes_j1++;
}
else if (schottenTotten->bornes[i]->GetPossesseur() == 2) {
bornes_j2++;
}
}
if (bornes_j1 == 5) {
cout << "Joueur 1 gagne" << endl;
joueurs[0]->setNbPoints(5);
joueur_gagnant = 1;
return true;
}
if (bornes_j2 == 5) {
cout << "Joueur 2 gagne" << endl;
joueurs[1]->setNbPoints(5);
joueur_gagnant = 2;
return true;
}
for (int i = 0; i < schottenTotten->bornes.size()-2; i++) {
if (schottenTotten->bornes[i]->GetPossesseur() == 1 && schottenTotten->bornes[i]->GetPossesseur() == schottenTotten->bornes[i+1]->GetPossesseur() && schottenTotten->bornes[i+1]->GetPossesseur() == schottenTotten->bornes[i+2]->GetPossesseur()) {
cout << schottenTotten->bornes[i]->GetPossesseur() << endl;
cout << "Joueur " << joueurs[0]->getNom() << " a gagne" << endl;
joueurs[schottenTotten->bornes[i]->GetPossesseur()-1]->setNbPoints(5);
joueur_gagnant = schottenTotten->bornes[i]->GetPossesseur();
return true;
}
if (schottenTotten->bornes[i]->GetPossesseur() == 2 && schottenTotten->bornes[i]->GetPossesseur() == schottenTotten->bornes[i+1]->GetPossesseur() && schottenTotten->bornes[i+1]->GetPossesseur() == schottenTotten->bornes[i+2]->GetPossesseur()) {
cout << schottenTotten->bornes[i]->GetPossesseur() << endl;
cout << "Joueur " << joueurs[1]->getNom() << " a gagne" << endl;
joueurs[schottenTotten->bornes[i]->GetPossesseur()-1]->setNbPoints(5);
joueur_gagnant = schottenTotten->bornes[i]->GetPossesseur();
return true;
}
}
return false;
}
void Jeu::revendication_borne(int i) {
if (!schottenTotten->bornes[i]->GetPossesseur() && schottenTotten->bornes[i]->getCartes_joueur_1().size() ==
schottenTotten->bornes[i]->getCartes_joueur_2().size() && schottenTotten->bornes[i]->getCartes_joueur_1().size() == schottenTotten->bornes[i]->getNbMaxCartes()) {
//Les deux ont le max de cartes
//Il faut demander la valeur des cartes tactiques
affichageConsole->afficher_cartes_bornes(schottenTotten->bornes, joueur_actuel);
cout << "\n\n\n\n\n" << "la borne : " << to_string(i+1) << " a un nombre max de cartes pour chacun des joueurs" << endl;
//schottenTotten->bornes[i]->demander_valeurs(1);
//schottenTotten->bornes[i]->demander_valeurs(2);
revendication = new Revendication(schottenTotten->bornes[i]);
schottenTotten->bornes[i]->setPossesseur(revendication->Revendiquant_avec_max_cartes());
cout << "possesseur " << schottenTotten->bornes[i]->GetPossesseur();
cout << "Le joueur :" << joueurs[schottenTotten->bornes[i]->GetPossesseur()-1]->getNom() << " a revendique" << endl;
}
if (!schottenTotten->bornes[i]->GetPossesseur() && schottenTotten->bornes[i]->getCartes_joueur_1().size() == schottenTotten->bornes[i]->getNbMaxCartes()) {
//Joueur 1 peut revendiquer
revendication = new Revendication(schottenTotten->bornes[i]);
Combinaison* combi_j1;
if (schottenTotten->bornes[i]->getCartes_joueur_1().size() == 3) {
combi_j1 = new Combinaison(schottenTotten->bornes[i]->getCartes_joueur_1()[0],schottenTotten->bornes[i]->getCartes_joueur_1()[1], schottenTotten->bornes[i]->getCartes_joueur_1()[2], 3);
}
else if (schottenTotten->bornes[i]->getCartes_joueur_1().size() == 4) {
combi_j1 = new Combinaison(schottenTotten->bornes[i]->getCartes_joueur_1()[0],schottenTotten->bornes[i]->getCartes_joueur_1()[1], schottenTotten->bornes[i]->getCartes_joueur_1()[2], schottenTotten->bornes[i]->getCartes_joueur_1()[3], 4);
}
vector<Carte*> cartes_combi;
for (int i = 0; i < schottenTotten->cartes.size(); i++) {
cartes_combi.push_back(schottenTotten->cartes[i]);
}
vector<Carte*> cartes_adversaire = schottenTotten->bornes[i]->getCartes_joueur_2();
if (revendication->PotentielleCombinaison(schottenTotten->bornes, cartes_combi, combi_j1, cartes_adversaire)) {
schottenTotten->bornes[i]->setPossesseur(0);
}
else {
schottenTotten->bornes[i]->setPossesseur(1);
cout << "Le joueur :" << joueurs[0]->getNom() << " a revendique" << endl;
}
}
if (!schottenTotten->bornes[i]->GetPossesseur() && schottenTotten->bornes[i]->getCartes_joueur_2().size() == schottenTotten->bornes[i]->getNbMaxCartes()) {
//Joueur 2 peut revendiquer
revendication = new Revendication(schottenTotten->bornes[i]);
vector<Carte*> cartes_combi;
for (int i = 0; i < schottenTotten->cartes.size(); i++) {
cartes_combi.push_back(schottenTotten->cartes[i]);
}
Combinaison* combi_j2;
if (schottenTotten->bornes[i]->getCartes_joueur_2().size() == 3) {
combi_j2 = new Combinaison(schottenTotten->bornes[i]->getCartes_joueur_2()[0],schottenTotten->bornes[i]->getCartes_joueur_2()[1], schottenTotten->bornes[i]->getCartes_joueur_2()[2], 3);
}
if (schottenTotten->bornes[i]->getCartes_joueur_2().size() == 4) {
combi_j2 = new Combinaison(schottenTotten->bornes[i]->getCartes_joueur_2()[0],schottenTotten->bornes[i]->getCartes_joueur_2()[1], schottenTotten->bornes[i]->getCartes_joueur_2()[2], schottenTotten->bornes[i]->getCartes_joueur_2()[3],4);
}
vector<Carte*> cartes_adversaire = schottenTotten->bornes[i]->getCartes_joueur_1();
if (revendication->PotentielleCombinaison(schottenTotten->bornes, cartes_combi, combi_j2, cartes_adversaire)) {
schottenTotten->bornes[i]->setPossesseur(0);
}
else {
schottenTotten->bornes[i]->setPossesseur(2);
cout << "Le joueur :" << joueurs[1]->getNom() << " a revendique" << endl;
}
}
}
void Jeu::setJoueurActuel(int i) {
joueur_actuel = i;
}