Ejemplo n.º 1
0
        /// <summary>
        /// Game start function
        /// </summary>
        private void startGame()
        {
            if (aisquares == null)
            {
                numberOfOpponents = 50;
                directions        = new int[numberOfOpponents];       //Make and fill array of random direction modifiers to apply to targets
                aisquares         = new Rectangle[numberOfOpponents]; //Make and fill array of target squares
            }

            xloc = 0;
            yloc = 0;

            //Fill array of target squares
            for (int i = 0; i < aisquares.Length; i++)
            {
                bool good = false;
                if (i < 24)
                {
                    good = true;
                }
                TargetSquare aitoadd    = new TargetSquare(globalSeed, good); //Create new target object
                Rectangle    fromtarget = aitoadd.makeTheShape();             //Get reutrned rectangle from target
                aisquares[i] = fromtarget;                                    //Add the target to the traget array
                mainGrid.Children.Add(aisquares[i]);                          //Add the target to the grid
                aisquares[i].Visibility = Visibility.Collapsed;
                directions[i]           = globalSeed.Next(0, 8);              //Add random direction modifier to square using global seed
            }

            //hide menu and display the game
            rectPlayer.Margin = new Thickness(xloc, yloc, 0, 0);
            lblScore.Margin   = new Thickness(xloc, yloc, 0, 0);

            MainMenu.Visibility   = Visibility.Collapsed;
            rectPlayer.Visibility = Visibility.Visible;
            lblScore.Visibility   = Visibility.Visible;
            playerScore           = 0;
            playerSize            = 20;
            speed = 2;
            lose  = false;
            //Show the targets
            for (int i = 0; i < aisquares.Length; i++)
            {
                aisquares[i].Visibility = Visibility.Visible;
            }


            aiClock.Enabled        = true; //start AI movement
            collisionTimer.Enabled = true; //start collision detection
        }