public bool ChanceOrPay(Player p) { Console.WriteLine("Dilemne : \n1. Vous tirez une carte chance\n2. Vous payez une amende de 1000 euros"); bool verif = false; while (!verif) { string answer = Console.ReadLine(); switch (answer) { case "1": ChanceCard cc = new ChanceCard(); cc.Effect(p); verif = true; break; case "2": if (p.Money > 1000) { p.Taxe(1000); verif = true; } else { Console.WriteLine("Vous n'avez pas suffisamment d'argent"); } break; default: Console.WriteLine("Je n'ai pas compris. Veuillez reessayer."); break; } } return(true); }
public void ShuffleChanceCards() { for (int n = ChanceCards.Length - 1; n > 0; n--) { int k = rand.Next(n + 1); ChanceCard temp = ChanceCards[n]; ChanceCards[n] = ChanceCards[k]; ChanceCards[k] = temp; } }
public ChanceCard DrawChanceCard(Player player, Player[] curPlayers) { ChanceCard cardDrawn = ChanceCards[ChanceCardIndex++]; cardDrawn.Use(player, curPlayers); if (ChanceCardIndex <= 16) { ChanceCardIndex = 0; ShuffleChanceCards(); } return(cardDrawn); }
public override void OnVisit(Player visitor, Board board) { base.OnVisit(visitor, board); switch (specialTileType) { case SpecialTileType.GO: visitor.ReceiveMoneyFromBank(Constants.GOAllowance); Console.WriteLine($"{visitor.DisplayName} receives {Constants.GOAllowance} from the bank for passing GO."); break; case SpecialTileType.Chance: ChanceCard chanceCard = SpecialCardDeck.GetChanceCard(); Console.WriteLine($"{visitor.DisplayName} drew chance card: {chanceCard.DisplayName}"); chanceCard.Use(visitor, board, board.Monopoly.Players); break; case SpecialTileType.CommunityChest: CommunityChest community = SpecialCardDeck.GetCommunityChest(); Console.WriteLine($"{visitor.DisplayName} drew community chest: {community.DisplayName}"); community.Use(visitor, board, board.Monopoly.Players); break; case SpecialTileType.VisitingJail: break; case SpecialTileType.Jail: visitor.Jail(board); break; case SpecialTileType.FreeParking: break; case SpecialTileType.IncomeTax: break; case SpecialTileType.LuxuryTax: break; default: throw new Exception($"Unhandled special tile type: {specialTileType}"); } }
public ChanceCard DrawCard() { ChanceCard topCard = communityCards.Dequeue(); return(topCard); }
public void Run(BoardGUI b) { while (!gameOver()) { Player curPlayer; for (int j = 0; playInGame() > 1; j = (j + 1) % 4) { curPlayer = players[j]; //Check if player has lost yet Console.WriteLine(curPlayer.inGame); if (!curPlayer.inGame) { continue; } while (again) { Console.WriteLine(); Console.WriteLine("----------------------------------------------------------------------"); Console.WriteLine("---------------------------Player " + j + "'s turn!---------------------------"); Console.WriteLine("----------------------------------------------------------------------"); Console.WriteLine(); Console.WriteLine("Player " + j + " wealth = " + players[j].money); Console.WriteLine("Player " + j + " position = " + players[j].position); Console.WriteLine(); again = false; //Roll Dice int die1 = RollDice(); int die2 = RollDice(); Console.WriteLine("Die 1 roll: " + die1); Console.WriteLine("Die 2 roll: " + die2); Console.WriteLine("Dice Roll for player " + j + ": " + (die1 + die2)); Console.WriteLine(); //Check if Jail and handle accordingly if (curPlayer.inJail) { handleJail(curPlayer, die1, die2); } //If still in jail end turn if (curPlayer.inJail) { break; } //check to see if roll gives second turn checkAgain(curPlayer, die1, die2); //Move Player board.MovePlayer(curPlayer, (die1 + die2)); b.Tick(); Console.WriteLine("You landed on " + board.Spaces[curPlayer.position].name); Console.WriteLine(); //handle movement based on space int action = board.Spaces[curPlayer.position].Handle(curPlayer, (die1 + die2)); b.Tick(); if (action == 1) { //bidding system: int lastBid = 0; Buyable temp = (Buyable)(board.Spaces[curPlayer.position]); int curBid = temp.GetPrice(); int highestBid = curBid; int highestPlayer = -1; int attempt = playInGame(); for (int i = 0; (lastBid < curBid || i != highestPlayer) && attempt > 0; i = ((i + 1) % 4)) { if (players[i].inGame == false) { continue; } attempt--; Console.WriteLine(); Console.WriteLine("Player " + i + " turn to bid"); lastBid = curBid; Console.WriteLine("LastBid = " + lastBid); //TODO: get a bid from each player if (players[i].isAI) { int ech = rand.Next(1, 6); int bech = ((Buyable)(board.Spaces[curPlayer.position])).GetPrice(); int blech = bech + (int)((double)((double)bech * ((double)ech / (((double)ech * 2) + 1)))); Console.WriteLine(bech); Console.WriteLine(blech); if (curBid < blech) { curBid = curBid + rand.Next(4, 10); } } else { Console.WriteLine("Enter your bid for " + board.Spaces[curPlayer.position].name); curBid = int.Parse(Console.ReadLine()); } b.BoardGUI_Paint(null, null); Console.WriteLine("curBid " + curBid); if (curBid > highestBid) { attempt = 4; highestPlayer = i; highestBid = curBid; } } if (highestPlayer != -1) { temp.Buy(players[highestPlayer]); players[highestPlayer].money -= (highestBid - temp.GetPrice()); } } if (action == 2) { ChanceCard card = deck.DrawChanceCard(curPlayer, players); Console.WriteLine(card.Name); } if (action == 3) { CommunityChestCard card = deck.DrawCommunityChestCard(curPlayer, players); Console.WriteLine(card.Name); } handlePossible(curPlayer); } again = true; againCount = 0; b.Tick(); } } foreach (Player p in players) { if (p.inGame) { Console.WriteLine("Player " + p.PlayerNumber + " wins!"); } } }