Beispiel #1
0
        /// <summary>
        /// Loads the map string.  See file header for
        /// string format
        /// </summary>
        /// <param name="mapString"></param>
        private void LoadMapString(string mapString)
        {
            // the number of rows and columns in the map
            int rows, cols;

            // split the map string into its rows
            string[] lines = mapString.Split(new char[] { '\n' });

            // if it is not an empty world
            if (lines.Length > 4)
            {
                string carType = lines[0];
                carType = carType.Trim();
                int.TryParse(lines[1], out rows);
                int.TryParse(lines[2], out cols);

                // invalid map size
                if (rows <= 0 || cols <= 0)
                {
                    return;
                }

                // create the world
                map = new MapTile[rows, cols];

                // load the different tiles into the world
                for (int r = 0; r < rows; r++)
                {
                    lines[r + 3] = lines[r + 3].Trim();
                    // the next row in the array
                    // offset by 3 because the first 3 elements in the
                    // array are the size of the world and car type
                    char[] currentLine = lines[r + 3].ToCharArray();

                    // get each tile in the row
                    for (int c = 0; c < cols; c++)
                    {
                        // convert the tile character to the integer
                        int val = (int)char.GetNumericValue(currentLine[c]);

                        // if a valid tile number
                        if (val < NUMBER_OF_TILES_TYPES && currentLine[c] != '\r' && currentLine[c] != '\n')
                        {
                            map[r, c] = (MapTile)val;

                            if (map[r, c] == MapTile.StartingLocation)
                            {
                                _car = CarFactory.MakeCar(carType, r, c, Direction.Up);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public void MakeTeleporter()
 {
     _car = CarFactory.MakeTeleporter(_car.Row, _car.Column, _car.FacingDirection, _car.Colour);
 }
Beispiel #3
0
 public void MakeFlyingCar()
 {
     _car = CarFactory.MakeFlyingCar(_car.Row, _car.Column, _car.FacingDirection, _car.Colour);
 }