Exemple #1
0
 public void generateBlankRoom(int xMod, int yMod)
 {
     for (int y = 0; y < tilesHigh; y++)
     {
         for (int x = 0; x < tilesWide; x++)
         {
             tiles[x * xMod, y * yMod] = new Tile(errorTile, new Rectangle(x * errorTile.Width, y * errorTile.Height, errorTile.Width, errorTile.Height), Color.Pink, false);
         }
     }
 }
Exemple #2
0
        protected void GenerateRoom(int xMod, int yMod)
        {
            int currentChar;
            tilesCode = new Char[tilesWide, tilesHigh];
            fileReader = new StreamReader("someLevel.txt");

            // This first loop iterates through the text file and addes it to a 2D array of characters
            // Because of special complications, and the fact that StreamReader.Read() returns an int, not a char, a lot of work is done with the ASCII coding of what is being returned.
            // ASCII Characters 13 and 10 are a carriage return and newline characters, which must be ignored.  Space is 32, which shouldn't be in the file, but they are easy to sneak in and as such,  is exlucded for now. Character 0 is simply null and is checked for for completions sake.
            // The returned value is later converted back into a character --- Convert.ToChar(someInt);
            for (int y = 0; y < tilesHigh; y++)
            {
                int i = 0;

                // this is an awkward loop.  The real iterator is actually i, but x is used for clarity purposes.  'i' iterates when something is actually added.  if something is skipped, x is deiterated
                for (int x = 0; x < tilesWide; x++)
                {
                    currentChar = fileReader.Read();

                    if (currentChar == 13 || currentChar == 10 || currentChar == 0 || currentChar == 32)
                    {
                        if (debug)
                            Console.WriteLine("Captured NewLine or Carriage Return");
                        x--; // this needs to be here, or we'll have gaps in the level
                    }
                    else
                    {
                        tilesCode[i, y] = Convert.ToChar(currentChar);
                        i++;
                    }
                }
            }

            //This second loop takes the tilesCode array (an array full of the text read from the original text file) and then draws the map based on the output
            //tiles[x, y] corrispond to tilesCode[i, y].  I could actually 'fix' the loop above, and will do at a later date, but it 'works' right now, so I'm inclined to leave it.
            for (int y = 0; y < tilesHigh; y++)
            {
                for (int x = 0; x < tilesWide; x++)
                {
                    if (debug)
                        Console.WriteLine("Ascii:" + (int)tilesCode[x, y] + " -- " + x);

                    switch (tilesCode[x, y])
                    {
                        case '#':
                            tiles[x * xMod, y * yMod] = new Tile(lightFloor, new Rectangle(x * lightFloor.Width, y * lightFloor.Height, lightFloor.Width, lightFloor.Height), Color.White, false);
                            break;
                        case '.':
                            tiles[x * xMod, y * yMod] = new Tile(darkFloor, new Rectangle(x * darkFloor.Width, y * darkFloor.Height, darkFloor.Width, darkFloor.Height), Color.White, false);
                            break;
                        case '^':
                            tiles[x * xMod, y * yMod] = new Tile(topWall, new Rectangle(x * topWall.Width, y * topWall.Height, topWall.Width, topWall.Height), Color.White, false);
                            break;
                        case 'v':
                            tiles[x * xMod, y * yMod] = new Tile(bottomWall, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case '>':
                            tiles[x * xMod, y * yMod] = new Tile(leftWall, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case '<':
                            tiles[x * xMod, y * yMod] = new Tile(rightWall, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case 'Q':
                            tiles[x * xMod, y * yMod] = new Tile(ULWall, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case 'E':
                            tiles[x * xMod, y * yMod] = new Tile(URWall, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case 'Z':
                            tiles[x * xMod, y * yMod] = new Tile(BLWall, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case 'C':
                            tiles[x * xMod, y * yMod] = new Tile(BRWall, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case 'W':
                            tiles[x * xMod, y * yMod] = new Tile(topDoor, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case 'D':
                            tiles[x * xMod, y * yMod] = new Tile(rightDoor, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case 'X':
                            tiles[x * xMod, y * yMod] = new Tile(bottomDoor, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        case 'A':
                            tiles[x * xMod, y * yMod] = new Tile(leftDoor, new Rectangle(x * bottomWall.Width, y * bottomWall.Height, bottomWall.Width, bottomWall.Height), Color.White, false);
                            break;
                        default:
                            tiles[x * xMod, y * yMod] = new Tile(errorTile, new Rectangle(x * errorTile.Width, y * errorTile.Height, errorTile.Width, errorTile.Height), Color.Pink, false);
                            break;
                    }
                }
            }
        }