예제 #1
0
        //##########################################################################################
        //Private Methods.

        /// <summary>
        /// Loads the form.
        /// </summary>
        private void LoadForm()
        {
            catDirectionCounter_ = 20;
            secondCounter_       = 0;
            displayCounter_      = 60;

            safetyZoneList_ = new List <StationaryObject>();
            wallList_       = new List <Wall>();
            cheeseList_     = new List <Cheese>();

            catBowl_  = new CatBowl(screenWidth_ / 5, screenHeight_ / 10);
            mouseDen_ = new MouseDen(screenWidth_ - WALL_THICKNESS, 3 * screenHeight_ / 4);
            cat_.ResetCat(screenWidth_, screenHeight_);
            mouse_.ResetMouse(screenWidth_, screenHeight_);

            //ADD objects to the lists
            safetyZoneList_.Add(mouseDen_);
            safetyZoneList_.Add(new HidingPlace(4 * screenWidth_ / 10, 0));
            safetyZoneList_.Add(new HidingPlace(7 * screenWidth_ / 10, 0));
            safetyZoneList_.Add(new HidingPlace(screenWidth_ - WALL_THICKNESS, WALL_THICKNESS + screenHeight_ / 3));
            safetyZoneList_.Add(new HidingPlace(screenWidth_ - screenWidth_ / 2, screenHeight_ - WALL_THICKNESS));
            safetyZoneList_.Add(new HidingPlace(0, screenWidth_ / 4));
            safetyZoneList_.Add(new HidingPlace(0, screenWidth_ / 2));
            safetyZoneList_.Add(new HidingPlace(screenWidth_ / 5, screenHeight_ - WALL_THICKNESS));
            mouse_.GetList(safetyZoneList_);

            wallList_.Add(new Wall(0, 0, screenWidth_, WALL_THICKNESS));
            wallList_.Add(new Wall(0, screenHeight_ - WALL_THICKNESS, screenWidth_, WALL_THICKNESS));
            wallList_.Add(new Wall(0, 0, WALL_THICKNESS, screenHeight_ - WALL_THICKNESS));
            wallList_.Add(new Wall(screenWidth_ - WALL_THICKNESS, 0, WALL_THICKNESS, 3 * screenHeight_ / 4));
            wallList_.Add(new Wall(screenWidth_ - WALL_THICKNESS, 3 * screenHeight_ / 4 + 60, WALL_THICKNESS,
                                   screenHeight_ - 3 * screenHeight_ / 4 + 60));

            /*ADD pieces of cheese to the cheese list with coordinates that
             * are not within in the boundaries of the mouse den*/
            while (cheeseList_.Count < 6)
            {
                int       cheeseX      = random.Next(40, screenWidth_ - 80);
                int       cheeseY      = random.Next(40, screenHeight_ - 75);
                Rectangle cheeseBounds = new Rectangle(cheeseX, cheeseY, 200, 200);
                if (!mouseDen_.GeneralLocation.IntersectsWith(cheeseBounds))
                {
                    cheeseList_.Add(new Cheese(cheeseX, cheeseY));
                }
            }

            /*Set the number of pieces of cheese to collect to the number of
             * pieces which has been displayed*/
            cheesePiecesToCollect_ = cheeseList_.Count;
            //Set booleans to false so the mouse doesn't move
            isUpPressed_    = false;
            isDownPressed_  = false;
            isLeftPressed_  = false;
            isRightPressed_ = false;
            //Start the timer tick event method
            gameTimer_.Start();
        }
예제 #2
0
        private void GameOver(string result)
        {
            gameTimer_.Enabled = false;
            string status = "";
            string points = " points!";

            if (result == "Win!")
            {
                level_++;
                catRunningSpeed_++;
                if (level_ == 6)
                {
                    status = "      You're amazing!";
                }
                else if (level_ == 11)
                {
                    status = "      You're a star!";
                }
                else if (level_ == 16)
                {
                    status = "      You're a legend!!";
                }
                MessageBox.Show("You " + result + "     Current points = " + playerScore_ + status);
            }
            else
            {
                MessageBox.Show("You " + result + "     Total score:  " + playerScore_.ToString() + points);
                saveHighScore(playerScore);
                catRunningSpeed_ = 5;
                playerScore_     = 0;
                level_           = 1;
            }

            /*Refresh the picture box and reset all lists and objects to
             * their original empty or null state and load the form*/
            pictureBoxDisplay.Refresh();
            cheeseList_.Clear();
            mouseDen_ = null;
            catBowl_  = null;
            LoadForm();
        }