public EndGame() { InitializeComponent(); int index = 1; bool firstLoop = true; while (GameLoop.getInstance().Gameboard.Players.Count() > 0) // Loops untill all players have been ordered { int maxMoney = -1000000; Player winner = null; foreach (Player p in GameLoop.getInstance().Gameboard.Players) // Loops through every player in the list { if (p.Money > maxMoney) // Gets player with the most money { maxMoney = p.Money; winner = p; } } GameLoop.getInstance().Gameboard.Players.Remove(winner); // Removes player from the list if (firstLoop) // If this was the 1st loop, the winner was the game winner { tbWinner.Text = winner.Name + " was the winner with " + winner.Money.ToString("c0") + " after 20 turns." + Environment.NewLine + "Congratulations!!!"; } else // If this was NOT the 1st loop, insert them into the general output string { tbOtherPlayers.Text += index + ". " + winner.Name.PadRight(9) + string.Format("{0:$#,##0}", winner.Money) + Environment.NewLine; } firstLoop = false; index++; } }
/// <summary> /// Display the pay rent form or the purchase property form /// </summary> /// <param name="player">Current player</param> /// <param name="property">Property tile that the current player landed on</param> private void DisplayPayRentOrPurchasePropertyForm(Player player, Property property) { Player propertyOwner = property.Owner; // if a property and is not owned, call the purchase property form if (propertyOwner == null) { // Figured out how to center windows with respect to their predecessors: // https://stackoverflow.com/questions/4306593/wpf-how-to-set-a-dialog-position-to-show-at-the-center-of-the-application PurchaseProperty purchaseProperty = new PurchaseProperty(); purchaseProperty.Owner = this; // Output information to the purchase property form purchaseProperty.tbOutputName.Text = player.Name; purchaseProperty.tbOutputMoney.Text = string.Format("{0:$#,##0}", player.Money); foreach (Property proprty in player.PropertiesOwned) { purchaseProperty.lbOutputPropertiesOwned.Items.Add(proprty.Name); } purchaseProperty.tbOutputCostOfProperty.Text = property.Cost.ToString("c0"); if (player.Money >= property.Cost) { purchaseProperty.tbUserInformation.Text = "Would you like to buy " + property.Name + "?"; } else { purchaseProperty.tbUserInformation.Text = "Sorry, you do not have enough money to purchase " + property.Name + "."; purchaseProperty.btnYesBuy.IsEnabled = false; } purchaseProperty.ShowDialog(); } // if the current player owns the property, do nothing else if (propertyOwner.Name == player.Name) { } // if another player owns the property, call the PayRent form else { PayRent payRent = new PayRent(); payRent.Owner = this; // Output information to pay rent form payRent.tbOutputName.Text = player.Name; payRent.tbOutputMoney.Text = string.Format("{0:$#,##0}", player.Money); payRent.tbOutputPayRentTo.Text = propertyOwner.Name; // Calculates the rent for utility or railroad property before output to the pay rent form if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Utility)) { Utility utilityProperty = (Utility)property; utilityProperty.CalculateRent((Utility)GameLoop.getInstance().Gameboard.TileOrder[12], (Utility)GameLoop.getInstance().Gameboard.TileOrder[28], utilityProperty.NearstUtility); } else if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Railroad)) { Railroad railroadProperty = (Railroad)property; railroadProperty.CalculateRent((Railroad)GameLoop.getInstance().Gameboard.TileOrder[5], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[15], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[25], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[35], railroadProperty.NearestRailroad); } payRent.tbOutputRentIsHowMuch.Text = property.Rent.ToString("c0"); payRent.ShowDialog(); } }
public MainWindow() { InitializeComponent(); // Initializes avaliable player icons and Community/Chance Cards GameLoop.getInstance().initilizeIconList(); GameLoop.getInstance().Gameboard.ReadInFiles(); GameLoop.getInstance().Gameboard.InitializeCards(); // Testing: Changes starting turn count //GameLoop.getInstance().Gameboard.TurnCount = 20; if (GameLoop.getInstance().Gameboard.Players.Count > 0) { // Displays first player's initial position and all players' icon's initial positions UpdatePlayerIconPosition(GameLoop.getInstance().Gameboard.Players[0]); // Displays first player's name and the initial turn count DisplayPlayerName(GameLoop.getInstance().Gameboard.Players[0]); DisplayPlayerIcon(GameLoop.getInstance().Gameboard.Players[0]); UpdateBoard(GameLoop.getInstance().Gameboard.Players[0]); DisplayTurnCounter(); // Adds each player's icon to the Grid foreach (Player p in GameLoop.getInstance().Gameboard.Players) { gridBoard.Children.Remove(GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon); gridBoard.Children.Add(GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon); } loadGameUpdateDisplay(); } }
/// <summary> /// Pays rent to the owner and takes the rent away from the current player /// </summary> /// <param name="player">the current player's turn</param> private void PayRent(Player player) { // Check if a utility, and calculates the rent if (GetType() == typeof(Utility)) { Utility currentUtility = (Utility)this; currentUtility.CalculateRent((Utility)GameLoop.getInstance().Gameboard.TileOrder[12], (Utility)GameLoop.getInstance().Gameboard.TileOrder[28], currentUtility.NearstUtility); } // Checks if a railroad, and and calculates the rent if (GetType() == typeof(Railroad)) { Railroad currentRailroad = (Railroad)this; currentRailroad.CalculateRent((Railroad)GameLoop.getInstance().Gameboard.TileOrder[5], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[15], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[25], (Railroad)GameLoop.getInstance().Gameboard.TileOrder[35], currentRailroad.NearestRailroad); } // Takes the money away from the current player player.Money -= Rent; // Pays rent to the owner foreach (Player plyr in GameLoop.getInstance().Gameboard.Players) { if (plyr == Owner) { plyr.Money += Rent; break; } } }
/// <summary> /// Moves the player's location through the tile list and calls PassGo's location action if it was passed mid-move /// </summary> /// <param name="player">Current player</param> public void Move(Player player, int differentLocation = -1) { int newLocation; // For using the Move method with the chance cards // When differentLocation is not specified, add the rolled dice to the player's location if (differentLocation == -1) { newLocation = player.Location + RolledDice[0] + RolledDice[1]; } // If the differentLocation is previously determined, set newLocation else { newLocation = differentLocation; } // // if the player passes go and is not in jail if (newLocation < player.Location && newLocation != 10) { if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(CardSpace)) { CardSpace cardTile = (CardSpace)GameLoop.getInstance().Gameboard.TileOrder[player.Location]; // if the card tile calls for going back 3 spaces and is not the first community chest card at location 2 if (cardTile.ProcessedCard[0, 3] == "Location" && GameLoop.getInstance().Gameboard.TileOrder[player.Location] != GameLoop.getInstance().Gameboard.TileOrder[2]) { // don't collect go } else { // If player passed Go, collect $200 TileOrder[0].LocationAction(player); } } } player.Location = newLocation; }
/// <summary> /// Performs the action for the player's new location based on what type of tile it is. /// </summary> /// <param name="player">Current Player</param> private void LocationResponse(Player player) { // if the player lands on a propertym display pay rent or purchase property form if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Basic) || GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Utility) || GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Railroad)) { Property property = (Property)GameLoop.getInstance().Gameboard.TileOrder[player.Location]; DisplayPayRentOrPurchasePropertyForm(player, property); DisplayCurrentPlayerProperties(player); // GUI } // when a player lands on a community chest spot or chance spot else if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(CardSpace)) { // Get the cardSpace and display the community or chance form CardSpace cardTile = (CardSpace)GameLoop.getInstance().Gameboard.TileOrder[player.Location]; DisplayCommunityOrChanceForm(player, cardTile); // if the community or chance card calls for the player to advance to a property, display pay rent or purchase property form if (cardTile.ProcessedCard[0, 1] == "Advance" && (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Basic) || GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Utility) || GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(Railroad))) { DisplayCurrentPlayerMoney(player); DisplayPayRentOrPurchasePropertyForm(player, (Property)GameLoop.getInstance().Gameboard.TileOrder[player.Location]); } // if the community or chance card calls for the player to advance to a card space, display community or chance card form else if (cardTile.ProcessedCard[0, 1] == "Advance" && (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(CardSpace))) { DisplayCurrentPlayerMoney(player); DisplayCommunityOrChanceForm(player, (CardSpace)GameLoop.getInstance().Gameboard.TileOrder[player.Location]); } // if the community or chance card calls for the player to advance to the go to jail space, send the player to jail else if (cardTile.ProcessedCard[0, 1] == "Advance" && (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(GoToJail))) { GoToJail goToJailTile = (GoToJail)GameLoop.getInstance().Gameboard.TileOrder[player.Location]; goToJailTile.LocationAction(player); } // if the community or chance card calls for the player to advance to the go to Income Tax, decrease the player's money by 10% (if more) or pay $200 else if (cardTile.ProcessedCard[0, 1] == "Advance" && (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(FreeParking))) { FreeParking freeParking = (FreeParking)GameLoop.getInstance().Gameboard.TileOrder[player.Location]; PayTaxForm(player, freeParking); } } // if Luxury Tax or Income Tax, display tax form else if (GameLoop.getInstance().Gameboard.TileOrder[player.Location].GetType() == typeof(FreeParking)) { FreeParking freeParking = (FreeParking)GameLoop.getInstance().Gameboard.TileOrder[player.Location]; if (freeParking.Name == "Income Tax" || freeParking.Name == "Luxury Tax") { PayTaxForm(player, freeParking); } } // if not a property or community chest or chance card, call location action on that tile else { GameLoop.getInstance().Gameboard.TileOrder[player.Location].LocationAction(player); } DisplayCurrentPlayerMoney(player); // GUI DisplayCurrentPlayerLocation(player); DisplayCurrentPlayerProperties(player); UpdateBoard(player); }
/// <summary> /// Rolls dice - effectively, takes a turn for the player. /// </summary> private void BtnRoll_Click(object sender, RoutedEventArgs e) { Player currentPlayer = GameLoop.getInstance().Gameboard.Players[GameLoop.getInstance().Gameboard.CurrentPlayerIndex]; // Gets current player // Stops the button from being repeatedly clicked while a turn is already taking place. btnRoll.IsEnabled = false; TakeTurn(currentPlayer); // Current Player takes their turn }
public static GameLoop getInstance() { if (uniqueInstance == null) { uniqueInstance = new GameLoop(); } return(uniqueInstance); }
/// <summary> /// Load Game /// </summary> private void BtnLoadGame_Click(object sender, RoutedEventArgs e) { if (GameLoop.getInstance().LoadGame()) { MainWindow main = new MainWindow(); main.Show(); Close(); } }
private void btnOk_Click(object sender, RoutedEventArgs e) { // Get the current player, player location, and CardSpace that the player landed on Player currentPlayer = GameLoop.getInstance().Gameboard.Players[GameLoop.getInstance().Gameboard.CurrentPlayerIndex]; int playerCurrentLocation = currentPlayer.Location; CardSpace cardTile = (CardSpace)GameLoop.getInstance().Gameboard.TileOrder[playerCurrentLocation]; // Carry out the specifications of the picked card cardTile.LocationAction(currentPlayer); this.Close(); }
/// <summary> /// Brings up the save file dialog /// </summary> private void BtnSave_Click(object sender, RoutedEventArgs e) { if (GameLoop.getInstance().SaveGame()) { MessageBox.Show("Game Saved!"); } else { MessageBox.Show("Error: Game could not be saved to file."); } }
/// <summary> /// Sets the rent due when landing on a utility property /// </summary> /// <param name="utility">one of the utility properties</param> public void CalculateRent(Utility utility1, Utility utility2, bool advanceToNearstUtility) { // An array of the utilities owned bool[] utilityOwned = { false, false }; // if a chance card, times the role of the dice by 10 (senerio of both utilities being owned) if (advanceToNearstUtility) { utilityOwned[0] = true; utilityOwned[1] = true; advanceToNearstUtility = false; } // if not, check the utility properties for ownership else { if (utility1.IsOwned) { utilityOwned[0] = true; } if (utility2.IsOwned) { utilityOwned[1] = true; } } //Updates the array depending on which utilities are owned on the gameboard int count = 0; for (int i = 0; i < utilityOwned.Length; i++) { if (utilityOwned[i] == true) { count++; } } // Need to access the dice roll int diceOne = GameLoop.getInstance().Gameboard.RolledDice[0]; int diceTwo = GameLoop.getInstance().Gameboard.RolledDice[1]; // Returns the amount of rent due depending on the number of utilities owned on the gameboard and the dice roll if (count == 1) { Rent = 4 * (diceOne + diceTwo); } if (count == 2) { Rent = 10 * (diceOne + diceTwo); } }
/// <summary> /// Displays the community chest form or the chance form /// </summary> /// <param name="player">the current player</param> /// <param name="cardTile">the CardSpace tile that the current player landed on</param> private void DisplayCommunityOrChanceForm(Player player, CardSpace cardTile) { List <Card> cardsList = new List <Card>(); // if land on a community chest card space, set the list of community chest cards and the processing array to a local variable if (player.Location == 2 || player.Location == 17 || player.Location == 33) { cardsList = GameLoop.getInstance().Gameboard.CommunityChestCards; cardTile.CardsForProcessing = new string[GameLoop.getInstance().Gameboard.CommunityChestCardsForProcessing.GetLength(0), GameLoop.getInstance().Gameboard.CommunityChestCardsForProcessing.GetLength(1)]; cardTile.CardsForProcessing = GameLoop.getInstance().Gameboard.CommunityChestCardsForProcessing; } // if land on a chance card space, set the list of chance cards and the processing array to local variables else if (player.Location == 7 || player.Location == 22 || player.Location == 36) { cardsList = GameLoop.getInstance().Gameboard.ChanceCards; cardTile.CardsForProcessing = new string[GameLoop.getInstance().Gameboard.ChanceCardsForProcessing.GetLength(0), GameLoop.getInstance().Gameboard.ChanceCardsForProcessing.GetLength(1)]; cardTile.CardsForProcessing = GameLoop.getInstance().Gameboard.ChanceCardsForProcessing; } // pick a random proccessed card int randomNum = GameLoop.getInstance().Gameboard.Rand.Next(cardTile.CardsForProcessing.GetLength(0)); for (int j = 0; j < cardTile.ProcessedCard.GetLength(1); j++) { cardTile.ProcessedCard[0, j] = cardTile.CardsForProcessing[randomNum, j]; } // if a Community Chest, card display the form if (cardTile.Name.Contains("Community Chest")) { CommunityChestCard communityChestCard = new CommunityChestCard(); communityChestCard.Owner = this; communityChestCard.tbOutputCommunityChest.Text = cardTile.ProcessedCard[0, 0]; communityChestCard.ShowDialog(); } // if a Chance card, display the form else if (cardTile.Name.Contains("Chance")) { ChanceCard chanceCard = new ChanceCard(); chanceCard.Owner = this; // Display the card's description chanceCard.tbOutputChance.Text = cardTile.ProcessedCard[0, 0]; chanceCard.ShowDialog(); } }
/// <summary> /// The current player purchases the property /// </summary> private void btnYesBuy_Click(object sender, RoutedEventArgs e) { // Disable buttons btnYesBuy.IsEnabled = false; btnNoDoNotBuy.IsEnabled = false; // Get the current player, player location, and property that the player landed on Player currentPlayer = GameLoop.getInstance().Gameboard.Players[GameLoop.getInstance().Gameboard.CurrentPlayerIndex]; int playerCurrentLocation = currentPlayer.Location; Property property = (Property)GameLoop.getInstance().Gameboard.TileOrder[playerCurrentLocation]; // Buy the property currentPlayer.CurrentPropertyAction = Player.PropertyAction.IsBuying; property.LocationAction(currentPlayer); //Close window Close(); }
private void updateProperty(Utility p, Player player, TextBlock tb) { if (!p.IsOwned) { tb.Foreground = Brushes.Green; tb.Text = p.Cost.ToString("c0"); } else if (p.Owner == player) { tb.Foreground = Brushes.Black; tb.Text = "Owned"; } else { tb.Foreground = Brushes.Red; tb.Text = (p.Rent * GameLoop.getInstance().Gameboard.RolledDice[0] * GameLoop.getInstance().Gameboard.RolledDice[1]).ToString("c0"); } }
/// <summary> /// Brings up the load file dialog /// </summary> private void loadGameUpdateDisplay() { Player currentPlayer = GameLoop.getInstance().Gameboard.Players[GameLoop.getInstance().Gameboard.CurrentPlayerIndex]; // Updates current player data display DisplayPlayerName(currentPlayer); DisplayTurnCounter(); lblRollResult.Content = "-- --"; DisplayCurrentPlayerMoney(currentPlayer); DisplayCurrentPlayerProperties(currentPlayer); // Updates all players' icon display foreach (Player p in GameLoop.getInstance().Gameboard.Players) { gridBoard.Children.Remove(GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon); gridBoard.Children.Add(GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon); } UpdateBoard(currentPlayer); UpdatePlayerIconPosition(currentPlayer); // Current player location display also gets updated here }
/// <summary> /// Brings up the load file dialog /// </summary> private void BtnLoad_Click(object sender, RoutedEventArgs e) { foreach (Player p in GameLoop.getInstance().Gameboard.Players) { gridBoard.Children.Remove(GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon); } if (GameLoop.getInstance().LoadGame()) { loadGameUpdateDisplay(); MessageBox.Show("Game Loaded!"); } else { foreach (Player p in GameLoop.getInstance().Gameboard.Players) { gridBoard.Children.Add(GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon); } MessageBox.Show("Error: Save file could not be loaded."); } }
/// <summary> /// Ends the player's turn. /// </summary> private void BtnEndTurn_Click(object sender, RoutedEventArgs e) { // Advances player GameLoop.getInstance().Gameboard.CurrentPlayerIndex++; if (GameLoop.getInstance().Gameboard.CurrentPlayerIndex >= GameLoop.getInstance().Gameboard.Players.Count()) { GameLoop.getInstance().Gameboard.CurrentPlayerIndex = 0; // Loops to the beginning of the player list GameLoop.getInstance().Gameboard.TurnCount++; } UpdateBoard(GameLoop.getInstance().Gameboard.Players[GameLoop.getInstance().Gameboard.CurrentPlayerIndex]); // If turn limit is reached... (must be ">" so every player gets their final turn) if (GameLoop.getInstance().Gameboard.TurnCount > 20) { EndGame end = new EndGame(); end.Owner = this; end.ShowDialog(); Application.Current.Shutdown(); // Closes Game } else { Player currentPlayer = GameLoop.getInstance().Gameboard.Players[GameLoop.getInstance().Gameboard.CurrentPlayerIndex]; GameLoop.getInstance().Gameboard.TurnIsReadyToEnd = false; // Updates the player display data to show the next player's data, as of the start of their turn. btnEndTurn.IsEnabled = GameLoop.getInstance().Gameboard.TurnIsReadyToEnd; DisplayPlayerName(currentPlayer); DisplayPlayerIcon(currentPlayer); DisplayTurnCounter(); lblRollResult.Content = "-- --"; DisplayCurrentPlayerLocation(currentPlayer); DisplayCurrentPlayerMoney(currentPlayer); DisplayCurrentPlayerProperties(currentPlayer); btnRoll.IsEnabled = !GameLoop.getInstance().Gameboard.TurnIsReadyToEnd; } }
/// <summary> /// Updates the visual location of all players' icons. /// </summary> /// <param name="player">Current player</param> private void UpdatePlayerIconPosition(Player player) { DisplayCurrentPlayerLocation(player); int playerIDX = 0; // Updates the player's displayed location foreach (Player p in GameLoop.getInstance().Gameboard.Players) { if (playerIDX == 0) { Image playerIcon = GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon; if (p.Location >= 0 && p.Location <= 10) { playerIcon.VerticalAlignment = VerticalAlignment.Top; playerIcon.HorizontalAlignment = HorizontalAlignment.Left; Grid.SetRow(playerIcon, 0); Grid.SetColumn(playerIcon, p.Location); } else if (p.Location > 10 && p.Location <= 20) { playerIcon.VerticalAlignment = VerticalAlignment.Top; playerIcon.HorizontalAlignment = HorizontalAlignment.Right; Grid.SetRow(playerIcon, p.Location - 10); Grid.SetColumn(playerIcon, 10); } else if (p.Location > 20 && p.Location <= 30) { playerIcon.VerticalAlignment = VerticalAlignment.Bottom; playerIcon.HorizontalAlignment = HorizontalAlignment.Right; Grid.SetRow(playerIcon, 10); Grid.SetColumn(playerIcon, Math.Abs((p.Location - 20) - 10)); } else { playerIcon.VerticalAlignment = VerticalAlignment.Bottom; playerIcon.HorizontalAlignment = HorizontalAlignment.Left; Grid.SetRow(playerIcon, Math.Abs((p.Location - 30) - 10)); Grid.SetColumn(playerIcon, 0); } } else if (playerIDX == 1) { Image playerIcon = GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon; if (p.Location >= 0 && p.Location <= 10) { playerIcon.VerticalAlignment = VerticalAlignment.Top; playerIcon.HorizontalAlignment = HorizontalAlignment.Right; Grid.SetRow(playerIcon, 0); Grid.SetColumn(playerIcon, p.Location); } else if (p.Location > 10 && p.Location <= 20) { playerIcon.VerticalAlignment = VerticalAlignment.Bottom; playerIcon.HorizontalAlignment = HorizontalAlignment.Right; Grid.SetRow(playerIcon, p.Location - 10); Grid.SetColumn(playerIcon, 10); } else if (p.Location > 20 && p.Location <= 30) { playerIcon.VerticalAlignment = VerticalAlignment.Bottom; playerIcon.HorizontalAlignment = HorizontalAlignment.Left; Grid.SetRow(playerIcon, 10); Grid.SetColumn(playerIcon, Math.Abs((p.Location - 20) - 10)); } else { playerIcon.VerticalAlignment = VerticalAlignment.Top; playerIcon.HorizontalAlignment = HorizontalAlignment.Left; Grid.SetRow(playerIcon, Math.Abs((p.Location - 30) - 10)); Grid.SetColumn(playerIcon, 0); } } else if (playerIDX == 2) { Image playerIcon = GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon; if (p.Location >= 0 && p.Location <= 10) { playerIcon.VerticalAlignment = VerticalAlignment.Center; playerIcon.HorizontalAlignment = HorizontalAlignment.Right; Grid.SetRow(playerIcon, 0); Grid.SetColumn(playerIcon, p.Location); } else if (p.Location > 10 && p.Location <= 20) { playerIcon.VerticalAlignment = VerticalAlignment.Bottom; playerIcon.HorizontalAlignment = HorizontalAlignment.Center; Grid.SetRow(playerIcon, p.Location - 10); Grid.SetColumn(playerIcon, 10); } else if (p.Location > 20 && p.Location <= 30) { playerIcon.VerticalAlignment = VerticalAlignment.Center; playerIcon.HorizontalAlignment = HorizontalAlignment.Left; Grid.SetRow(playerIcon, 10); Grid.SetColumn(playerIcon, Math.Abs((p.Location - 20) - 10)); } else { playerIcon.VerticalAlignment = VerticalAlignment.Top; playerIcon.HorizontalAlignment = HorizontalAlignment.Center; Grid.SetRow(playerIcon, Math.Abs((p.Location - 30) - 10)); Grid.SetColumn(playerIcon, 0); } } else if (playerIDX == 3) { Image playerIcon = GameLoop.getInstance().Icons[p.IconIndex].PlayerIcon; if (p.Location >= 0 && p.Location <= 10) { playerIcon.VerticalAlignment = VerticalAlignment.Center; playerIcon.HorizontalAlignment = HorizontalAlignment.Left; Grid.SetRow(playerIcon, 0); Grid.SetColumn(playerIcon, p.Location); } else if (p.Location > 10 && p.Location <= 20) { playerIcon.VerticalAlignment = VerticalAlignment.Top; playerIcon.HorizontalAlignment = HorizontalAlignment.Center; Grid.SetRow(playerIcon, p.Location - 10); Grid.SetColumn(playerIcon, 10); } else if (p.Location > 20 && p.Location <= 30) { playerIcon.VerticalAlignment = VerticalAlignment.Center; playerIcon.HorizontalAlignment = HorizontalAlignment.Right; Grid.SetRow(playerIcon, 10); Grid.SetColumn(playerIcon, Math.Abs((p.Location - 20) - 10)); } else { playerIcon.VerticalAlignment = VerticalAlignment.Bottom; playerIcon.HorizontalAlignment = HorizontalAlignment.Center; Grid.SetRow(playerIcon, Math.Abs((p.Location - 30) - 10)); Grid.SetColumn(playerIcon, 0); } } playerIDX++; } }
public override void LocationAction(Player player) { // When the card allows the current player to collect money if (ProcessedCard[0, 1] == "Collect") { // if the current player collects money only once if (ProcessedCard[0, 2] == "Once") { // the current player recieves the money int.TryParse(ProcessedCard[0, 3], out int collectedMoney); player.Money += collectedMoney; } // the current player collects money from every player else if (ProcessedCard[0, 2] == "Every") { int.TryParse(ProcessedCard[0, 3], out int collectedMoney); // Take the money away from each player in the list except the current player foreach (Player member in GameLoop.getInstance().Gameboard.Players) { if (member == player) { continue; } else { member.Money -= collectedMoney; player.Money += collectedMoney; } } } } else if (ProcessedCard[0, 1] == "Pay") { // if the current player collects money only once if (ProcessedCard[0, 2] == "Once") { // the current player pays the money int.TryParse(ProcessedCard[0, 3], out int payMoney); player.Money -= payMoney; } // the current player pays money from every player else if (ProcessedCard[0, 2] == "Every") { int.TryParse(ProcessedCard[0, 3], out int payMoney); if (payMoney != 0) { // Pay money to each player in the list except the current player foreach (Player member in GameLoop.getInstance().Gameboard.Players) { if (member == player) { continue; } else { member.Money += payMoney; player.Money -= payMoney; } } } } } else if (ProcessedCard[0, 1] == "Advance") { // Move to a direct location if (ProcessedCard[0, 2] == "NotNearest") { string nameOfTile = ProcessedCard[0, 3]; // if the card specifies to move forward or backwards a certain number of spaces, move the player to this new location if (nameOfTile == "Location") { int.TryParse(ProcessedCard[0, 5], out int SpacesToMove); int newLocation = player.Location + SpacesToMove; GameLoop.getInstance().Gameboard.Move(player, newLocation); } else // move player to specified tile { for (int i = 0; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++) { // if the tile name equals the name from the processing array, move player to that location if (GameLoop.getInstance().Gameboard.TileOrder[i].Name == nameOfTile) { GameLoop.getInstance().Gameboard.Move(player, i); if (nameOfTile == "Jail") { player.IsInJail = true; } break; } } } } else if (ProcessedCard[0, 2] == "Nearest") { if (ProcessedCard[0, 3] == "Railroad") { // for player locations less than the last railroad on the game board if (player.Location < 35) { for (int i = player.Location + 1; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++) { // move player to nearest railroad and set advance to nearst railroad attribute used to Calculate Rent if (GameLoop.getInstance().Gameboard.TileOrder[i].GetType() == typeof(Railroad)) { GameLoop.getInstance().Gameboard.Move(player, i); Railroad nearestRailroad = (Railroad)GameLoop.getInstance().Gameboard.TileOrder[i]; nearestRailroad.NearestRailroad = true; break; } } } // for player locations greater than or equal to the last railroad on the game board else { for (int i = 0; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++) { // move player to nearest railroad, and set advance to nearst railroad attribute used to Calculate Rent if (GameLoop.getInstance().Gameboard.TileOrder[i].GetType() == typeof(Railroad)) { GameLoop.getInstance().Gameboard.Move(player, i); Railroad nearestRailroad = (Railroad)GameLoop.getInstance().Gameboard.TileOrder[i]; nearestRailroad.NearestRailroad = true; break; } } } } else if (ProcessedCard[0, 3] == "Utility") { // for player locations less than the last utility on the game board if (player.Location < 28) { for (int i = player.Location + 1; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++) { // move player to nearest utility, and set advance to nearst utility attribute used to Calculate Rent if (GameLoop.getInstance().Gameboard.TileOrder[i].GetType() == typeof(Utility)) { GameLoop.getInstance().Gameboard.Move(player, i); Utility nearestUtility = (Utility)GameLoop.getInstance().Gameboard.TileOrder[i]; nearestUtility.NearstUtility = true; break; } } } // for player locations greater than or equal to the last utility on the game board else { for (int i = 0; i < GameLoop.getInstance().Gameboard.TileOrder.Length; i++) { // move player to nearest utility, and set advance to nearst utility attribute used to Calculate Rent if (GameLoop.getInstance().Gameboard.TileOrder[i].GetType() == typeof(Utility)) { GameLoop.getInstance().Gameboard.Move(player, i); Utility nearestUtility = (Utility)GameLoop.getInstance().Gameboard.TileOrder[i]; nearestUtility.NearstUtility = true; break; } } } } } } }
private void BtnStart_Click(object sender, RoutedEventArgs e) { int player1IconNumber = 1; int player2IconNumber = 2; int player3IconNumber = 3; int player4IconNumber = 4; if ((bool)rbCar1.IsChecked) { player1IconNumber = 0; } else if ((bool)rbDog1.IsChecked) { player1IconNumber = 1; } else if ((bool)rbHat1.IsChecked) { player1IconNumber = 2; } else if ((bool)rbIron1.IsChecked) { player1IconNumber = 3; } else if ((bool)rbShip1.IsChecked) { player1IconNumber = 4; } else if ((bool)rbShoe1.IsChecked) { player1IconNumber = 5; } else if ((bool)rbThimble1.IsChecked) { player1IconNumber = 6; } else if ((bool)rbWheelbarrow1.IsChecked) { player1IconNumber = 7; } if ((bool)rbCar2.IsChecked) { player2IconNumber = 0; } else if ((bool)rbDog2.IsChecked) { player2IconNumber = 1; } else if ((bool)rbHat2.IsChecked) { player2IconNumber = 2; } else if ((bool)rbIron2.IsChecked) { player2IconNumber = 3; } else if ((bool)rbShip2.IsChecked) { player2IconNumber = 4; } else if ((bool)rbShoe2.IsChecked) { player2IconNumber = 5; } else if ((bool)rbThimble2.IsChecked) { player2IconNumber = 6; } else if ((bool)rbWheelbarrow2.IsChecked) { player2IconNumber = 7; } if ((bool)rbCar3.IsChecked) { player3IconNumber = 0; } else if ((bool)rbDog3.IsChecked) { player3IconNumber = 1; } else if ((bool)rbHat3.IsChecked) { player3IconNumber = 2; } else if ((bool)rbIron3.IsChecked) { player3IconNumber = 3; } else if ((bool)rbShip3.IsChecked) { player3IconNumber = 4; } else if ((bool)rbShoe3.IsChecked) { player3IconNumber = 5; } else if ((bool)rbThimble3.IsChecked) { player3IconNumber = 6; } else if ((bool)rbWheelbarrow3.IsChecked) { player3IconNumber = 7; } if ((bool)rbCar4.IsChecked) { player4IconNumber = 0; } else if ((bool)rbDog4.IsChecked) { player4IconNumber = 1; } else if ((bool)rbHat4.IsChecked) { player4IconNumber = 2; } else if ((bool)rbIron4.IsChecked) { player4IconNumber = 3; } else if ((bool)rbShip4.IsChecked) { player4IconNumber = 4; } else if ((bool)rbShoe4.IsChecked) { player4IconNumber = 5; } else if ((bool)rbThimble4.IsChecked) { player4IconNumber = 6; } else if ((bool)rbWheelbarrow4.IsChecked) { player4IconNumber = 7; } if (txtBoxName1.Text == "" || txtBoxName2.Text == "") { MessageBox.Show("Please enter names for player 1 and player 2."); } else { if (player1IconNumber == player2IconNumber || player1IconNumber == player3IconNumber || player1IconNumber == player4IconNumber || player2IconNumber == player3IconNumber || player2IconNumber == player4IconNumber || player3IconNumber == player4IconNumber) { MessageBox.Show("Please select icons that are different from each other."); } else { GameLoop.getInstance().Gameboard.AddPlayer(new Player(txtBoxName1.Text, player1IconNumber)); GameLoop.getInstance().Gameboard.AddPlayer(new Player(txtBoxName2.Text, player2IconNumber)); if (txtBoxName3.Text != "") { GameLoop.getInstance().Gameboard.AddPlayer(new Player(txtBoxName3.Text, player3IconNumber)); } if (txtBoxName4.Text != "") { GameLoop.getInstance().Gameboard.AddPlayer(new Player(txtBoxName4.Text, player4IconNumber)); } MainWindow main = new MainWindow(); main.Show(); Close(); } } }
/// <summary> /// Displays the player icon. /// </summary> private void DisplayPlayerIcon(Player player) { imgPlayer.Source = GameLoop.getInstance().Icons[player.IconIndex].PlayerIcon.Source; }
/// <summary> /// Displays what turn the game is on. /// </summary> private void DisplayTurnCounter() { lblTurnCount.Content = "Turn: " + GameLoop.getInstance().Gameboard.TurnCount + " (" + (GameLoop.getInstance().Gameboard.CurrentPlayerIndex + 1) + "/" + GameLoop.getInstance().Gameboard.Players.Count + ")"; }
/// <summary> /// Displays what dice were rolled. /// </summary> private void DisplayRolledDice() { lblRollResult.Content = GameLoop.getInstance().Gameboard.RolledDice[0] + " " + GameLoop.getInstance().Gameboard.RolledDice[1]; }
/// <summary> /// Displays current player's location. /// </summary> /// <param name="player">Current player</param> private void DisplayCurrentPlayerLocation(Player player) { lblLocationResult.Content = "(" + player.Location + ") " + GameLoop.getInstance().Gameboard.TileOrder[player.Location].Name; }
private void UpdateBoard(Player player) { Property p1 = (Property)GameLoop.getInstance().Gameboard.TileOrder[1]; Property p3 = (Property)GameLoop.getInstance().Gameboard.TileOrder[3]; FreeParking p4 = (FreeParking)GameLoop.getInstance().Gameboard.TileOrder[4]; Property p5 = (Railroad)GameLoop.getInstance().Gameboard.TileOrder[5]; Property p6 = (Property)GameLoop.getInstance().Gameboard.TileOrder[6]; Property p8 = (Property)GameLoop.getInstance().Gameboard.TileOrder[8]; Property p9 = (Property)GameLoop.getInstance().Gameboard.TileOrder[9]; Property p11 = (Property)GameLoop.getInstance().Gameboard.TileOrder[11]; Utility p12 = (Utility)GameLoop.getInstance().Gameboard.TileOrder[12]; Property p13 = (Property)GameLoop.getInstance().Gameboard.TileOrder[13]; Property p14 = (Property)GameLoop.getInstance().Gameboard.TileOrder[14]; Property p15 = (Railroad)GameLoop.getInstance().Gameboard.TileOrder[15]; Property p16 = (Property)GameLoop.getInstance().Gameboard.TileOrder[16]; Property p18 = (Property)GameLoop.getInstance().Gameboard.TileOrder[18]; Property p19 = (Property)GameLoop.getInstance().Gameboard.TileOrder[19]; Property p21 = (Property)GameLoop.getInstance().Gameboard.TileOrder[21]; Property p23 = (Property)GameLoop.getInstance().Gameboard.TileOrder[23]; Property p24 = (Property)GameLoop.getInstance().Gameboard.TileOrder[24]; Property p25 = (Railroad)GameLoop.getInstance().Gameboard.TileOrder[25]; Property p26 = (Property)GameLoop.getInstance().Gameboard.TileOrder[26]; Property p27 = (Property)GameLoop.getInstance().Gameboard.TileOrder[27]; Utility p28 = (Utility)GameLoop.getInstance().Gameboard.TileOrder[28]; Property p29 = (Property)GameLoop.getInstance().Gameboard.TileOrder[29]; Property p31 = (Property)GameLoop.getInstance().Gameboard.TileOrder[31]; Property p32 = (Property)GameLoop.getInstance().Gameboard.TileOrder[32]; Property p34 = (Property)GameLoop.getInstance().Gameboard.TileOrder[34]; Property p35 = (Railroad)GameLoop.getInstance().Gameboard.TileOrder[35]; Property p37 = (Property)GameLoop.getInstance().Gameboard.TileOrder[37]; FreeParking p38 = (FreeParking)GameLoop.getInstance().Gameboard.TileOrder[38]; Property p39 = (Property)GameLoop.getInstance().Gameboard.TileOrder[39]; updateProperty(p1, player, tbValue1); updateProperty(p3, player, tbValue3); updateProperty(p4, player, tbValue4); updateProperty(p5, player, tbValue5); updateProperty(p6, player, tbValue6); updateProperty(p8, player, tbValue8); updateProperty(p9, player, tbValue9); updateProperty(p11, player, tbValue11); updateProperty(p12, player, tbValue12); updateProperty(p13, player, tbValue13); updateProperty(p14, player, tbValue14); updateProperty(p15, player, tbValue15); updateProperty(p16, player, tbValue16); updateProperty(p18, player, tbValue18); updateProperty(p19, player, tbValue19); updateProperty(p21, player, tbValue21); updateProperty(p23, player, tbValue23); updateProperty(p24, player, tbValue24); updateProperty(p25, player, tbValue25); updateProperty(p26, player, tbValue26); updateProperty(p27, player, tbValue27); updateProperty(p28, player, tbValue28); updateProperty(p29, player, tbValue29); updateProperty(p31, player, tbValue31); updateProperty(p32, player, tbValue32); updateProperty(p34, player, tbValue34); updateProperty(p35, player, tbValue35); updateProperty(p37, player, tbValue37); updateProperty(p38, player, tbValue38); updateProperty(p39, player, tbValue39); }
/// <summary> /// One iteration of a turn loop (Roll, Move, LocationAction) with the proper logic to support doubles, Jail, and normal turns. /// Updates the GUI at the proper places. /// The button logic is also advanced here, based upon rolling no doubles. /// </summary> /// <param name="player">Current player</param> private void TakeTurn(Player player) { bool doubleWasRolled = false; GameLoop.getInstance().Gameboard.RollDice(); // Roll dice DisplayRolledDice(); // GUI UpdateBoard(player); if (player.IsInJail) { player.TurnsSpentInJail++; UpdatePlayerIconPosition(player); // GUI if (GameLoop.getInstance().Gameboard.RolledDice[0] == GameLoop.getInstance().Gameboard.RolledDice[1] || player.TurnsSpentInJail == 3) // If double was rolled, or this was the 3rd turn spent in Jail, release the player. { player.TurnsSpentInJail = 0; player.IsInJail = false; if (player.TurnsSpentInJail != 3) // If player was released by rolling a double: { GameLoop.getInstance().Gameboard.Move(player); // Move player UpdatePlayerIconPosition(player); // GUI LocationResponse(player); // Action of player's new location UpdatePlayerIconPosition(player); // GUI } } } else { if (GameLoop.getInstance().Gameboard.RolledDice[0] == GameLoop.getInstance().Gameboard.RolledDice[1]) // If doubles were rolled, increase count { doubleWasRolled = true; player.DoublesRolled++; } if (player.DoublesRolled == 3) // If 3rd double was rolled, send player to Jail { player.Location = 10; // Jail space player.IsInJail = true; UpdatePlayerIconPosition(player); // GUI } else { GameLoop.getInstance().Gameboard.Move(player); // Move player UpdatePlayerIconPosition(player); // GUI DisplayCurrentPlayerMoney(player); LocationResponse(player); // Action of player's new location UpdatePlayerIconPosition(player); // GUI } } // Checks to see if the turn should be advanced (dice doubles logic) if (!doubleWasRolled || player.IsInJail) { player.DoublesRolled = 0; GameLoop.getInstance().Gameboard.TurnIsReadyToEnd = true; } else { GameLoop.getInstance().Gameboard.TurnIsReadyToEnd = false; } btnEndTurn.IsEnabled = GameLoop.getInstance().Gameboard.TurnIsReadyToEnd; btnRoll.IsEnabled = !GameLoop.getInstance().Gameboard.TurnIsReadyToEnd; }