-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cs
executable file
·1321 lines (1262 loc) · 51.5 KB
/
Game.cs
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
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Linq;
using Godot;
using System;
using System.IO;
using System.Collections.Generic;
public class Game : Node2D
{
public List<GameStates> GamePhases = new List<GameStates>();
public int index = -1;
bool StartGame; //True if Ready button has been pressed
bool GameReady; //True if all is ready to play the game
public bool PassTurnPressed; //True if Pass Turn button has been pressed
public bool RoundEnded;
bool EndGame; //True if the game has ended
bool NextRoundPressed; //True if Next Round button has been pressed
Dictionary<string, Player> RoundWinner = new Dictionary<string, Player>(); //Dictionary that contains the winner of each round
int Round = 1; //Round number
public List<Position2D> UserPlayerField = new List<Position2D>(); //List of positions where the user can place his cards
public List<Position2D> EnemyPlayerField = new List<Position2D>(); //List of positions where the enemy can place his cards
public static Player UserPlayer; //User player
public static Player EnemyPlayer; //Enemy player
public string SelectedCardName; //Name of the selected card
public bool CardSelected; //True if a card has been selected
public static string EffectObjetive; //Name of the card that will be affected by the effect
public string ActionMessage; //Message that will be displayed in the action message label, it will offers information about the game
public Position2D ClickPosition = new Position2D(); //Position where the mouse was clicked
public InputEventMouseButton MouseClick; //Mouse click event
public CardSupport SelectedCard; //Selected card
public bool UserSide = true; //True if the user is playing
public bool HumanVsHuman; //True if the game is human vs human
public bool HumanVsMachine; //True if the game is human vs machine
public bool MachineVsMachine; //True if the game is machine vs machine
public bool PrintPhaseMessage;
bool OnGame;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
ActionMessage = "Press Deck to Start";
Menu.Instance = this;
SetFields();
SetInitialStateOfBoard();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(float delta)
{
GetNode<RichTextLabel>("Board/ActionMessage").Text = ActionMessage;
if (index != -1)
{
if (GamePhases[index] is MainPhase1)
{
// Main Phase 1
if (PrintPhaseMessage)
{
ActionMessage = "Main Phase 1";
AddSideMessage();
PrintPhaseMessage = false;
}
GetNode<Button>("Board/EffectButton").Disabled = false;
GetNode<Button>("Board/EndPhase").Disabled = false;
GetNode<Button>("Board/PassTurn").Disabled = false;
GetNode<Button>("Board/NextRound").Disabled = true;
}
if (GamePhases[index] is BattlePhase)
{
// Battle Phase
if (PrintPhaseMessage)
{
ActionMessage = "Battle Phase";
PrintPhaseMessage = false;
AddSideMessage();
}
GetNode<Button>("Board/EffectButton").Disabled = true;
GetNode<Button>("Board/EndPhase").Disabled = false;
GetNode<Button>("Board/NextRound").Disabled = true;
GetNode<Button>("Board/PassTurn").Disabled = false;
}
if (GamePhases[index] is MainPhase2)
{
// Main Phase2
if (PrintPhaseMessage)
{
ActionMessage = "Main Phase 2";
AddSideMessage();
PrintPhaseMessage = false;
}
GetNode<Button>("Board/EffectButton").Disabled = false;
GetNode<Button>("Board/EndPhase").Disabled = false;
GetNode<Button>("Board/PassTurn").Disabled = false;
GetNode<Button>("Board/NextRound").Disabled = true;
}
if (GamePhases[index] is EffectPhase)
{
EffectPhase effectPhase = (EffectPhase)GamePhases[index];
for (int i = 0; i < effectPhase.effects.Count; i++)
{
Effect effect = effectPhase.effects[i];
if (!effect.Used)
{
if (IsPossibleToUseTheEffect(effect, effectPhase.UserSide))
{
effect.Used = true;
if (effectPhase.effects[i].AutomaticEffect)
{
EffectObjetive = ChooseForAutomaticEffect(effect);
GamePhases.Add(new ResolvePhase(effect, EffectObjetive, effectPhase.UserSide));
GamePhases.Add(effectPhase);
index++;
// _Process(delta);
}
else
{
PrintPhaseMessage = true;
WaitingForChoosingACardToDoEffect wait = new WaitingForChoosingACardToDoEffect(UserSide, effectPhase.effects[i]);
EffectObjetive = null;
GamePhases.Add(wait);
GamePhases.Add(new ResolvePhase(effect, EffectObjetive, effectPhase.UserSide));
GamePhases.Add(effectPhase);
index++;
// _Process(delta);
}
}
}
}
if (index + 1 >= GamePhases.Count)
{
effectPhase.CardDoingTheEffect.HasActivatedEffect = true;
if (effectPhase.CardDoingTheEffect.LogicCard is Politic)
{
DestroyCard(effectPhase.CardDoingTheEffect);
}
if (effectPhase.IsMainPhase1)
GamePhases.Add(new MainPhase1(UserSide));
else
GamePhases.Add(new MainPhase2(UserSide));
index++;
}
}
if (GamePhases[index] is WaitingForChoosingACardToDoEffect)
{
WaitingForChoosingACardToDoEffect wait = (WaitingForChoosingACardToDoEffect)GamePhases[index];
if (PrintPhaseMessage)
{
ActionMessage = "Waiting for a selection";
PrintPhaseMessage = false;
}
if (EffectObjetive != null)
{
if (GamePhases[index + 1] is ResolvePhase)
{
ResolvePhase resolvePhase = (ResolvePhase)GamePhases[index + 1];
resolvePhase.EffectObjetive = EffectObjetive;
GamePhases[index + 1] = resolvePhase;
index++;
}
}
}
if (GamePhases[index] is ResolvePhase)
{
// Phase where the effects will take place on the board
ResolvePhase resolvePhase = (ResolvePhase)GamePhases[index];
Effect effect = resolvePhase.effect;
switch (effect.EffectString)
{
case TokenValues.DestroyCard:
DestroyCard(GetNode<CardSupport>("Board/" + EffectObjetive));
break;
case TokenValues.DecreaseHealth:
DecreaseHealth(GetNode<CardSupport>("Board/" + EffectObjetive), effect.TempAmount);
break;
case TokenValues.DecreaseAttack:
DecreaseAttack(GetNode<CardSupport>("Board/" + EffectObjetive), effect.TempAmount);
break;
case TokenValues.IncreaseHealth:
IncreaseHealth(GetNode<CardSupport>("Board/" + EffectObjetive), effect.TempAmount);
break;
case TokenValues.IncreaseAttack:
IncreaseAttack(GetNode<CardSupport>("Board/" + EffectObjetive), effect.TempAmount);
break;
case TokenValues.DrawCards:
if (resolvePhase.UserSide) UserPlayer.DrawCards(effect.TempAmount);
else EnemyPlayer.DrawCards(effect.TempAmount);
break;
case TokenValues.AddCardToBoard:
if (resolvePhase.UserSide) AddCardToTheBoard(UserPlayer, UserPlayerField, InstanceANewCardSupport(effect.CardToHandle));
else AddCardToTheBoard(EnemyPlayer, EnemyPlayerField, InstanceANewCardSupport(effect.CardToHandle));
ActionMessage = $"{effect.CardToHandle.CardName} is added to the board";
break;
case TokenValues.AddCardToDeck:
ActionMessage = $"{effect.CardToHandle.CardName} is added to the deck of ";
if (resolvePhase.UserSide)
{
UserPlayer.PlayerBoard.Deck.Add(InstanceANewCardSupport(effect.CardToHandle));
ShuffleCards(UserPlayer.PlayerBoard.Deck);
ActionMessage += $"{UserPlayer.name}";
}
else
{
EnemyPlayer.PlayerBoard.Deck.Add(InstanceANewCardSupport(effect.CardToHandle));
ShuffleCards(EnemyPlayer.PlayerBoard.Deck);
ActionMessage += $"{EnemyPlayer.name}";
}
break;
default:
break;
}
effect.Used = true;
index++;
}
if (GamePhases[index] is EndRoundPhase)
{
GetNode<Button>("Board/EffectButton").Disabled = true;
GetNode<Button>("Board/EndPhase").Disabled = true;
GetNode<Button>("Board/PassTurn").Disabled = true;
GetNode<Button>("Board/NextRound").Disabled = false;
}
}
if (GameReady)
{
PrintCardsinRange(UserPlayer);
PrintCardsinRange(EnemyPlayer);
if (OnGame && (UserPlayer.PlayerBoard.HandCards.Count == 0 && UserPlayer.PlayerBoard.CardsOnBoard.Count == 0) ||
OnGame && (EnemyPlayer.PlayerBoard.HandCards.Count == 0 && EnemyPlayer.PlayerBoard.CardsOnBoard.Count == 0))
{
EndRound();
}
if (UserSide)
{
UserPlayer.Play();
}
else
{
EnemyPlayer.Play();
}
}
}
private bool IsPossibleToUseTheEffect(Effect effect, bool userSide)
{
switch (effect.EffectString)
{
case TokenValues.DestroyCard:
case TokenValues.DecreaseHealth:
case TokenValues.DecreaseAttack:
case TokenValues.IncreaseHealth:
case TokenValues.IncreaseAttack:
CardSupport card = SearchRandomCardOnBoard();
if (card != null)
{
effect.EffectObjetive = card.LogicCard.CardName;
}
else return false;
break;
case TokenValues.AddCardToBoard:
return ThereAreSetPossiblePositions(userSide);
default:
break;
}
return true;
}
private bool ThereAreSetPossiblePositions(bool userSide)
{
for (int i = 0; i < 8; i++)
{
if (userSide)
{
if (!UserPlayer.PlayerBoard.CardsOnBoard.ContainsValue(UserPlayerField.ElementAt(i)))
{
return true;
}
}
else
{
if (!EnemyPlayer.PlayerBoard.CardsOnBoard.ContainsValue(EnemyPlayerField.ElementAt(i)))
{
return true;
}
}
}
return false;
}
public void AddSideMessage()
{
if (UserSide)
ActionMessage += $"\n{UserPlayer.name} Turn";
else
ActionMessage += $"\n{EnemyPlayer.name} Turn";
}
private void CreatePlayers() //Initialize the players
{
if (HumanVsHuman)
{
UserPlayer = new HumanPlayer(Menu.FinalDeck[0].LogicCard.political_current, new Board(Menu.FinalDeck), GetNode<Position2D>("Board/Position2D17"), GetNode<Position2D>("Board/Position2D18"), this);
ImageTexture CardTexture = new ImageTexture();
CardTexture.Load(System.IO.Directory.GetCurrentDirectory() + "/Textures/Card.jpg");
List<CardSupport> Deck = new List<CardSupport>();
Deck = MakeDeck(CardTexture, Menu.PathToEnemyDeck, new List<CardSupport>());
EnemyPlayer = new HumanPlayer(Deck[0].LogicCard.political_current, new Board(Deck), GetNode<Position2D>("Board/Position2D19"), GetNode<Position2D>("Board/Position2D20"), this);
ShuffleCards(UserPlayer.PlayerBoard.Deck);
ShuffleCards(EnemyPlayer.PlayerBoard.Deck);
}
else if (HumanVsMachine)
{
UserPlayer = new HumanPlayer(Menu.FinalDeck[0].LogicCard.political_current, new Board(Menu.FinalDeck), GetNode<Position2D>("Board/Position2D17"), GetNode<Position2D>("Board/Position2D18"), this);
ImageTexture CardTexture = new ImageTexture();
CardTexture.Load(System.IO.Directory.GetCurrentDirectory() + "/Textures/Card.jpg");
List<CardSupport> Deck = new List<CardSupport>();
Deck = MakeDeck(CardTexture, Menu.PathToEnemyDeck, new List<CardSupport>());
EnemyPlayer = new VirtualPlayer(Deck[0].LogicCard.political_current, new Board(Deck), GetNode<Position2D>("Board/Position2D19"), GetNode<Position2D>("Board/Position2D20"), this);
ShuffleCards(UserPlayer.PlayerBoard.Deck);
ShuffleCards(EnemyPlayer.PlayerBoard.Deck);
}
else if (MachineVsMachine)
{
UserPlayer = new VirtualPlayer(Menu.FinalDeck[0].LogicCard.political_current, new Board(Menu.FinalDeck), GetNode<Position2D>("Board/Position2D17"), GetNode<Position2D>("Board/Position2D18"), this);
ImageTexture CardTexture = new ImageTexture();
CardTexture.Load(System.IO.Directory.GetCurrentDirectory() + "/Textures/Card.jpg");
List<CardSupport> Deck = new List<CardSupport>();
Deck = MakeDeck(CardTexture, Menu.PathToEnemyDeck, new List<CardSupport>());
EnemyPlayer = new VirtualPlayer(Deck[0].LogicCard.political_current, new Board(Deck), GetNode<Position2D>("Board/Position2D19"), GetNode<Position2D>("Board/Position2D20"), this);
ShuffleCards(UserPlayer.PlayerBoard.Deck);
ShuffleCards(EnemyPlayer.PlayerBoard.Deck);
}
}
private void Start() //Each player draw the cards and the game is ready to start
{
UserPlayer.DrawCards(8);
EnemyPlayer.DrawCards(8);
GamePhases = new List<GameStates>();
GamePhases.Add(new MainPhase1(UserSide));
index = 0;
GameReady = true;
PrintPhaseMessage = true;
OnGame = true;
}
private bool TheCardIsUnit(string CardName)
{
if (GetNode<CardSupport>("Board/" + CardName).LogicCard.cardtype == TokenValues.Politic)
return false;
return true;
}
public void PrintCardsinRange(Player player) //Prints the cards in the hand, add the cards to the node tree
{
double length = player.PositionRight.Position.x - player.PositionLeft.Position.x;
double CardWidth = length / player.PlayerBoard.HandCards.Count;
for (int i = 0; i < player.PlayerBoard.HandCards.Count; i++)
{
player.PlayerBoard.HandCards[i].GetNode<MarginContainer>("CardMargin").RectPosition = new Vector2((float)(player.PositionLeft.Position.x + i * CardWidth), player.PositionLeft.Position.y);
if (!player.PlayerBoard.HandCards[i].HasParent)
{
GetNode<Sprite>("Board").AddChild(player.PlayerBoard.HandCards[i], true);
GetNode<Node2D>("Board/CardSupport").Name = player.PlayerBoard.HandCards[i].LogicCard.CardName;
player.PlayerBoard.HandCards[i].HasParent = true;
}
}
}
public void _on_Ready_pressed()
{
CreatePlayers();
StartGame = true;
}
public void _on_Deck_pressed()
{
if (EndGame)
{
GetTree().Quit();
}
else
{
if (StartGame)
{
Start();
StartGame = false;
}
if (NextRoundPressed)
{
NextRoundPressed = false;
Start();
}
ActionMessage = "";
}
}
public void MakeSummon(CardSupport CardToSummon, Position2D square) //Changes the card position to the square position where it is summoned
{
CardToSummon.GetNode<MarginContainer>("CardMargin").RectPosition = square.Position;
}
public void _on_Button_pressed() //When the button is pressed, it checks if the selected card is in the hand, if it is, it summons it
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (EnemyPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
EnemyPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), EnemyPlayerField[0]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button2_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (EnemyPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
EnemyPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), EnemyPlayerField[1]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button3_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (EnemyPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
EnemyPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), EnemyPlayerField[2]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button4_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (EnemyPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
EnemyPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), EnemyPlayerField[3]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button5_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (EnemyPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
EnemyPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), EnemyPlayerField[4]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button6_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (EnemyPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
EnemyPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), EnemyPlayerField[5]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button7_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (EnemyPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
EnemyPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), EnemyPlayerField[6]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button8_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (EnemyPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
EnemyPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), EnemyPlayerField[7]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button9_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (UserPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
UserPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), UserPlayerField[0]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button10_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (UserPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
UserPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), UserPlayerField[1]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button11_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (UserPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
UserPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), UserPlayerField[2]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button12_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (UserPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
UserPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), UserPlayerField[3]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button13_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (UserPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
UserPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), UserPlayerField[4]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button14_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (UserPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
UserPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), UserPlayerField[5]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button15_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (UserPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
UserPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), UserPlayerField[6]);
}
}
}
else SelectedCardName = "";
}
}
public void _on_Button16_pressed()
{
if ((ButtonList)MouseClick.ButtonIndex == ButtonList.Left)
{
CardSupport SelectedCard = GetCardSelected();
if (SelectedCard != null)
{
if (GamePhases[index] is MainPhase1 || GamePhases[index] is MainPhase2)
{
if (UserPlayer.PlayerBoard.HandCards.Contains(SelectedCard))
{
UserPlayer.Summon(GetNode<CardSupport>("Board/" + SelectedCardName), UserPlayerField[7]);
}
}
}
else SelectedCardName = "";
}
}
public List<CardSupport> MakeDeck(ImageTexture CardTexture, string PathToDeck, List<CardSupport> Deck) //It creates the deck of the player
{
DirectoryInfo di = new DirectoryInfo(PathToDeck);
FileInfo[] CardstoCreate = di.GetFiles();
if (CardstoCreate.Length == 0)
{
throw new ArgumentException("No cards found in the deck");
}
CardTemplate[] LogicCards = new CardTemplate[CardstoCreate.Length];
for (int i = 0; i < CardstoCreate.Length; i++)
{
LogicCards[i] = new CardTemplate(CardstoCreate[i].FullName);
if (LogicCards[i].cardtype == TokenValues.Unit)
{
LogicCards[i] = new Unit(LogicCards[i].CardName, LogicCards[i].cardtype, LogicCards[i].Rareness, LogicCards[i].Lore, LogicCards[i].Health, LogicCards[i].Attack, LogicCards[i].political_current, LogicCards[i].PathToPhoto, LogicCards[i].EffectText, LogicCards[i].Effect);
}
else
{
LogicCards[i] = new Politic(LogicCards[i].CardName, LogicCards[i].cardtype, LogicCards[i].Rareness, LogicCards[i].Lore, LogicCards[i].Health, LogicCards[i].Attack, LogicCards[i].political_current, LogicCards[i].PathToPhoto, LogicCards[i].EffectText, LogicCards[i].Effect);
}
PackedScene NewNode = (PackedScene)GD.Load("res://CardSupport.tscn");
Deck.Add((CardSupport)NewNode.Instance());
Deck[i].LogicCard = LogicCards[i];
Deck[i].Instance = this;
Deck[i].GetNode<Sprite>("CardMargin/BackgroundCard").Texture = CardTexture;
Deck[i].GetNode<MarginContainer>("CardMargin").RectSize = GetNode<MarginContainer>("Board/CardOnBoardMargin").RectSize;
Deck[i].MakeCard(CardTexture);
}
return Deck;
}
public void ChangeSide() //It changes the current player's turn
{
if (GetNode<TextureButton>("Board/EnemyField").Visible)
{
GetNode<TextureButton>("Board/EnemyField").Hide();
GetNode<TextureButton>("Board/UserField").Show();
}
else
{
GetNode<TextureButton>("Board/EnemyField").Show();
GetNode<TextureButton>("Board/UserField").Hide();
}
if (UserSide)
{
UserSide = false;
ActionMessage = $"{EnemyPlayer.name} Side";
}
else
{
UserSide = true;
ActionMessage = $"{UserPlayer.name} Side";
}
GamePhases = new List<GameStates>();
GamePhases.Add(new MainPhase1(UserSide));
index = 0;
}
public void DestroyCard(CardSupport Card) //It destroys the card and sends it to the graveyard
{
Card.GetNode<MarginContainer>("CardMargin").RectPosition = GetNode<Position2D>("Board/Position2D18").Position;
if (UserPlayer.name == Card.LogicCard.political_current)
{
UserPlayer.PlayerBoard.Graveyard.Add(Card);
UserPlayer.PlayerBoard.CardsOnBoard.Remove(Card);
Card.Summoned = false;
}
else
{
EnemyPlayer.PlayerBoard.Graveyard.Add(Card);
EnemyPlayer.PlayerBoard.CardsOnBoard.Remove(Card);
Card.Summoned = false;
}
ActionMessage = $"{Card.LogicCard.CardName} Destroyed";
// AddSideMessage();
}
public void _on_EndPhase_pressed()
{
if (GamePhases[index] is MainPhase1)
{
GamePhases.Add(new BattlePhase(UserSide));
index++;
}
else if (GamePhases[index] is BattlePhase)
{
GamePhases.Add(new MainPhase2(UserSide));
index++;
}
else if (GamePhases[index] is MainPhase2)
{
UpdateCardStatus();
ChangeSide();
}
PrintPhaseMessage = true;
}
public void UpdateCardStatus() //It reset the HasAttacked and HasActivatedEffect conditions of the cards
{
Player Player;
if (UserSide)
{
Player = UserPlayer;
}
else
{
Player = EnemyPlayer;
}
foreach (CardSupport Card in Player.PlayerBoard.CardsOnBoard.Keys)
{
if (Card.HasAttacked)
Card.HasAttacked = false;
if (Card.HasActivatedEffect)
Card.HasActivatedEffect = false;
}
}
public void _on_PassTurn_pressed() //If it is pressed twice (one by each player or two by the same player), it ends the round
{
if (PassTurnPressed)
{
EndRound();
}
else
{
PassTurnPressed = true;
UpdateCardStatus();
ChangeSide();
}
}
public void EndRound() //It ends the round and declares the round winner, if it is necessary, it declares the game winner
{
OnGame = false;
int UserPlayerPoints = 0;
int EnemyPlayerPoints = 0;
foreach (CardSupport Card in UserPlayer.PlayerBoard.CardsOnBoard.Keys)
{
UserPlayerPoints += Card.LogicCard.Health;
}
foreach (CardSupport Card in EnemyPlayer.PlayerBoard.CardsOnBoard.Keys)
{
EnemyPlayerPoints += Card.LogicCard.Health;
}
if (UserPlayerPoints > EnemyPlayerPoints)
{
DeclareRoundWinner(UserPlayer);
}
else if (UserPlayerPoints < EnemyPlayerPoints)
{
DeclareRoundWinner(EnemyPlayer);
}
else if (PassTurnPressed)
{
ActionMessage = "Tie";
PassTurnPressed = false;
}
else
{
if (UserPlayer.PlayerBoard.HandCards.Count > 0)
{
DeclareRoundWinner(UserPlayer);
}
else if (EnemyPlayer.PlayerBoard.HandCards.Count > 0)
{
DeclareRoundWinner(EnemyPlayer);
}
else
{
ActionMessage = "Tie";
AddSideMessage();
}
}
if (!EndGame)
{
GetNode<Button>("Board/NextRound").Disabled = false;
}
GamePhases = new List<GameStates>();
GamePhases.Add(new EndRoundPhase(UserSide));
index = 0;
// RoundEnded = true;
}
public void _on_NextRound_pressed() //It cleans the board (destroy summoned cards) and starts the next round
{
for (int i = UserPlayer.PlayerBoard.CardsOnBoard.Keys.Count - 1; i >= 0; i--)
{
DestroyCard(UserPlayer.PlayerBoard.CardsOnBoard.Keys.ElementAt(i));
}
for (int i = EnemyPlayer.PlayerBoard.CardsOnBoard.Keys.Count - 1; i >= 0; i--)
{
DestroyCard(EnemyPlayer.PlayerBoard.CardsOnBoard.Keys.ElementAt(i));
}
ActionMessage = "Press Deck";
if (Round == 2) GetNode<RichTextLabel>("Board/Round").Text = "Second Round";
else if (Round == 3) GetNode<RichTextLabel>("Board/Round").Text = "Third Round";
NextRoundPressed = true;
}
public void DeclareWinner(Player player) //It declares the game winner
{
_on_NextRound_pressed();
EndGame = true;
GetNode<Button>("Board/NextRound").Disabled = true;
GetNode<RichTextLabel>("Board/GameWinner").Text = player.name + " Wins the Game";
GetNode<RichTextLabel>("Board/GameWinner").Show();
ActionMessage = "Press Deck to Exit";
}
public void DeclareRoundWinner(Player player) //It declares the round winner
{
if (Round != 3)
{
ActionMessage = player.name + " Wins this Round";
if (Round == 1) RoundWinner.Add("First", player);
else
{
RoundWinner.Add("Second", player);
if (RoundWinner["First"].name == player.name)
{
DeclareWinner(player);
}
}
Round++;
}
else
{
DeclareWinner(player);
}
}
public void ShuffleCards(List<CardSupport> Cards) //It shuffles the cards
{
Random rnd = new Random();
for (int i = Cards.Count - 1; i > 0; i--)
{
int j = rnd.Next(i + 1);
CardSupport temp = Cards[j];
Cards[j] = Cards[i];
Cards[i] = temp;
}
}
public void _on_EffectButton_pressed()
{
PassTurnPressed = false;
if (SelectedCard.CardPressed)
{
bool IsMainPhase1;
if (GamePhases[index] is MainPhase1) IsMainPhase1 = true;
else IsMainPhase1 = false;
if ((UserSide && GetNode<CardSupport>("Board/" + SelectedCardName).LogicCard.political_current == UserPlayer.name) || (!UserSide && GetNode<CardSupport>("Board/" + SelectedCardName).LogicCard.political_current == EnemyPlayer.name))
{
if (!GetNode<CardSupport>("Board/" + SelectedCardName).HasActivatedEffect)
{
EffectPhase effectPhase = new EffectPhase(GetNode<CardSupport>("Board/" + SelectedCardName), UserSide, IsMainPhase1);
CardSelected = false;
effectPhase.CreateEffects();
if (effectPhase.effects.Count > 0)
{
GamePhases.Add(effectPhase);
index++;
}
else
{
if (GetNode<CardSupport>("Board/" + SelectedCardName).LogicCard is Politic)
{
DestroyCard(GetNode<CardSupport>("Board/" + SelectedCardName));
}
ActionMessage = SelectedCardName + " doesn't have an effect";
AddSideMessage();
}
}
else
{
ActionMessage = SelectedCardName + " has already activated effect";
AddSideMessage();
}
}
}
}
private void CleanBoardPolitics()
{
List<CardSupport> ToDestroy = new List<CardSupport>();
foreach (CardSupport cardSupport in UserPlayer.PlayerBoard.CardsOnBoard.Keys)
{
if (cardSupport.LogicCard.cardtype == TokenValues.Politic && cardSupport.HasActivatedEffect)
ToDestroy.Add(cardSupport);
}
foreach (CardSupport cardSupport in EnemyPlayer.PlayerBoard.CardsOnBoard.Keys)
{
if (cardSupport.LogicCard.cardtype == TokenValues.Politic && cardSupport.HasActivatedEffect)
ToDestroy.Add(cardSupport);
}
foreach (CardSupport cardSupport in ToDestroy)
DestroyCard(cardSupport);
}
private CardSupport InstanceANewCardSupport(CardTemplate cardTemplate)
{
PackedScene NewNode = (PackedScene)GD.Load("res://CardSupport.tscn");
CardSupport newcard = (CardSupport)NewNode.Instance();
ImageTexture CardTexture = new ImageTexture();
CardTexture.Load(System.IO.Directory.GetCurrentDirectory() + "/Textures/Card.jpg");