Beispiel #1
0
 public void StartNewGame()
 {
     grid.Draw();
     snake         = new Snake("snakeEyes.bmp", grid, "snakeSkin.bmp");
     snake.Alive   = true;
     frog.Position = FindFreeCell();
 }
Beispiel #2
0
        public Form1()//constructor
        {
            InitializeComponent();

            // set the Properties of the form
            Top        = 0;
            Left       = 0;
            Height     = FORMHEIGHT;
            Width      = FORMWIDTH;
            KeyPreview = true;

            gameRun = true;
            random  = new Random();
            grid    = new Grid(Properties.Resources.blank);
            Controls.Add(grid); // important, need to add the grid object to the list of controls on the form
            grid.Draw();

            gameManager = new GameManager(grid, random);
            gameManager.StartNewGame();
            timer1.Enabled = true;
        }
Beispiel #3
0
        public ErrorMessage PlayGame()//the actual gameplay of the game, the action that occur at each timer tick
        {
            grid.Draw();
            snake.Draw();

            if (frog.Alive == false)
            {
                frog.Position = FindFreeCell();
                frog.Alive    = true;
            }

            frog.Draw();
            snake.Move();

            ErrorMessage message = ErrorMessage.noError;

            if (snake.CheckWall() == true)
            {
                message    = ErrorMessage.snakeHitWall;
                frog.Alive = false;
            }

            if (snake.CheckSelf() == true)
            {
                message    = ErrorMessage.snakeHitSelf;
                frog.Alive = false;
            }

            if (snake.EatFrog(frog.Position) == true)
            {
                frog.Alive = false;
                snake.Grow();
                message = ErrorMessage.snakeEatenFrog;
            }

            return(message);
        }