public GhostInventory(Image Slot, Image Selected, Image emptyIcon, Text Number) : base(Slot, Selected, emptyIcon, Number)
 {
     for (int i = 0; i < 10; i++)
     {
         Traps.Add(null);
     }
 }
Esempio n. 2
0
 public void AddTrap(uint instanceId, TrapStack trap)
 {
     lock (TrapLock)
     {
         Traps.Add(instanceId, trap);
     }
 }
Esempio n. 3
0
        // Loading a level and setting the obstacles, blocks and enemies that
        // contains in the correct position.
        public void LoadLevel(string levelFile)
        {
            if (!File.Exists(levelFile))
            {
                Console.WriteLine("This level doesn't exist, so it couldn't" +
                                  "be loaded...");
            }
            else
            {
                try
                {
                    StreamReader fileReader = File.OpenText(levelFile);
                    string       line;
                    int          numHeight = 0;
                    int          numWidth  = 0;
                    do
                    {
                        line = fileReader.ReadLine();
                        if (line != null)
                        {
                            numWidth = 0;
                            string[] elements = line.Split(',');
                            for (int i = 0; i < elements.Length; i++)
                            {
                                if (elements[i] == "B")
                                {
                                    Blocks.Add(
                                        new Block(i * Block.SPRITE_WIDTH,
                                                  numHeight * Block.SPRITE_HEIGHT, 0));
                                }
                                else if (elements[i] == "S")
                                {
                                    XStart = (short)(i * Block.SPRITE_WIDTH);
                                    YStart = (short)(numHeight *
                                                     Block.SPRITE_HEIGHT);
                                }
                                else if (elements[i] == "E")
                                {
                                    XEnd = (short)(i * Block.SPRITE_WIDTH);
                                    YEnd = (short)(numHeight *
                                                   Block.SPRITE_HEIGHT);
                                }
                                else if (elements[i] == "T")
                                {
                                    Traps.Add(new Trap(i * Block.SPRITE_WIDTH,
                                                       numHeight * Block.SPRITE_HEIGHT, 's'));
                                }
                                else if (elements[i] == "Q")
                                {
                                    Traps.Add(new Trap(i * Block.SPRITE_WIDTH,
                                                       numHeight * Block.SPRITE_HEIGHT, 'l'));
                                }
                                else if (elements[i] == "W")
                                {
                                    Traps.Add(new Trap(i * Block.SPRITE_WIDTH,
                                                       numHeight * Block.SPRITE_HEIGHT, 'w'));
                                }
                                else if (elements[i] == "Y")
                                {
                                    Traps.Add(new Trap(i * Block.SPRITE_WIDTH,
                                                       numHeight * Block.SPRITE_HEIGHT, 'y'));
                                }
                                else if (elements[i] == "X")
                                {
                                    // Setting the origin view of the map
                                    XMap = (short)(i * Block.SPRITE_WIDTH);
                                    YMap = (short)(numHeight *
                                                   Block.SPRITE_HEIGHT);
                                    Blocks.Add(
                                        new Block(i * Block.SPRITE_WIDTH,
                                                  numHeight * Block.SPRITE_HEIGHT, 0));
                                }
                                else if (elements[i] == "C")
                                {
                                    Collectibles.Add(
                                        new Collectible(i * Block.SPRITE_WIDTH,
                                                        numHeight * Block.SPRITE_HEIGHT));
                                }
                                else if (elements[i] == "F")
                                {
                                    Enemies.Add(new GroundEnemy(
                                                    (short)(i * Enemy.SPRITE_WIDTH),
                                                    (short)(numHeight *
                                                            Block.SPRITE_HEIGHT)));
                                }
                                else if (elements[i] == "V")
                                {
                                    Enemies.Add(new FlyingEnemy(
                                                    (short)(i * Enemy.SPRITE_WIDTH),
                                                    (short)(numHeight *
                                                            Block.SPRITE_HEIGHT)));
                                }
                                numWidth++;
                            }
                            numHeight++;
                        }
                    } while (line != null);

                    Width  = (short)(numWidth * Block.SPRITE_WIDTH);
                    Height = (short)(numHeight * Block.SPRITE_HEIGHT);

                    fileReader.Close();
                }
                catch (FileNotFoundException)
                {
                    Console.WriteLine("File of the level not found.");
                }
                catch (PathTooLongException)
                {
                    Console.WriteLine("The path to search this level is too" +
                                      " long...");
                }
                catch (IOException e)
                {
                    Console.WriteLine("IO error... --> " + e.Message);
                }
                catch (Exception e)
                {
                    // A log file will be used in the end
                    Console.WriteLine("My bad! An error ocurred --> " +
                                      e.Message);
                }
            }
        }