public void Reset() { Spaces[0] = new GoSpace("Go", 0); Spaces[1] = new PropertySpace("Mediteranian Avenue", 1, 60, 50, 2, 10, 30, 90, 160, 250); Spaces[2] = new CommunityChestSpace("Community Chest", 2); Spaces[3] = new PropertySpace("Baltic Avenue", 3, 60, 50, 4, 20, 60, 180, 320, 450); Spaces[4] = new IncomeTaxSpace("Income Tax", 4); Spaces[5] = new RailroadSpace("Reading Railroad", 5); Spaces[6] = new PropertySpace("Oriental Avenue", 6, 100, 50, 6, 30, 90, 270, 400, 550); Spaces[7] = new ChanceSpace("Chance Space", 7); Spaces[8] = new PropertySpace("Vermont Avenue", 8, 100, 50, 6, 30, 90, 270, 400, 550); Spaces[9] = new PropertySpace("Connecicut Avenue", 9, 120, 50, 8, 40, 100, 300, 450, 600); Spaces[10] = new JailSpace("Jail", 10); Spaces[11] = new PropertySpace("St. Charles Place", 11, 140, 100, 10, 50, 150, 450, 625, 750); Spaces[12] = new ElectricCompanySpace("Electric Company", 12); Spaces[13] = new PropertySpace("States Avenue", 13, 140, 100, 10, 50, 150, 450, 625, 750); Spaces[14] = new PropertySpace("Virginia Avenue", 14, 160, 100, 12, 60, 180, 500, 700, 900); Spaces[15] = new RailroadSpace("Pennsylvania Railroad", 15); Spaces[16] = new PropertySpace("St. James Place", 16, 180, 100, 14, 70, 200, 550, 750, 950); Spaces[17] = new CommunityChestSpace("Community Chest Space", 17); Spaces[18] = new PropertySpace("Tennessee Avenue", 18, 180, 100, 14, 70, 200, 550, 750, 950); Spaces[19] = new PropertySpace("New York Avenue", 19, 200, 100, 16, 80, 220, 600, 800, 1000); Spaces[20] = new FreeParkingSpace("Free Parking", 20); Spaces[21] = new PropertySpace("Kentucky Avenue", 21, 220, 150, 18, 90, 250, 700, 875, 1050); Spaces[22] = new ChanceSpace("Chance Space", 22); Spaces[23] = new PropertySpace("Indiana Avenue", 23, 220, 150, 18, 90, 250, 700, 875, 1050); Spaces[24] = new PropertySpace("Illinois Avenue", 24, 240, 150, 20, 100, 300, 750, 925, 1100); Spaces[25] = new RailroadSpace("B&O Railroad", 25); Spaces[26] = new PropertySpace("Atlantic Avenue", 26, 260, 150, 22, 110, 330, 800, 975, 1150); Spaces[27] = new PropertySpace("Ventnor Avenue", 27, 260, 150, 22, 110, 330, 800, 975, 1150); Spaces[28] = new WaterworksSpace("Water Works", 28); Spaces[29] = new PropertySpace("Marvin Gardens", 29, 280, 150, 24, 120, 360, 850, 1025, 1200); Spaces[30] = new GoToJailSpace("Go to Jail", 30); Spaces[31] = new PropertySpace("Pacific Avenue", 31, 300, 200, 26, 130, 390, 900, 1100, 1275); Spaces[32] = new PropertySpace("North Carolina Avenue", 32, 300, 200, 26, 130, 390, 900, 1100, 1275); Spaces[33] = new CommunityChestSpace("Community Chest Space", 33); Spaces[34] = new PropertySpace("Pennsylvania", 34, 320, 200, 28, 150, 450, 1000, 1200, 1400); Spaces[35] = new RailroadSpace("Short Line", 35); Spaces[36] = new ChanceSpace("Chance Space", 36); Spaces[37] = new PropertySpace("Park Place", 37, 350, 200, 35, 175, 500, 1100, 1300, 1500); Spaces[38] = new LuxuryTaxSpace("Luxury Tax", 38); Spaces[39] = new PropertySpace("Boardwalk", 39, 400, 200, 50, 200, 600, 1400, 1700, 2000); }
public static IList <Space> GetField() { List <Space> listOfSpaces = new List <Space>(); //ChanceSpace ChanceSpaceObject=new ChanceSpace(); CommunityChestSpace communityChestSpaceObject = new CommunityChestSpace(); ChanceSpace chanceSpaceObject = new ChanceSpace(); ParkingSpace parking = new ParkingSpace(); listOfSpaces.Add(parking); PropertySpace oldKentRoad = new PropertySpace("Old Kent Road", 60, 30, 2, 10, 30, 90, 160, 250, Color.Brown); listOfSpaces.Add(oldKentRoad); listOfSpaces.Add(communityChestSpaceObject); PropertySpace whiteChappelRoad = new PropertySpace("White Chapel Road", 60, 30, 4, 20, 60, 180, 320, 450, Color.Brown); listOfSpaces.Add(whiteChappelRoad); Tax incomeTax = new Tax(200); listOfSpaces.Add(incomeTax); RailRoad kingsCrossStation = new RailRoad("Kings Cross Station", 200, 100, 25); listOfSpaces.Add(kingsCrossStation); PropertySpace theAngleIslington = new PropertySpace("The Angel Islington", 100, 50, 6, 30, 90, 270, 400, 550, Color.LightBlue); listOfSpaces.Add(theAngleIslington); listOfSpaces.Add(chanceSpaceObject); PropertySpace eustonRoad = new PropertySpace("Euston Road", 100, 50, 6, 30, 90, 270, 400, 550, Color.LightBlue); listOfSpaces.Add(eustonRoad); PropertySpace pentonvilleRoad = new PropertySpace("Pentonville Road", 120, 60, 8, 40, 100, 300, 450, 600, Color.LightBlue); listOfSpaces.Add(pentonvilleRoad); Jail jail = new Jail(); listOfSpaces.Add(jail); PropertySpace pallMall = new PropertySpace("Pall Mall", 140, 70, 10, 50, 150, 450, 625, 750, Color.Pink); listOfSpaces.Add(pallMall); UtilitySpace electricCompany = new UtilitySpace("Electric Company", 150, 75, 30); listOfSpaces.Add(electricCompany); PropertySpace whitehall = new PropertySpace("Whitehall", 140, 70, 10, 50, 150, 450, 625, 750, Color.Pink); listOfSpaces.Add(whitehall); PropertySpace nortamberLandAvenue = new PropertySpace("Northumberland avenue", 160, 80, 12, 60, 180, 500, 700, 900, Color.Pink); listOfSpaces.Add(nortamberLandAvenue); RailRoad marylibone = new RailRoad("Marylibone station", 200, 100, 25); listOfSpaces.Add(marylibone); PropertySpace bawStreet = new PropertySpace("Bow Street", 180, 90, 14, 70, 200, 550, 750, 950, Color.Orange); listOfSpaces.Add(bawStreet); listOfSpaces.Add(communityChestSpaceObject); PropertySpace marlboroStreet = new PropertySpace("Marlborough Street", 180, 90, 14, 70, 200, 550, 750, 950, Color.Orange); listOfSpaces.Add(marlboroStreet); PropertySpace vineStreet = new PropertySpace("Vine Street", 200, 100, 16, 80, 220, 600, 800, 1000, Color.Orange); listOfSpaces.Add(vineStreet); listOfSpaces.Add(parking); PropertySpace strand = new PropertySpace("Strand", 200, 110, 18, 90, 250, 700, 875, 1050, Color.Red); listOfSpaces.Add(strand); listOfSpaces.Add(chanceSpaceObject); PropertySpace fleetStreet = new PropertySpace("Fleet Street", 220, 110, 18, 90, 250, 700, 875, 1050, Color.Red); listOfSpaces.Add(fleetStreet); PropertySpace trafalfarQuare = new PropertySpace("Trafalgar Square", 240, 120, 20, 100, 300, 750, 925, 1100, Color.Red); listOfSpaces.Add(trafalfarQuare); RailRoad fanchurchStation = new RailRoad("Fanchurch Station", 200, 100, 25); listOfSpaces.Add(fanchurchStation); PropertySpace leicesterSquare = new PropertySpace("Leicester square", 260, 130, 22, 110, 330, 800, 975, 1150, Color.Yellow); listOfSpaces.Add(leicesterSquare); PropertySpace coventryStreet = new PropertySpace("Coventry Street", 260, 130, 22, 110, 330, 800, 975, 1150, Color.Yellow); listOfSpaces.Add(coventryStreet); UtilitySpace waterCompany = new UtilitySpace("Water Company", 150, 75, 30); listOfSpaces.Add(waterCompany); PropertySpace piccadilly = new PropertySpace("Piccadilly", 280, 140, 22, 120, 360, 850, 1025, 1200, Color.Yellow); listOfSpaces.Add(piccadilly); GoToPrison gotoPrison = new GoToPrison(); listOfSpaces.Add(gotoPrison); PropertySpace oxfordStreet = new PropertySpace("Oxford Street", 300, 150, 26, 130, 390, 900, 1100, 1275, Color.Green); listOfSpaces.Add(oxfordStreet); PropertySpace regentStreet = new PropertySpace("Regent Street", 300, 150, 26, 130, 390, 900, 1100, 1275, Color.Green); listOfSpaces.Add(regentStreet); listOfSpaces.Add(communityChestSpaceObject); PropertySpace bondStreet = new PropertySpace("Bond Street", 320, 160, 28, 150, 450, 1000, 1200, 1400, Color.Green); listOfSpaces.Add(bondStreet); RailRoad liverpoolStation = new RailRoad("Liverpool Station", 200, 100, 25); listOfSpaces.Add(liverpoolStation); listOfSpaces.Add(chanceSpaceObject); PropertySpace parkLane = new PropertySpace("Park Lane", 350, 175, 35, 175, 500, 1100, 1300, 1500, Color.DarkBlue); listOfSpaces.Add(parkLane); Tax superTax = new Tax(100); listOfSpaces.Add(superTax); PropertySpace mayfair = new PropertySpace("Mayfair", 400, 200, 50, 200, 600, 1400, 1700, 2000, Color.DarkBlue); listOfSpaces.Add(mayfair); return(listOfSpaces); }
/// <summary> /// Инициализирует игру и создает все игровые переменные. /// - playerArray - массив игроков /// - spaceArray - массив клеток(пространств) /// - обновление поля со статистикой и информацией /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNewGame_Click(object sender, EventArgs e) { bool checkClick = true; //проверка, совершено ли было нажатие кнопки colorArray[0] = Color.Green; colorArray[1] = Color.Blue; colorArray[2] = Color.Red; colorArray[3] = Color.Purple; if (checkClick == true && QPlayersIn.ReadOnly == true) { DialogResult dialog = MessageBox.Show("Вы уверены, что хотите завершить текущую игру?", "Завершение текущей игры", MessageBoxButtons.YesNo); if (dialog == System.Windows.Forms.DialogResult.Yes) { backToStart(); btnNewGame.Text = "Новая игра"; } } else { try { QPlayers = Int32.Parse(QPlayersIn.Text); if (QPlayers == 2) { lblP3Turn.Visible = false; lblP4Turn.Visible = false; txtPlayer3M.Visible = false; txtPlayer4M.Visible = false; lblPlayer3M.Visible = false; lblPlayer4M.Visible = false; } if (QPlayers == 3) { lblP4Turn.Visible = false; txtPlayer4M.Visible = false; lblPlayer4M.Visible = false; } if (QPlayers <= 1 || QPlayers >= 5) { MessageBox.Show("Введите число в интервале 2 - 4!"); checkClick = false; } else { QPlayersIn.ReadOnly = true;//отключение выбора кол-ва игроков btnNewGame.Text = "Завершить игру"; playerArray = new Player[QPlayers]; for (int i = 0; i < QPlayers; i++) { playerArray[i] = new Player(); } } } catch (FormatException) { MessageBox.Show("Пожалуйста, введите число в интервале 2 - 4 в поле!"); QPlayersIn.ReadOnly = false; return; } if (checkClick == true) { // Инициализация игровых клеток spaceArray[0] = new GoSpace(); spaceArray[1] = new PropertySpace(25); spaceArray[2] = new DrawCardSpace(); spaceArray[3] = new PropertySpace(50); spaceArray[4] = new GameSpace("default"); spaceArray[5] = new PropertySpace(75); spaceArray[6] = new DrawCardSpace(); spaceArray[7] = new PropertySpace(100); spaceArray[8] = new GameSpace("default"); spaceArray[9] = new PropertySpace(125); spaceArray[10] = new DrawCardSpace(); spaceArray[11] = new PropertySpace(150); spaceArray[12] = new GoToJailSpace(); spaceArray[13] = new PropertySpace(175); spaceArray[14] = new DrawCardSpace(); spaceArray[15] = new PropertySpace(200); // Включение кнопок с клетками btnGO.Enabled = true; btnSvobody.Enabled = true; btnChance1.Enabled = true; btnPushkina.Enabled = true; btnJail.Enabled = true; btnGagarina.Enabled = true; btnChance2.Enabled = true; btnYubiley.Enabled = true; btnFP.Enabled = true; btnLenina.Enabled = true; btnChance3.Enabled = true; btnProf.Enabled = true; btnGoToJail.Enabled = true; btnTverskaya.Enabled = true; btnChance4.Enabled = true; btnSovetskaya.Enabled = true; btnRollDice.Visible = true; pictureDice.Visible = true;// updateStats(); changeTurn(); playerPosition(); } } }
public bool ownsMonopoly(Player player, PropertySpace prop, Board bored) { if (prop.ID == 1 || prop.ID == 3) { if (((PropertySpace)(board.Spaces[1])).Owner == ((PropertySpace)(board.Spaces[3])).Owner) { return(true); } else { return(false); } } if (prop.ID == 6 || prop.ID == 8 || prop.ID == 9) { if (((PropertySpace)(board.Spaces[6])).Owner == ((PropertySpace)(board.Spaces[8])).Owner && ((PropertySpace)(board.Spaces[9])).Owner == ((PropertySpace)(board.Spaces[8])).Owner) { return(true); } else { return(false); } } if (prop.ID == 11 || prop.ID == 13 || prop.ID == 14) { if (((PropertySpace)(board.Spaces[11])).Owner == ((PropertySpace)(board.Spaces[13])).Owner && ((PropertySpace)(board.Spaces[13])).Owner == ((PropertySpace)(board.Spaces[14])).Owner) { return(true); } else { return(false); } } if (prop.ID == 16 || prop.ID == 18 || prop.ID == 19) { if (((PropertySpace)(board.Spaces[16])).Owner == ((PropertySpace)(board.Spaces[18])).Owner && ((PropertySpace)(board.Spaces[19])).Owner == ((PropertySpace)(board.Spaces[18])).Owner) { return(true); } else { return(false); } } if (prop.ID == 21 || prop.ID == 23 || prop.ID == 24) { if (((PropertySpace)(board.Spaces[21])).Owner == ((PropertySpace)(board.Spaces[23])).Owner && ((PropertySpace)(board.Spaces[23])).Owner == ((PropertySpace)(board.Spaces[24])).Owner) { return(true); } else { return(false); } } if (prop.ID == 26 || prop.ID == 27 || prop.ID == 29) { if (((PropertySpace)(board.Spaces[26])).Owner == ((PropertySpace)(board.Spaces[27])).Owner && ((PropertySpace)(board.Spaces[29])).Owner == ((PropertySpace)(board.Spaces[27])).Owner) { return(true); } else { return(false); } } if (prop.ID == 31 || prop.ID == 32 || prop.ID == 34) { if (((PropertySpace)(board.Spaces[31])).Owner == ((PropertySpace)(board.Spaces[32])).Owner && ((PropertySpace)(board.Spaces[32])).Owner == ((PropertySpace)(board.Spaces[34])).Owner) { return(true); } else { return(false); } } if (prop.ID == 37 || prop.ID == 39) { if (((PropertySpace)(board.Spaces[37])).Owner == ((PropertySpace)(board.Spaces[39])).Owner) { return(true); } else { return(false); } } return(false); }
public void handlePossible(Player curPlayer) { Console.WriteLine("What would you like to do? Enter your choice as an integer."); Console.WriteLine(); Console.WriteLine("Current wealth: " + curPlayer.money); Console.WriteLine(); Console.Write("Current properties (5 houses means a hotel): "); //find properties int t = 0; foreach (Space sp in board.Spaces) { if (sp is Buyable space) { if (space.Owner == curPlayer) { t++; Console.Write(space.name); if (space is PropertySpace s) { Console.WriteLine(" which has " + s.houseCount + " houses"); } if (space.IsMortgaged) { Console.Write(" and is mortgaged; "); } else { Console.Write(" and is not mortgaged; "); } } } } if (t == 0) { Console.WriteLine("None!"); } else { Console.WriteLine(); } int exit = -1; beenDareDoneDat = false; while (true) { Console.WriteLine("Player balence: $" + curPlayer.money); Console.WriteLine(); Console.WriteLine("1: Buy houses for your properties"); Console.WriteLine("2: Sell houses on your properties"); Console.WriteLine("3: Mortgage your properties"); Console.WriteLine("4: Buy back your properties"); Console.WriteLine("5: Exit"); if (!curPlayer.isAI) { exit = int.Parse(Console.ReadLine()); } else { if (beenDareDoneDat) { exit = 5; } else if (curPlayer.money > 400) { exit = 1; } else if (curPlayer.money < 0) { exit = 3; } else if (curPlayer.money > 200) { exit = 4; } else { exit = 5; } } Console.WriteLine(); if (exit == 5) { break; } //BuyBack if (exit == 4) { List <Buyable> spList = new List <Buyable>(); foreach (Space sp in board.Spaces) { if ((sp is Buyable space) && space.IsMortgaged && space.Owner == curPlayer) { spList.Add(space); } } bool esc = false; int escape = -1; while (!esc) { int k = 0; foreach (Buyable sp in spList) { Console.WriteLine(k + ": " + sp.name + " with a cost to buy back of " + (sp.GetPrice() / 2) * 1.1); k++; } Console.WriteLine(k + ": Exit"); Console.WriteLine(); Console.WriteLine("Enter an int for your selection"); if (curPlayer.isAI) { if (curPlayer.money > 200) { escape = 0; } else { escape = k; } } else { escape = int.Parse(Console.ReadLine()); } if (escape == k) { esc = true; } else { Buyable a = spList[escape]; spList.RemoveAt(escape); a.BuyBack(); } } } //end buyback if (exit == 3) { List <Buyable> spList = new List <Buyable>(); foreach (Space sp in board.Spaces) { if ((sp is Buyable space) && !space.IsMortgaged && space.Owner == curPlayer) { if (space is PropertySpace s && s.houseCount > 0) { continue; } spList.Add(space); } } bool esc = false; int escape = -1; while (!esc) { int k = 0; foreach (Buyable sp in spList) { Console.WriteLine(k + ": " + sp.name + " with mortgage payment of " + (sp.GetPrice() / 2)); k++; } Console.WriteLine(k + ": Exit"); Console.WriteLine(); Console.WriteLine("Enter an int for your selection"); if (curPlayer.isAI) { if (curPlayer.money < 0) { escape = 0; } else { escape = k; } } else { escape = int.Parse(Console.ReadLine()); } if (escape == k) { esc = true; } else { Buyable a = spList[escape]; spList.RemoveAt(escape); a.Mortgage(); } } } //end mortgage if (exit == 2) //sell houses { List <PropertySpace> spList = new List <PropertySpace>(); foreach (Space sp in board.Spaces) { if ((sp is PropertySpace space) && space.houseCount > 0) { spList.Add(space); } } bool esc = false; int escape = -1; while (!esc) { int k = 0; foreach (PropertySpace sp in spList) { if (sp.houseCount > 0) { Console.WriteLine(k + ": " + sp.name + " with " + sp.houseCount + " houses for sale at $" + (sp.housePrice / 2)); k++; } } Console.WriteLine(k + ": Exit"); Console.WriteLine(); Console.WriteLine("Enter an int for your selection"); escape = int.Parse(Console.ReadLine()); if (escape == k) { esc = true; } else { PropertySpace a = spList[escape]; if (a.houseCount == 1) { spList.RemoveAt(escape); } a.SellHouse(); } } } //end sell houses if (exit == 1) { List <PropertySpace> spList = new List <PropertySpace>(); foreach (Space sp in board.Spaces) { if ((sp is PropertySpace space) && space.houseCount < 5 && curPlayer == space.Owner && ownsMonopoly(curPlayer, space, board)) { spList.Add(space); } } bool esc = false; int escape = -1; while (!esc) { int k = 0; foreach (PropertySpace sp in spList) { if (sp.houseCount < 5) { Console.WriteLine(k + ": " + sp.name + " with " + sp.houseCount + " houses at a cost of $" + sp.housePrice); k++; } } Console.WriteLine(k + ": Exit"); Console.WriteLine(); Console.WriteLine("Enter an int for your selection"); if (curPlayer.isAI) { if (curPlayer.money > 400) { escape = 0; } else { escape = k; } } else { escape = int.Parse(Console.ReadLine()); } if (escape == k) { esc = true; } else { PropertySpace a = spList[escape]; if (a.houseCount == 4) { spList.RemoveAt(escape); } a.AddHouse(); } } } beenDareDoneDat = true; } }