コード例 #1
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);
        }
コード例 #2
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();
        }