Exemple #1
0
        private void createComponent(char c, int x, int y)
        {                                  // digit means - it is a place for player
            if (char.IsDigit(c))
            {                              // in the map file, there can be more digits (reserved for players) but we do not use all of them
                int index = c - '0';
                if (index < ActivePlayers) // only add player if it is allowed
                {
                    players[index] = new Player(this, x, y, "Images/player" + index.ToString(), index);
                }
            }
            else
            {
                MapObject comp = null;

                switch (c)
                {
                // create stone
                case 's': comp = new Stone(this, x, y, "Images/stone2"); break;

                // '.' means free space - some barrel may be created
                case '.':
                    if (generator.Next(0, 10) < 3)
                    {
                        return;                                 // do not create barrel on each position
                    }
                    int       rnd  = generator.Next(0, 7);
                    BonusType type = BonusType.None;
                    if (rnd < 4)        // only 4 of 7 barrel have some bonus
                    {
                        type = (BonusType)rnd;
                    }
                    comp = new Barrel(this, x, y, "Images/box2", type);
                    break;
                }
                if (comp != null)   // just create an instace of this component, but do not load
                {
                    components[x, y] = comp;
                }
            }
        }
Exemple #2
0
        private void createComponent(char c, int x, int y)
        {   // digit means - it is a place for player
            if (char.IsDigit(c))
            {   // in the map file, there can be more digits (reserved for players) but we do not use all of them
                int index = c - '0';
                if (index < ActivePlayers)   // only add player if it is allowed
                    players[index] = new Player(this, x, y, "Images/player" + index.ToString(), index);
            }
            else
            {
                MapObject comp = null;

                switch (c)
                {
                    // create stone
                    case 's': comp = new Stone(this, x, y, "Images/stone2"); break;
                    // '.' means free space - some barrel may be created
                    case '.':
                        if (generator.Next(0, 10) < 3) return;  // do not create barrel on each position

                        int rnd = generator.Next(0, 7);
                        BonusType type = BonusType.None;
                        if (rnd < 4)    // only 4 of 7 barrel have some bonus
                            type = (BonusType)rnd;
                        comp = new Barrel(this, x, y, "Images/box2", type);
                        break;
                }
                if (comp != null)   // just create an instace of this component, but do not load
                    components[x, y] = comp;
            }
        }