@@ -17,12 +17,14 @@ public class Game {
17
17
private int timeOfGame ;
18
18
public Card currentCard ;
19
19
public Item currentItem ;
20
- private Account activeAccount ;
21
20
private boolean storyMode = false ;
22
21
private View view = View .getInstance ();
23
22
24
- public Game (){
25
- activeAccount = Controller .currentAccount ;
23
+ public Account whoseTurn (){
24
+ if (Controller .currentAccount .myTurn ){
25
+ return Controller .currentAccount ;
26
+ }
27
+ return Controller .enemyAccount ;
26
28
}
27
29
Map getMap () {
28
30
return map ;
@@ -345,7 +347,7 @@ private boolean distanceTooLong(Card card, int x, int y) {
345
347
public void attack (Card myCard , Card opponentCard ) throws CloneNotSupportedException {
346
348
if (!myCard .disarmed ) {
347
349
myCard .attack (opponentCard );
348
- if (activeAccount .equals (Controller .currentAccount )) {
350
+ if (whoseTurn () .equals (Controller .currentAccount )) {
349
351
player1Mp -= myCard .Mp ;
350
352
} else {
351
353
player2Mp -= myCard .Mp ;
@@ -425,7 +427,7 @@ public void useSpecialPower(int x, int y) {
425
427
}
426
428
427
429
public void showHand () {
428
- activeAccount .getMainDeck ().showHand ();
430
+ whoseTurn () .getMainDeck ().showHand ();
429
431
}
430
432
431
433
public void endTurn () {
@@ -436,19 +438,21 @@ public void endTurn() {
436
438
for (Card card : Controller .enemyAccount .getCardsInGame ()) {
437
439
card .getCurrentBlock ().blockEffect ();
438
440
}
439
- if (activeAccount .equals (Controller .currentAccount )) {
440
- activeAccount = Controller .enemyAccount ;
441
+ if (whoseTurn ().equals (Controller .currentAccount )) {
442
+ Controller .currentAccount .myTurn = false ;
443
+ Controller .enemyAccount .myTurn = true ;
441
444
} else {
442
- activeAccount = Controller .currentAccount ;
445
+ Controller .currentAccount .myTurn = true ;
446
+ Controller .enemyAccount .myTurn = false ;
443
447
}
444
- for (Card card : activeAccount .getCardsInGame ()) {
448
+ for (Card card : whoseTurn () .getCardsInGame ()) {
445
449
card .attackedThisTurn = false ;
446
450
}
447
- if (activeAccount .getMainDeck ().getItem ().getItemName ().equals ("KingWisom" )) {
448
- activeAccount .getMainDeck ().getItem ().KingWisdom (activeAccount .getUsername ());
451
+ if (whoseTurn () .getMainDeck ().getItem ().getItemName ().equals ("KingWisom" )) {
452
+ whoseTurn () .getMainDeck ().getItem ().KingWisdom (whoseTurn () .getUsername ());
449
453
}
450
- if (activeAccount .getMainDeck ().getItem ().getItemName ().equals ("TajDanaii" )) {
451
- activeAccount .getMainDeck ().getItem ().tajeDanaii (activeAccount .getUsername ());
454
+ if (whoseTurn () .getMainDeck ().getItem ().getItemName ().equals ("TajDanaii" )) {
455
+ whoseTurn () .getMainDeck ().getItem ().tajeDanaii (whoseTurn () .getUsername ());
452
456
}
453
457
map .checkIfCollectibleOrFlagIsTaken ();
454
458
updateGraveYard ();
@@ -470,7 +474,7 @@ private void buffEffect() throws CloneNotSupportedException {
470
474
}
471
475
472
476
private void addToMana () {
473
- if (activeAccount .equals (Controller .currentAccount )) {
477
+ if (whoseTurn () .equals (Controller .currentAccount )) {
474
478
if (turn < 14 ) {
475
479
player1Mp = (turn / 2 ) + 2 ;
476
480
} else {
@@ -488,7 +492,7 @@ private void addToMana() {
488
492
public void help () {
489
493
view .showMyMinions ();
490
494
view .showEnemyMinion ();
491
- activeAccount .getMainDeck ().showHand ();
495
+ whoseTurn () .getMainDeck ().showHand ();
492
496
}
493
497
494
498
public void useItem (Item item , int x , int y ) {
@@ -504,7 +508,7 @@ public void useItem(Item item, int x, int y) {
504
508
505
509
public void addCardsToGame (String cardName , int x , int y ) {
506
510
Card card = Card .returnCardByName (cardName );
507
- if (card == null || !activeAccount .getMainDeck ().hand .returnHand ().contains (card )) {
511
+ if (card == null || !whoseTurn () .getMainDeck ().hand .returnHand ().contains (card )) {
508
512
view .invalidCardNameInGame ();
509
513
return ;
510
514
}
@@ -529,7 +533,7 @@ public void addCardsToGame(String cardName, int x, int y) {
529
533
view .invalidTarget ();
530
534
return ;
531
535
}
532
- boolean whichAccount = activeAccount .equals (Controller .currentAccount );
536
+ boolean whichAccount = whoseTurn () .equals (Controller .currentAccount );
533
537
if (whichAccount ) {
534
538
if ((Controller .currentGame .player1Mp - card .Mp ) < 0 ) {
535
539
view .notEnoughMana ();
@@ -548,7 +552,7 @@ public void addCardsToGame(String cardName, int x, int y) {
548
552
}
549
553
cardsInGame .add (card );
550
554
block .cardMovedToBlock (card );
551
- if (activeAccount .equals (Controller .currentAccount )) {
555
+ if (whoseTurn () .equals (Controller .currentAccount )) {
552
556
Controller .currentAccount .getMainDeck ().hand .deleteFromHand (card );
553
557
if (Controller .currentAccount .getMainDeck ().getItem ().getItemName ().equals ("ghosleTamid" ) && card .getTypeOfAttack ().equals (TypeOfCard .Minion )) {
554
558
Item item = Controller .currentAccount .getMainDeck ().getItem ();
@@ -582,30 +586,30 @@ public void addCardsToGame(String cardName, int x, int y) {
582
586
private boolean checkSurroundingBlocks (int x , int y , boolean canBeEnserted ) {
583
587
Block surrondingBlock = map .getBlock (x - 1 , y );
584
588
if (surrondingBlock != null ) {
585
- if (!surrondingBlock .isEmpty () && activeAccount .getCardsInGame ().contains (surrondingBlock .card )) {
589
+ if (!surrondingBlock .isEmpty () && whoseTurn () .getCardsInGame ().contains (surrondingBlock .card )) {
586
590
canBeEnserted = true ;
587
591
}
588
592
}
589
593
if (!canBeEnserted ) {
590
594
surrondingBlock = map .getBlock (x , y - 1 );
591
595
if (surrondingBlock != null ) {
592
- if (!surrondingBlock .isEmpty () && !activeAccount .getCardsInGame ().contains (surrondingBlock .card )) {
596
+ if (!surrondingBlock .isEmpty () && !whoseTurn () .getCardsInGame ().contains (surrondingBlock .card )) {
593
597
canBeEnserted = true ;
594
598
}
595
599
}
596
600
}
597
601
if (!canBeEnserted ) {
598
602
surrondingBlock = map .getBlock (x + 1 , y );
599
603
if (surrondingBlock != null ) {
600
- if (surrondingBlock .isEmpty () && !activeAccount .getCardsInGame ().contains (surrondingBlock .card )) {
604
+ if (surrondingBlock .isEmpty () && !whoseTurn () .getCardsInGame ().contains (surrondingBlock .card )) {
601
605
canBeEnserted = true ;
602
606
}
603
607
}
604
608
}
605
609
if (!canBeEnserted ) {
606
610
surrondingBlock = map .getBlock (x , y + 1 );
607
611
if (surrondingBlock != null ) {
608
- if (surrondingBlock .isEmpty () && !activeAccount .getCardsInGame ().contains (surrondingBlock .card )) {
612
+ if (surrondingBlock .isEmpty () && !whoseTurn () .getCardsInGame ().contains (surrondingBlock .card )) {
609
613
canBeEnserted = true ;
610
614
}
611
615
}
@@ -635,11 +639,11 @@ public void showCard(String cardIdInGame) {
635
639
}
636
640
637
641
public Account getActiveAccount () {
638
- return this .activeAccount ;
642
+ return this .whoseTurn () ;
639
643
}
640
644
641
645
public void showCollectibles () {
642
- for (Card card : activeAccount .getCardsInGame ()) {
646
+ for (Card card : whoseTurn () .getCardsInGame ()) {
643
647
for (Collectible collectible : card .getCollectibles ()) {
644
648
view .showCollectible (collectible );
645
649
}
0 commit comments