public void ShuffleCommunityChestCards() { for (int n = CommunityChestCards.Length - 1; n > 0; n--) { int k = rand.Next(n + 1); CommunityChestCard temp = CommunityChestCards[n]; CommunityChestCards[n] = CommunityChestCards[k]; CommunityChestCards[k] = temp; } }
public CommunityChestCard DrawCommunityChestCard(Player player, Player[] curPlayers) { CommunityChestCard cardDrawn = CommunityChestCards[CommunityChestCardIndex++]; cardDrawn.Use(player, curPlayers); if (CommunityChestCardIndex <= 17) { CommunityChestCardIndex = 0; ShuffleCommunityChestCards(); } return(cardDrawn); }
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!"); } } }