Esempio n. 1
0
        void StartButtonClick(object sender, EventArgs e)
        {
            // Get numberOfBaddies from RadioBox in baddieSelectorPanel
            if (baddieSelectorButton1.Checked) numberOfBaddies = 1;
            else if (baddieSelectorButton2.Checked) numberOfBaddies = 2;
            else if (baddieSelectorButton3.Checked) numberOfBaddies = 3;
            else if (baddieSelectorButton4.Checked) numberOfBaddies = 4;
            else if (baddieSelectorButton5.Checked) numberOfBaddies = 5;
            else if (baddieSelectorButton6.Checked) numberOfBaddies = 6;

            baddies = new List<Character>(numberOfBaddies);

            // Get numberOfHeroes from RadioBox in heroSelectorPanel
            if (heroSelectorButton1.Checked) numberOfHeroes = 1;
            else if (heroSelectorButton2.Checked) numberOfHeroes = 2;
            else if (heroSelectorButton3.Checked) numberOfHeroes = 3;
            else if (heroSelectorButton4.Checked) numberOfHeroes = 4;

            heroes = new List<Character>(numberOfHeroes);

            // Get room parameters from RadioBox in roomSelectorPanel - also select correct background image
            if (roomSelectorButton1.Checked){
                roomSquaresX = 3;
                roomSquaresY = 5;
                this.pictureBox1.BackgroundImage = global::MoveAndFight.Images.room3x5;
            } else if (roomSelectorButton2.Checked){
                roomSquaresX = 4;
                roomSquaresY = 4;
                this.pictureBox1.BackgroundImage = global::MoveAndFight.Images.room4x4;
            } else if (roomSelectorButton3.Checked){
                roomSquaresX = 5;
                roomSquaresY = 5;
                this.pictureBox1.BackgroundImage = global::MoveAndFight.Images.room5x5;
            }

            room = new Room(roomSquaresX, roomSquaresY);

            // Randomly select hero start point(s), ensuring there are no conflicts with other heroes (N.B. no baddies exist at this point)
            for (int i = 0; i < numberOfHeroes; i++)
            {
                Point bufferLocation = RandomLocation();
                Boolean pointAvailable = true;

                // Check other Hero locations and reassign bufferLocation until it is an available location
                    do{
                        // Assume location is initially free
                        pointAvailable = true;
                        foreach (Character hero in heroes)
                        {
                            if (bufferLocation == hero.location)
                            {
                                // If location not free, choose another and check everybody again
                                bufferLocation = RandomLocation();
                                pointAvailable = false;
                                break;
                            }
                        }
                    } while (!pointAvailable);

                // bufferLocation is available, so assign it to new Hero
                heroes.Add(new Hero (bufferLocation, (Direction) random.Next(4), i+1));
            }

            // Randomly select baddie start point(s), ensuring there are no conflicts with heroes or other baddies
            AssignBaddieLocations();

            // Assign active hero (green/1)
            activeHero = (Hero) heroes[0];

            gameClock.Start();
            gameClock.Tick += new EventHandler(GameTimeUp);
            ResetGame();
        }
Esempio n. 2
0
 void ActivateHeroButton4Click(object sender, EventArgs e)
 {
     leftTurnButton.Image = global::MoveAndFight.Images.arrow_leftturn_4;
     rightTurnButton.Image = global::MoveAndFight.Images.arrow_rightturn_4;
     forwardButton.Image = global::MoveAndFight.Images.arrow_north_4;
     activeHero = (Hero) heroes[3];
 }