Exemple #1
0
        private void SetHeaderRow()
        {
            if (_gameState.Map == null)
            {
                throw new InvalidOperationException("Map needs to be initialized.");
            }

            StringBuilder builder = new StringBuilder();

            builder.Append("   ");
            for (int i = 0; i < _gameState.Map.Size; i++)
            {
                builder.Append(CoordinateConverter.XToString(i));
                builder.Append(" ");
            }

            _headerRow = builder.ToString();
        }
Exemple #2
0
        /// <summary>
        /// Draws the map to the console.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if the map wasn't initialized.</exception>
        public void Draw(int iPlayer)
        {
            if (_gameState.Map == null)
            {
                throw new InvalidOperationException("Map needs to be initialized.");
            }

            Pawn p = _gameState.CurrentPlayer.getCurrentPawn();

            Console.WriteLine("Location : " + CoordinateConverter.XToString(p.Location.X) + CoordinateConverter.YToString(p.Location.Y));


            Console.WriteLine(_headerRow);

            List <MapCoordinates> reachableSectors = Pawn.GetReachableCoordinatesFor(p);

            for (int y = 0; y < _gameState.Map.Size; y++)
            {
                string row = CoordinateConverter.YToString(y).PadRight(3, ' ');
                row += GetGridRowRepresentation(_gameState.Map, y, reachableSectors);
                row += CoordinateConverter.YToString(y).PadLeft(3, ' ');
                Console.WriteLine(row);
            }

            Console.WriteLine(_headerRow);
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            GameParameters parameters = new GameParameters
            {
                MapSize           = Convert.ToInt32(ConfigurationManager.AppSettings["MapSize"]),
                PawnMovementRange = Convert.ToInt32(ConfigurationManager.AppSettings["MovementRange"]),
                NumberPlayers     = Convert.ToInt32(ConfigurationManager.AppSettings["NumberPlayers"]),
                NumberPawnMvt2    = Convert.ToInt32(ConfigurationManager.AppSettings["NumberPawnMvt2"]),
                NumberPawnMvt3    = Convert.ToInt32(ConfigurationManager.AppSettings["NumberPawnMvt3"]),
                NumberPawnMvt4    = Convert.ToInt32(ConfigurationManager.AppSettings["NumberPawnMvt4"]),
                NumberPawn        = Convert.ToInt32(ConfigurationManager.AppSettings["NumberPawnMvt2"])
                                    + Convert.ToInt32(ConfigurationManager.AppSettings["NumberPawnMvt3"])
                                    + Convert.ToInt32(ConfigurationManager.AppSettings["NumberPawnMvt4"])
            };

            if (parameters.MapSize > 26 || parameters.PawnMovementRange < 1)
            {
                parameters = GameParameters.Default;
            }

            Game     currentGame = new Game(parameters);
            GameGrid grid        = new GameGrid {
                GameState = currentGame
            };

            bool shouldExit = false;
            int  tourPlayer = 0;

            int[] tour = new int[2];
            tour[0] = 0;
            tour[1] = 0;
            do
            {
                //Console.Clear();
                Console.WriteLine("(Type 'exit' to leave the game.)");
                Console.WriteLine();
                currentGame.updatePlayerTour(tourPlayer);
                grid.Draw(tourPlayer);
                Console.WriteLine();
                Console.WriteLine();

                Console.WriteLine("[PLAYER " + (tourPlayer + 1) + "]");
                Console.Write("Enter coordinates to move Pawn" + tour[tourPlayer] + " to: ");
                string input = Console.ReadLine();
                shouldExit = !String.IsNullOrWhiteSpace(input) && input.ToLower() == _exitCode;

                if (!shouldExit && CoordinateConverter.TryParse(input, out MapCoordinates destination))
                {
                    MoveResult result = currentGame.MovePawnTo(destination);
                    switch (result)
                    {
                    case MoveResult.Illegal:
                        Console.WriteLine();
                        Console.WriteLine("Can't move there. Press any key to retry.");
                        Console.ReadKey();
                        break;

                    case MoveResult.OK:
                        tour[tourPlayer] = (tour[tourPlayer] + 1) % 5;
                        tourPlayer       = (tourPlayer + 1) % 2;
                        continue;

                    default:
                        Console.WriteLine();
                        Console.WriteLine("Let's not do that again, ok ? Press any key to retry.");
                        Console.ReadKey();
                        break;
                    }
                }
                else
                {
                    if (!shouldExit)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid Input. Press any key to retry.");
                        Console.ReadKey();
                    }
                }
            }while (!shouldExit && !currentGame.CurrentPlayer.isFailed());

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("BRAVO Player " + tourPlayer);
            Console.ReadKey();
        }