//Attacking phase for human players public virtual void AttackingPhase(GameRiver gameRiver, Card attackingCard) { CardList gameRiverList = new CardList(); for (int i = 0; i < gameRiver.length(); i++) { gameRiverList.Add(gameRiver.GetCard(i)); } switch (gameRiver.length()) { case 0: gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); break; case 2: if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank) { gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); break; } break; case 4: if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank) { gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); break; } break; case 6: if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank | attackingCard.getCardRank() == gameRiverList[4].rank | attackingCard.getCardRank() == gameRiverList[5].rank) { gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); break; } break; case 8: if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank | attackingCard.getCardRank() == gameRiverList[4].rank | attackingCard.getCardRank() == gameRiverList[5].rank) { gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); break; } break; } }
} // end of GameRiver() //Beginning of Player() static void Player() { int userInput = 0; GameDeck myDeck = new GameDeck(); GameRiver myRiver = new GameRiver(); PlayerHand playerOneHand = new PlayerHand(); PlayerHand playerTwoHand = new PlayerHand(); Player playerOne = new Player("Timmy", playerOneHand, true, false); Player playerTwo = new Player("Teddy", playerTwoHand, false, true); myDeck.Shuffle(52); //shower player info Console.WriteLine(myDeck.ToString(myDeck)); Console.WriteLine(playerOne.ToStringPlayerInfo()); Console.WriteLine(playerTwo.ToStringPlayerInfo()); //refill player cards playerOne.RefillHand(myDeck); playerTwo.RefillHand(myDeck); //Console.WriteLine(playerOne.ToStringPlayerInfo()); //Console.WriteLine(playerTwo.ToStringPlayerInfo()); //Console.WriteLine(myDeck.ToString(myDeck)); //Attacking/defendingPhase while (playerOne.getIsAttacking() == true) { Console.WriteLine("NEW ATTACKING PHASE"); Console.WriteLine(playerOne.ToStringPlayerInfo()); Console.WriteLine(playerTwo.ToStringPlayerInfo()); Console.WriteLine("\nEnter int number for card you want to play"); userInput = Convert.ToInt32(Console.ReadLine()); //playerOne.AttackingPhase(myRiver, userInput); while (playerTwo.getIsDefending() == true) { userInput = 0; Console.WriteLine("\nEnter int number for card you want to play"); userInput = Convert.ToInt32(Console.ReadLine()); //playerTwo.DefendingPhase(myRiver, userInput); } Console.WriteLine(playerOne.ToStringPlayerInfo()); Console.WriteLine(playerTwo.ToStringPlayerInfo()); Console.WriteLine(myRiver.ToString(myRiver)); //will set defending back to true for player two for new attacking phase playerTwo.setIsDefending(true); } Console.ReadKey(); } // end of Player()
//to string will output as a string game river cards public String ToString(GameRiver gameRiver1) { String gameRiverString = ""; gameRiverString += "\n\n\tRiverCards\n\t"; for (int i = 0; i < gameRiver1.length(); i++) { Card tempCard = gameRiver1.GetCard(i); gameRiverString += tempCard.ToString(); if (i != 51) { gameRiverString += ", "; } } return(gameRiverString); }
//logs the round stats public void LogRound(GameLog gameLog, int roundNumber, Player playerOne, Player playerTwo, GameRiver gameRiver) { gameLog.Log("\nROUND: " + roundNumber.ToString() + "\n\t" + playerOne.getHand().ToString(playerOne.getHand(), playerOne.getName()) + "\n\n\t" + playerTwo.getHand().ToString(playerTwo.getHand(), playerTwo.getName()) + gameRiver.ToString(gameRiver)); }
} // end of CardSuitsEnum() //Beginning of GameDeck() static void GameDeck() { GameDeck myDeck = new GameDeck(); myDeck.Shuffle(52); //showdeck Console.WriteLine(myDeck.ToString(myDeck)); //player one draws a single card from deck Card card1; card1 = myDeck.DrawCard(); Console.WriteLine(card1.ToString(1)); //showdeck Console.WriteLine(myDeck.ToString(myDeck)); //creates two player objects PlayerHand playerOneHand = new PlayerHand(); PlayerHand playerTwoHand = new PlayerHand(); //player one adds drawn card to hand playerOneHand.AddCardToHand(card1); Console.WriteLine(playerOneHand.ToString(playerOneHand, 1)); //player two draws 6 cards CardList cardsDrawn1; cardsDrawn1 = myDeck.DrawCards(6); Console.WriteLine(cardsDrawn1.ToString(cardsDrawn1, 2)); //playertwo adds cards to hand playerTwoHand.AddCardsToHand(cardsDrawn1); Console.WriteLine(playerTwoHand.ToString(playerTwoHand, 2)); //playertwo chooses two cards from hand Card choosenCardFromHand1; choosenCardFromHand1 = playerTwoHand.ChooseCardFromHand(2); Card choosenCardFromHand3; choosenCardFromHand3 = playerTwoHand.ChooseCardFromHand(0); Console.WriteLine(playerTwoHand.ToString(playerTwoHand, 2)); //player one draws cards from deck CardList cardsDrawn2; cardsDrawn2 = myDeck.DrawCards(5); Console.WriteLine(cardsDrawn2.ToString(cardsDrawn2, 1)); playerOneHand.AddCardsToHand(cardsDrawn2); Console.WriteLine(playerOneHand.ToString(playerOneHand, 1)); //playerone chooses two cards from hand Card choosenCardFromHand2; choosenCardFromHand2 = playerOneHand.ChooseCardFromHand(1); Card choosenCardFromHand4; choosenCardFromHand4 = playerOneHand.ChooseCardFromHand(2); Console.WriteLine(playerOneHand.ToString(playerOneHand, 1)); //choosen card from playertwo put in gameriver1 list GameRiver gameRiver1 = new GameRiver(); //player two choosen cards added to river gameRiver1.AddCardToRiver(choosenCardFromHand1); gameRiver1.AddCardToRiver(choosenCardFromHand3); //player one choosen cards added to river gameRiver1.AddCardToRiver(choosenCardFromHand2); gameRiver1.AddCardToRiver(choosenCardFromHand4); Console.WriteLine(gameRiver1.ToString(gameRiver1)); //Console.WriteLine(gameRiver1.cardRiverComparison()); Console.ReadKey(); //GameDeck Functionality GameDeck deck1 = new GameDeck(); GameDeck deck2 = (GameDeck)deck1.Clone(); Console.WriteLine("\nThe first card in the original deck is: {0}", deck1.GetCard(0)); Console.WriteLine("The first card in the cloned deck is: {0}", deck2.GetCard(0)); deck1.Shuffle(52); Console.WriteLine("Original deck shuffled."); Console.WriteLine("The first card in the original deck is: {0}", deck1.GetCard(0)); Console.WriteLine("The first card in the cloned deck is: {0}", deck2.GetCard(0)); Console.ReadKey(); } // end of GameDeck()
//ComputerAttackingPhase method, guides the ai through attacking phase public void AttackingPhase(GameRiver gameRiver) { Card attackingCard = new Card(); CardList gameRiverList = new CardList(); bool sucessfullattack = false; for (int i = 0; i < gameRiver.length(); i++) { gameRiverList.Add(gameRiver.GetCard(i)); } switch (gameRiver.length()) { case 0: //AI chooses a card for (int i = 0; i < getHand().length(); i++) { attackingCard = getHand().ChooseCardFromHand(i); gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); sucessfullattack = true; break; } break; case 2: //AI chooses a card for (int i = 0; i < getHand().length(); i++) { attackingCard = getHand().ChooseCardFromHand(i); if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank) { gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); sucessfullattack = true; break; } } break; case 4: //AI chooses a card for (int i = 0; i < getHand().length(); i++) { attackingCard = getHand().ChooseCardFromHand(i); if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank) { gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); sucessfullattack = true; break; } } break; case 6: //AI chooses a card for (int i = 0; i < getHand().length(); i++) { attackingCard = getHand().ChooseCardFromHand(i); if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank | attackingCard.getCardRank() == gameRiverList[4].rank | attackingCard.getCardRank() == gameRiverList[5].rank) { gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); sucessfullattack = true; break; } } break; case 8: //AI chooses a card for (int i = 0; i < getHand().length(); i++) { attackingCard = getHand().ChooseCardFromHand(i); if (attackingCard.getCardRank() == gameRiverList[0].rank | attackingCard.getCardRank() == gameRiverList[1].rank | attackingCard.getCardRank() == gameRiverList[2].rank | attackingCard.getCardRank() == gameRiverList[3].rank | attackingCard.getCardRank() == gameRiverList[4].rank | attackingCard.getCardRank() == gameRiverList[5].rank) { gameRiver.AddCardToRiver(attackingCard); getHand().RemoveCardFromHand(attackingCard); sucessfullattack = true; break; } } break; } if (sucessfullattack == false && gameRiver.length() == 0 | gameRiver.length() == 2 | gameRiver.length() == 4 | gameRiver.length() == 6 | gameRiver.length() == 8) { setIsDefending(true); } }
//ComputerDefendingPhase method, guides the ai through Defending phase public void DefendingPhase(GameRiver gameRiver, Card trumpCard) { Card defendingCard = new Card(); CardList gameRiverList = new CardList(); bool sucessfulldefense = false; //int computerInput = 0; for (int i = 0; i < gameRiver.length(); i++) { gameRiverList.Add(gameRiver.GetCard(i)); } switch (gameRiver.length()) { case 1: //AI chooses a card for (int i = 0; i < getHand().length(); i++) { defendingCard = getHand().ChooseCardFromHand(i); if (defendingCard.getCardSuit() == gameRiverList[0].suit & defendingCard > gameRiverList[0] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[0]) { gameRiver.AddCardToRiver(defendingCard); getHand().RemoveCardFromHand(defendingCard); sucessfulldefense = true; break; } } break; case 3: //AI chooses a card for (int i = 0; i < getHand().length(); i++) { defendingCard = getHand().ChooseCardFromHand(i); if (defendingCard.getCardSuit() == gameRiverList[2].suit & defendingCard > gameRiverList[2] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[2]) { gameRiver.AddCardToRiver(defendingCard); getHand().RemoveCardFromHand(defendingCard); sucessfulldefense = true; break; } } break; case 5: //AI chooses a card for (int i = 0; i < getHand().length(); i++) { defendingCard = getHand().ChooseCardFromHand(i); if (defendingCard.getCardSuit() == gameRiverList[4].suit & defendingCard > gameRiverList[4] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[4]) { gameRiver.AddCardToRiver(defendingCard); getHand().RemoveCardFromHand(defendingCard); sucessfulldefense = true; break; } } break; case 7: //AI chooses a card for (int i = 0; i < getHand().length(); i++) { defendingCard = getHand().ChooseCardFromHand(i); if (defendingCard.getCardSuit() == gameRiverList[6].suit & defendingCard > gameRiverList[6] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[6]) { gameRiver.AddCardToRiver(defendingCard); getHand().RemoveCardFromHand(defendingCard); sucessfulldefense = true; break; } } break; } if (sucessfulldefense == false && gameRiver.length() == 1 | gameRiver.length() == 3 | gameRiver.length() == 5 | gameRiver.length() == 7) { setIsDefending(false); } }
//Defending phase for human players public virtual void DefendingPhase(GameRiver gameRiver, Card trumpCard, Card defendingCard) { //Card defendingCard = new Card(); CardList gameRiverList = new CardList(); bool sucessfulldefense = false; //gameRiver.AddCardToRiver(defendingCard); //getHand().RemoveCardFromHand(defendingCard); //sucessfulldefense = true; for (int i = 0; i < gameRiver.length(); i++) { gameRiverList.Add(gameRiver.GetCard(i)); } switch (gameRiver.length()) { case 1: if (defendingCard.getCardSuit() == gameRiverList[0].suit & defendingCard > gameRiverList[0] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[0]) { gameRiver.AddCardToRiver(defendingCard); getHand().RemoveCardFromHand(defendingCard); sucessfulldefense = true; break; } break; case 3: if (defendingCard.getCardSuit() == gameRiverList[2].suit & defendingCard > gameRiverList[2] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[2]) { gameRiver.AddCardToRiver(defendingCard); getHand().RemoveCardFromHand(defendingCard); sucessfulldefense = true; break; } break; case 5: if (defendingCard.getCardSuit() == gameRiverList[4].suit & defendingCard > gameRiverList[4] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[4]) { gameRiver.AddCardToRiver(defendingCard); getHand().RemoveCardFromHand(defendingCard); sucessfulldefense = true; break; } break; case 7: if (defendingCard.getCardSuit() == gameRiverList[6].suit & defendingCard > gameRiverList[6] | defendingCard.getCardSuit() == trumpCard.getCardSuit() & defendingCard > gameRiverList[6]) { gameRiver.AddCardToRiver(defendingCard); getHand().RemoveCardFromHand(defendingCard); sucessfulldefense = true; break; } break; } //if (sucessfulldefense == false) //{ // setIsDefending(false); //} }
//clones the river cards public object Clone() { GameRiver newGameRiver = new GameRiver(gameRiver.Clone() as CardList); return(newGameRiver); }