Example #1
0
        public ErrorMessage PlayGame()
        {
            ErrorMessage message = ErrorMessage.noError;

            if (!frog.Alive)
            {
                frog.Position = FindFreeCell();
                frog.Alive    = true;
            }
            grid.Draw();
            if (snake.Alive)
            {
                snake.Draw();
                snake.Move();
            }
            if (frog.Alive)
            {
                frog.Draw();
            }
            if (frog.Position.X == snake.Position[1].X && frog.Position.Y == snake.Position[1].Y)               //          Snake eat frog
            {
                message    = ErrorMessage.snakeEatenFrog;
                frog.Alive = false;
                points++;
                snake.Position.Add(frog.Position);
            }
            for (int i = 1; i < snake.Position.Count; i++)                                                  //      Snake Hit Self
            {
                if (snake.Position[0].X == snake.Position[i].X && snake.Position[0].Y == snake.Position[i].Y)
                {
                    snake.Alive = false;
                    message     = ErrorMessage.snakeHitSelf;
                }
            }
            if (snake.Position[0].X >= 30 || snake.Position[0].X < 0 || snake.Position[0].Y >= 30 || snake.Position[0].Y < 0)           //  Snake hit wall
            {
                message     = ErrorMessage.snakeHitWall;
                snake.Alive = false;
            }

            return(message);
        }
Example #2
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);
        }