예제 #1
0
        static void Main(string[] args)
        {
            Board playingBoard = new Board();
            List<Player> players = newPlayers();
            Int16 numberOfPlayers;

            Console.WriteLine("Welcome to Monopoly!");
            Console.Write("How many will be playing (2-4): ");
            Int16.TryParse(Console.ReadLine(), out numberOfPlayers);

            players.RemoveRange(numberOfPlayers, 4 - numberOfPlayers);

            foreach (Player p in players)
            {
                Console.Write("{0}, what's your name: ", p.Name);
                p.Name = Console.ReadLine();

                Console.WriteLine("These tokens are available: {0}", availableTokens(players));
                Console.Write("{0}, which would you like: ", p.Name);
                p.Token = (Tokens)Enum.Parse(typeof(Tokens), Console.ReadLine());
            }

            Console.WriteLine("Let's get started!");
            viewBoard();

            Console.Write("Bob, what's your name: ");
            string a = Console.ReadLine();
        }
 public Player(string _name, Die[] _dice, Board _board, int _cash)
 {
     this.name = _name;
     this.dice = _dice;
     this.board = _board;
     this.cash = _cash;
     this.piece = new Piece(board.GetStartSquare(), this.name);
 }
 public Player(string name, Cup cup, Board board, int cash)
 {
     this.name = name;
     this.cup = cup;
     this.board = board;
     this.cash = cash;
     piece = new Piece(board.GetStartSquare());
     Console.WriteLine("Name:" + name + "Created");
     this.rrcount = 0;
 }
예제 #4
0
        public static void viewBoard(List<Player> players, Board board)
        {
            foreach (Int16 i in viewBoardOrder)
            {
                if (i/10 == 2)
                {

                }
            }

            Console.WriteLine(" ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ");
            Console.WriteLine(String.Format("|{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|"), viewTopName[0], viewTopName[1], viewTopName[2], viewTopName[3], viewTopName[4], viewTopName[5], viewTopName[6], viewTopName[7], viewTopName[8], viewTopName[9], viewTopName[10]);
            Console.WriteLine(String.Format("|{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|"), viewBottomName[0], viewBottomName[1], viewBottomName[2], viewBottomName[3], viewBottomName[4], viewBottomName[5], viewBottomName[6], viewBottomName[7], viewBottomName[8], viewBottomName[9], viewBottomName[10]);
            Console.WriteLine(String.Format("|{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|"), board.PlayingBoard[viewBoardOrder[0]].writeHouses(), board.PlayingBoard[viewBoardOrder[1]].writeHouses(), board.PlayingBoard[viewBoardOrder[2]].writeHouses(), board.PlayingBoard[viewBoardOrder[3]].writeHouses(), board.PlayingBoard[viewBoardOrder[4]].writeHouses(), board.PlayingBoard[viewBoardOrder[5]].writeHouses(), board.PlayingBoard[viewBoardOrder[6]].writeHouses(), board.PlayingBoard[viewBoardOrder[7]].writeHouses(), board.PlayingBoard[viewBoardOrder[8]].writeHouses(), board.PlayingBoard[viewBoardOrder[9]].writeHouses(), board.PlayingBoard[viewBoardOrder[10]].writeHouses());
            Console.WriteLine(String.Format("| {0} {1} |     | 1 2 |   2 |     |     |     |     |     |     |     |"), players[0].location(viewBoardOrder[0]));
            Console.WriteLine("|     |     | 3 4 |     |     |     |     |     |     |     |     |");
            Console.WriteLine("|     |     |  2  |  1  |     |     |     |     |     |     |     |");
            Console.WriteLine(" ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine(" -----                                                       ----- ");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine("|     |                                                     |     |");
            Console.WriteLine(" -----                                                       ----- ");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine(" ----                                         ---- ");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine(" ----                                         ---- ");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine(" ----                                         ---- ");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine(" ----                                         ---- ");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine(" ----                                         ---- ");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine("|    |                                       |    |");
            Console.WriteLine(" ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ");
            Console.WriteLine("|    |    |    |    |    |    |    |    |    | 1 2|");
            Console.WriteLine("|    |    |    |    |    |    |    |    |    |    |");
            Console.WriteLine(" ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ");
        }
예제 #5
0
 //method to access singleton
 public static Board access()
 {
     if (board == null)
         board = new Board();
     return board;
 }
예제 #6
0
        public Board CreateBoard()
        {
            String line = "";
            String[] strValues;
            int[] intValues;
            StreamReader stmReader;
            Char delimitChar = ',';
            Board resultBoard;
            ui.UIDebug("Attempting to create board...");

            try{
                stmReader = new StreamReader(mBoardPath);
                resultBoard = new Board();
                ui.UIDebug("Board stream initalized!");
                for (int i = 1; i <= resultBoard.BoardSpaces.Length - 1; i++)
                {
                    line = stmReader.ReadLine();
                    strValues = line.Split(delimitChar);
                    intValues = new int[strValues.Length];

                    //create int array for int values such as rent, mortagage, etc
                    for (int j = 0; j <= strValues.Length - 1; j++)
                    {
                        try
                        {
                            intValues[j] = int.Parse(strValues[j]);
                        }//try
                        catch (FormatException ex)
                        {
                            intValues[j] = 0;
                            ex.GetType();
                        }//catch
                    }//for

                    //ugly switch, need to revise in the future
                    switch (strValues[0])
                    {
                        case "Property":
                            Rent tempRent = new Rent(intValues[5], intValues[6], intValues[7], intValues[8], intValues[9], intValues[10]);
                            Tiles.Property thisProp = new Tiles.Property(intValues[2], strValues[1], (PropertyColor)intValues[4], intValues[3], tempRent, intValues[11]);
                            resultBoard.BoardSpaces[i] = thisProp;
                            //add the property to the proper color group, see Enums for more details
                            resultBoard.ColorGroups[(int)thisProp.Color].AddProperty(thisProp);
                            break;
                        case "Railroad":
                            resultBoard.BoardSpaces[i] = new Tiles.Railroad(intValues[2], strValues[1]);
                            break;
                        case "Utility":
                            resultBoard.BoardSpaces[i] = new Tiles.Utility(intValues[2], strValues[1]);
                            break;
                        case "LuxuryTax":
                            resultBoard.BoardSpaces[i] = new Tiles.LuxuryTax(intValues[2], strValues[1]);
                            break;
                        case "IncomeTax":
                            resultBoard.BoardSpaces[i] = new Tiles.IncomeTax(intValues[2], strValues[1]);
                            break;
                        case "CommunityChest":
                            resultBoard.BoardSpaces[i] = new Tiles.CommunityChest(intValues[2], strValues[1]);
                            break;
                        case "Chance":
                            resultBoard.BoardSpaces[i] = new Tiles.Chance(intValues[2], strValues[1]);
                            break;
                        case "Go":
                            resultBoard.BoardSpaces[i] = new Tiles.Go(intValues[2], strValues[1]);
                            break;
                        case "GoToJail":
                            resultBoard.BoardSpaces[i] = new Tiles.GoToJail(intValues[2], strValues[1]);
                            break;
                        case "Jail":
                            resultBoard.BoardSpaces[i] = new Tiles.Jail(intValues[2], strValues[1]);
                            break;
                        case "FreeParking":
                            resultBoard.BoardSpaces[i] = new Tiles.FreeParking(intValues[2], strValues[1]);
                            break;
                        default:
                            ui.Error("The BoardReader was unable to determine space type!");
                            break;
                    }//switch

                }//for

            }//try (open streamreader)

            catch (FileNotFoundException ex){
                ui.Error("Stream couldn't be found.", ex);
                return null;
            }//catch FileNotFound (streamreader)

            return resultBoard;
        }
예제 #7
0
 public void BoardIsConstructedWithFortyLocations()
 {
     var locations = ConstructLocations(40);
     var board = new Board(locations);
     Assert.AreEqual(40, board.Locations.Count());
 }
 public int PropertyCountEqualsNumberOfProperties(params string[] names)
 {
     IBoard board = new Board(new PropertyFactory(names));
     return board.PropertyCount;
 }
예제 #9
0
        private void Setup(IEnumerable<IPlayer> players, int roundsToPlay)
        {
            RoundsToPlay = roundsToPlay;

            Board = new Board();

            AddPlayers(players.ToList());
        }
예제 #10
0
 private static void CreateBoard()
 {
     Board theboard = new Board();
     Console.WriteLine("Board Created");
     Console.ReadKey();
 }
예제 #11
0
        public virtual void TakeTurn(Board board)
        {
            Console.WriteLine($"{DisplayName} [${Money} | {OwnedTiles.Count} properties | {MortgagedTiles.Count} mortgaged].");

            if (boardLocation == board.GetSpecialTile(SpecialTileType.Jail).BoardPosition&& JailTurnRemaining > 0)  // In jail
            {
                Console.WriteLine($"{DisplayName} is in jail. {JailTurnRemaining} turn{(JailTurnRemaining > 1 ? "s" : "")} remaining.");
                if (OutOfJailCards.Count > 0)
                {
                    if (IsHuman)
                    {
                        Console.WriteLine($"Do you want to use 1 Get out of Jail card? (You have {OutOfJailCards.Count}) (Y/n)");
                    }

                    if (!IsHuman || Console.ReadKey(true).Key == ConsoleKey.Y)
                    {
                        JailTurnRemaining = 0;
                        Console.WriteLine($"{DisplayName} used 1 Get out of Jail card.");
                    }
                }
            }
            else
            {
                DiceRoll = random.Next(1, 7);
                Tile tile = AdvanceBoardPostiion(board, DiceRoll, false);

                Console.WriteLine($"{DisplayName} rolled a {DiceRoll}.");
                Console.WriteLine($"{DisplayName} is visiting {tile.DisplayName}. {((tile is PropertyTile && ((PropertyTile)tile).Owner != null) ? $"[{((PropertyTile)tile).Owner.DisplayName}]" : String.Empty)}");
                tile.OnVisit(this, board);
            }

            var canUnmortgage = MortgagedTiles.Where(tile => Money > tile.TileOptions.UnMortgageValue).ToList();

            if (canUnmortgage.Count > 0)
            {
                if (IsHuman)
                {
                    Console.WriteLine($"Do you want to buy back any mortgaged property? (Y/n)");
                    ConsoleKey key = Console.ReadKey(true).Key;

                    if (key == ConsoleKey.Y)
                    {
                        do
                        {
                            for (int i = 0; i < canUnmortgage.Count(); i++)
                            {
                                PurchasableRentTile tile = canUnmortgage[i];
                                Console.WriteLine($"Choose the property to unmortgage by entering the corressponding number:");
                                Console.WriteLine($"{i + 1}. {tile.DisplayName} for ${tile.TileOptions.UnMortgageValue}.");
                            }

                            char c;
                            bool isDigit, isValid;
                            int  choice = 0;
                            do
                            {
                                c       = Console.ReadKey(true).KeyChar;
                                isDigit = isValid = char.IsDigit(c);
                                if (c == 'q' || c == 'Q') // Quit
                                {
                                    key = ConsoleKey.N;
                                    break;
                                }
                                else if (!isDigit)
                                {
                                    Console.WriteLine("The value you have entered is not a number. To exit, enter 'Q'.");
                                }
                                else
                                {
                                    choice = int.Parse(c.ToString());
                                    if (choice < 0 || choice >= canUnmortgage.Count())
                                    {
                                        Console.WriteLine("The number you have entered is not a valid choice.");
                                        isValid = false;
                                    }
                                }
                            }while (!(isDigit && isValid));

                            PurchasableRentTile tileToBuyBack = canUnmortgage[choice];
                            tileToBuyBack.UnMortgage();

                            Console.WriteLine($"Continue rebuying more mortgaged property? (Y/n)");
                            key = Console.ReadKey(true).Key;
                        }while (key == ConsoleKey.Y);
                    }
                }
                else
                {
                    canUnmortgage = canUnmortgage.OrderBy(tile => tile.TileOptions.UnMortgageValue).ToList();
                    while (MortgagedTiles.Count > 0 && Money > canUnmortgage.Min(tile => tile.TileOptions.UnMortgageValue * 3 / 2))
                    {
                        PurchasableRentTile tileToBuyBack = canUnmortgage.SkipWhile(tile => !tile.IsMortgaged).First();
                        tileToBuyBack.UnMortgage();
                    }
                }
            }

            if (JailTurnRemaining > 0)
            {
                JailTurnRemaining--;
            }

            Console.WriteLine($"{DisplayName} [${Money} | {OwnedTiles.Count} properties | {OwnedTiles.Where(tile => tile.IsMortgaged).Count()} mortgaged].");
        }
예제 #12
0
 public void Jail(Board board)
 {
     MoveToBoardPostiion(board, board.GetSpecialTile(SpecialTileType.Jail).BoardPosition, false); // Don't call OnVisit again otherwise its an infinite loop.
     JailTurnRemaining = 3;
     Console.WriteLine($"{DisplayName} was sent to jail.");
 }