示例#1
0
        public bool moveCharacterBy(sbyte x, sbyte y)
        {
            FloorTile tile = currentLevel[(byte)(character.X + x), (byte)(character.Y + y)];

            switch (tile.Type)
            {
            case BackgroundType.Wall:
            case BackgroundType.Water:
            case BackgroundType.Entrance:
                break;

            case BackgroundType.Exit:
                if (character.NumberOfDiamondsCollected >= currentLevel.NumberOfDiamondsNeeded)
                {
                    saveGame();
                    return(true);
                }
                break;

            case BackgroundType.Floor:
                if (tile.Item != null && tile.Item.Type == ItemType.Diamond)
                {
                    tile.Item = null;
                    character.NumberOfDiamondsCollected++;
                    character.moveBy(x, y);
                }
                else if (tile.Item == null)
                {
                    character.moveBy(x, y);
                }
                break;
            }
            return(false);
        }
示例#2
0
 public Level(byte x, byte y)
 {
     floor = new FloorTile[x][];
     for (byte i = 0; i < x; i++)
     {
         floor[i] = new FloorTile[y];
     }
 }
示例#3
0
 public void ReadXml(XmlReader reader)
 {
     if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "Level")
     {
         LvlNumber = short.Parse(reader["Number"]);
         Name      = reader["Name"];
         if (reader.ReadToDescendant("StartX"))
         {
             CharacterStartX = byte.Parse(reader.ReadElementContentAsString());
         }
         if (reader.Name == "StartY")
         {
             CharacterStartY = byte.Parse(reader.ReadElementContentAsString());
         }
         if (reader.Name == "EndX")
         {
             CharacterEndX = byte.Parse(reader.ReadElementContentAsString());
         }
         if (reader.Name == "EndY")
         {
             CharacterEndY = byte.Parse(reader.ReadElementContentAsString());
         }
         if (reader.Name == "InLevel")
         {
             NumberOfDiamonds = short.Parse(reader.ReadElementContentAsString());
         }
         if (reader.Name == "Needed")
         {
             NumberOfDiamondsNeeded = short.Parse(reader.ReadElementContentAsString());
         }
         if (reader.Name == "Floor")
         {
             List <FloorTile[]> rows = new List <FloorTile[]>();
             reader.ReadToDescendant("Row");
             while (reader.LocalName == "Row")
             {
                 List <FloorTile> floorTiles = new List <FloorTile>();
                 reader.ReadToDescendant("FloorTile");
                 while (reader.LocalName == "FloorTile")
                 {
                     FloorTile tile = new FloorTile();
                     tile.ReadXml(reader);
                     floorTiles.Add(tile);
                 }
                 rows.Add(floorTiles.ToArray());
                 reader.Read();
             }
             floor = rows.ToArray();
         }
         reader.Read();
     }
 }
示例#4
0
        private static void gameScreen(GameLogic game)
        {
            Console.Clear();
            byte sizeX = game.getLevelSizeX();
            byte sizeY = game.getLevelSizeY();

            Console.SetWindowSize(sizeY + 10, sizeX + 9);
            Console.SetBufferSize(sizeY + 10, sizeX + 9);
            //Console.SetWindowSize(20, 20);
            //Console.SetBufferSize(20, 20);

            for (int i = 0; i < sizeY + 4; i++)
            {
                Console.Write('*');
            }
            Console.WriteLine();
            for (int i = 0; i < sizeY + 4; i++)
            {
                if (i == 0 || i == sizeY + 3)
                {
                    Console.Write('*');
                }
                else
                {
                    Console.Write(' ');
                }
            }
            Console.WriteLine();

            for (byte i = 0; i < sizeX; i++)
            {
                for (byte j = 0; j < sizeY; j++)
                {
                    if (j == 0)
                    {
                        Console.Write("* ");
                    }

                    FloorTile tile = game.getFloorTile(i, j);

                    if (tile.Type == BackgroundType.Floor)
                    {
                        Console.BackgroundColor = ConsoleColor.DarkYellow;
                    }
                    else if (tile.Type == BackgroundType.Water)
                    {
                        Console.BackgroundColor = ConsoleColor.Blue;
                    }
                    else
                    {
                        Console.BackgroundColor = ConsoleColor.DarkRed;
                    }

                    if (tile.Type == BackgroundType.Entrance)
                    {
                        Console.Write('@');
                    }
                    else if (tile.Type == BackgroundType.Exit)
                    {
                        Console.Write('#');
                    }
                    else if (tile.Item != null)
                    {
                        if (tile.Item.Type == ItemType.Diamond)
                        {
                            Console.Write('O');
                        }
                        else if (tile.Item.Type == ItemType.Chest && !tile.Item.IsOpened.Value)
                        {
                            Console.Write('U');
                        }
                        else if (tile.Item.Type == ItemType.Chest && tile.Item.IsOpened.Value)
                        {
                            Console.Write('u');
                        }
                        else if (tile.Item.Type == ItemType.LockForGoldenKey && !tile.Item.IsOpened.Value)
                        {
                            Console.Write('G');
                        }
                        else if (tile.Item.Type == ItemType.LockForGoldenKey && tile.Item.IsOpened.Value)
                        {
                            Console.Write('g');
                        }
                        else if (tile.Item.Type == ItemType.LockForSilverKey && !tile.Item.IsOpened.Value)
                        {
                            Console.Write('S');
                        }
                        else if (tile.Item.Type == ItemType.LockForSilverKey && tile.Item.IsOpened.Value)
                        {
                            Console.Write('s');
                        }
                        else if (tile.Item.Type == ItemType.LockBlock)
                        {
                            Console.Write('=');
                        }
                    }
                    else if (game.getCharacterX() == i && game.getCharacterY() == j)
                    {
                        Console.Write('*');
                    }
                    else
                    {
                        Console.Write(' ');
                    }

                    Console.BackgroundColor = ConsoleColor.Black;

                    if (j == sizeY - 1)
                    {
                        Console.Write(" *");
                    }
                }
                Console.WriteLine();
            }

            for (int i = 0; i < sizeY + 4; i++)
            {
                if (i == 0 || i == sizeY + 3)
                {
                    Console.Write('*');
                }
                else
                {
                    Console.Write(' ');
                }
            }
            Console.WriteLine();
            Console.WriteLine("S:" + game.getHasSilverKey().ToString() + " G:" + game.getHasGoldenKey().ToString());
            Console.WriteLine("D:" + game.getCharacterDiamonds().ToString() + " N:" + game.getNumberOfNeededDiamonds().ToString());

            Console.WriteLine();
            Console.WriteLine("Move by Arrows");
            Console.WriteLine("Exit - ESC, E");
            for (int i = 0; i < sizeY + 4; i++)
            {
                Console.Write('*');
            }
            Console.SetCursorPosition(0, sizeX + 3);
        }