Exemplo n.º 1
0
        //Place random food object
        private void GenerateFood()
        {
            int maxXPos = pbCanvas.Size.Width / Settings.Width;
            int maxYPos = pbCanvas.Size.Height / Settings.Height;

            Random random = new Random();
            food = new Circle { x = random.Next(0, maxXPos), y = random.Next(0, maxYPos) };
        }
Exemplo n.º 2
0
        private void GenerateFood()
        {
            int maxXPosition = this.pbCanvas.Size.Width / Settings.Width;
            int maxYposition = this.pbCanvas.Size.Height / Settings.Height;

            Random random = new Random();
            int x = random.Next(0, maxXPosition);
            int y = random.Next(0, maxYposition);
            this.food = new Circle(x, y);
        }
Exemplo n.º 3
0
        //Place food randomly on canvas
        private void GenerateFood()
        {
            int maxXPos = canvas.Size.Width / Settings.Width;
            int maxYPos = canvas.Size.Height / Settings.Height;

            Random random = new Random();
            food = new Circle();
            food.X = random.Next(0, maxXPos);
            food.Y = random.Next(0, maxYPos);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Special constructor
        /// </summary>
        /// <param name="a"></param>
        /// <param name="d"></param>
        public SplashScreen()
        {
            InitializeComponent();

            new Settings();
            Settings.direction = Direction.Right;
            //Set game speed and start timer
            gameTimer.Interval = 2000 / Settings.Speed;
            gameTimer.Tick += UpdateScreen;

            snake.Clear();
            Circle head = new Circle { X = 5, Y = ((pbCanvas.Height / Settings.Width) / 2) };
            snake.Add(head);

            Circle circle = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle);
            Circle circle2 = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle2);
            Circle circle3 = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle3);
            Circle circle4 = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle4);
            Circle circle5 = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle5);
            Circle circle6 = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle6);

            gameTimer.Start();
        }
Exemplo n.º 5
0
        private void Eat()
        {
            int x = this.snake[this.snake.Count - 1].X;
            int y = this.snake[this.snake.Count - 1].Y;
            Circle eatedFood = new Circle(x, y);

            this.snake.Add(eatedFood);

            Settings.Score += Settings.Points;
            this.lblScore.Text = Settings.Score.ToString();

            this.GenerateFood();
        }
Exemplo n.º 6
0
        private void Eat()
        {
            //add circle to body
            Circle food = new Circle();
            food.x = snake[snake.Count - 1].x;
            food.y = snake[snake.Count - 1].y;

            snake.Add(food);

            //update score
            Settings.Score += Settings.Points;
            labelScore.Text = Settings.Score.ToString();

            GenerateFood();
        }
Exemplo n.º 7
0
        private void Eat()
        {
            //Add circle to body
            Circle circle = new Circle
            {
                x = Snake[Snake.Count - 1].x,
                y = Snake[Snake.Count - 1].y
            };
            Snake.Add(circle);

            //Update score
            Settings.Score += Settings.Points;
            labelScore.Text = Settings.Score.ToString();

            GenerateFood();
        }
Exemplo n.º 8
0
        private void StartGame()
        {
            gameoverLabel.Visible = false;

            //Set settings to default
            new Settings();
            Snake.Clear();

            //Create new player object
            Circle head = new Circle();
            head.X = 25;
            head.Y = 20;
            Snake.Add(head);

            scoreLabel.Text = Settings.Score.ToString();
            GenerateFood();
        }
Exemplo n.º 9
0
        private void StartGame()
        {
            lblGameOver.Visible = false;

            //Set settings to default
            new Settings();

            //Create new player object
            Snake.Clear();
            Circle head = new Circle {X = 10, Y = 5};
            Snake.Add(head);


            lblScore.Text = Settings.Score.ToString();
            GenerateFood();

        }
Exemplo n.º 10
0
        private void Eat()
        {
            Circle food = new Circle();
            food.X = Snake[Snake.Count - 1].X;
            food.Y = Snake[Snake.Count - 1].Y;

            Snake.Add(food);

            //Update score
            Settings.Score += Settings.Points;
            scoreLabel.Text = Settings.Score.ToString();

            GenerateFood();
        }
Exemplo n.º 11
0
        private void GenerateFood()
        {
            int maxXPos = pbCanvas.Size.Width / Settings.Width;
            int maxYPos = pbCanvas.Size.Height / Settings.Height;

            int x = random.Next(0, maxXPos);
            int y = random.Next(0, maxYPos);

            int i = 0;

            while (i < snake.Count) {
                if ((snake[i].X == x) && (snake[i].Y == y)) {
                    x = random.Next(0, maxXPos);
                    y = random.Next(0, maxYPos);
                    i = 0;
                }
                else {
                    i++;
                }
            }

            food = new Circle(x, y);
        }
Exemplo n.º 12
0
 public void TestSuperFruit()
 {
     Circle sfood = new Circle { X = 50, Y = 50 };
     GameForm myform = new GameForm(false, false, 2);
     myform.GenerateSuperFood(sfood);
     Assert.AreEqual(myform.superFood.X, sfood.X);
     Assert.AreEqual(myform.superFood.Y, sfood.Y);
 }
Exemplo n.º 13
0
Arquivo: Form1.cs Projeto: ybaa/Snake
        private void GenerateFood()
        {
            Random random = new Random();
            Food = new Circle();

            //set max position of food
            int maxXPosition = mainAreaPb.Size.Width / Settings.Width;
            int maxYPosition = mainAreaPb.Size.Height / Settings.Heigth;

            Food.X = random.Next(0, maxXPosition);
            Food.Y = random.Next(0, maxYPosition);
        }
Exemplo n.º 14
0
        private void Eat()
        {
            Game.FoodRemaining--;

            //Add food to body
            Circle food = new Circle(0, 0);

            food.X = Game.Snake[Game.Snake.Count - 1].X;
            food.Y = Game.Snake[Game.Snake.Count - 1].Y;
            Game.Snake.Add(food);

            Random rnd = new Random();

            poz = rnd.Next(0, 3);
            //Update Score
            Settings.Score += Settings.Points;
            Score_lbl.Text  = Settings.Score.ToString();

            food.X = -1;
            food.Y = -1;

            if (MenuForm.RelaxMode == false)
            {
                if (Settings.Score == 700)
                {
                    Level1();
                    NewSnake();
                }

                if (Settings.Score == 1400)
                {
                    Level2();
                    NewSnake();
                }

                if (Settings.Score == 2100)
                {
                    Level3();
                    NewSnake();
                }

                if (Settings.Score == 2900)
                {
                    Level4();
                    NewSnake();
                }

                if (Settings.Score == 3700)
                {
                    Level5();
                    NewSnake();
                }

                if (Settings.Score == 4600)
                {
                    Level6();
                    NewSnake();
                }

                if (Settings.Score == 5600)
                {
                    Level7();
                    NewSnake();
                }
                if (Settings.Score == 6600)
                {
                    Settings.Win = true;
                }
            }
            Game.GenerateFood(pbCanvas.Size.Width, pbCanvas.Size.Height);
        }
Exemplo n.º 15
0
        private void StartGame()
        {
            var settings = new Settings();
            this.lblGameOver.Visible = false;

            this.snake.Clear();

            Circle head = new Circle(10, 5);
            this.snake.Add(head);

            this.lblScore.Text = Settings.Score.ToString();

            this.GenerateFood();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Starts the game with special settings
        /// </summary>
        /// <param name="a"></param>
        /// <param name="d"></param>
        public void StartGame(bool a, bool c ,int d)
        {
            new Settings(a, c ,d);

            lblGameMessage.Visible = false;

            //Create new player object
            snake.Clear();
            Circle head = new Circle { X = 10, Y = 5 };
            snake.Add(head);

            toolStripStatusLabel1.Text = "Score: " + Settings.Score.ToString();
            gameTimer.Start();
            superfoodTimer.Start();
            GenerateFood();

            if (c)
            {
                Music = new SoundPlayer(@"../../Resources/JohnCena.wav");
                Music.PlayLooping();
            }
            else
                Music = new SoundPlayer(@"../../Resources/GetLucky2.wav");
                Music.PlayLooping();
        }
Exemplo n.º 17
0
        //Methods for tests
        public void GenerateSuperFood(Circle sfood)
        {
            int maxXPos = pbCanvas.Size.Width / Settings.Width;
            int maxYPos = pbCanvas.Size.Height / Settings.Height;

            Random random = new Random();
            superFood = new Circle { X = sfood.X, Y = sfood.Y };
            eaten = false;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Generates super food
        /// </summary>
        public void GenerateSuperFood()
        {
            int maxXPos = pbCanvas.Size.Width / Settings.Width;
            int maxYPos = pbCanvas.Size.Height / Settings.Height;

            Random random = new Random();
            superFood = new Circle { X = random.Next(0, maxXPos), Y = random.Next(0, maxYPos) };
            eaten = false;
        }
Exemplo n.º 19
0
        /// <summary>
        /// What happens when a special food is eaten
        /// </summary>
        public void EatSpec()
        {
            //Add circle to body
            eaten = true;

            Circle circle = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle);
            Circle circle2 = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle2);
            Circle circle3 = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle3);

            //Update Score
            Settings.Score += 40;
            toolStripStatusLabel1.Text = "Score: " + Settings.Score.ToString();

            Random rng = new Random();
            superfoodTimer.Interval = rng.Next(2000, 3000);
        }
Exemplo n.º 20
0
        /// <summary>
        /// What happends when the snake eats a food
        /// </summary>
        public void Eat()
        {
            //Add circle to body
            Circle circle = new Circle
            {
                X = snake[snake.Count - 1].X,
                Y = snake[snake.Count - 1].Y
            };
            snake.Add(circle);

            //Update Score
            Settings.Score += Settings.Points;
            toolStripStatusLabel1.Text = "Score: " + Settings.Score.ToString();

            GenerateFood();
        }
Exemplo n.º 21
0
        private void StartGame()
        {
            new Settings();
            lblGameOver.Visible = false;
            lblScore.Text = Settings.Score.ToString();

            gameTimer.Interval = 1000 / Settings.Speed;
            gameTimer.Start();

            snake.Clear();

            //create a new game
            int maxXPos = pbCanvas.Size.Width / Settings.Width;
            int maxYPos = pbCanvas.Size.Height / Settings.Height;

            Circle head = new Circle(random.Next(0, maxXPos), random.Next(0, maxYPos));
            snake.Add(head);

            GenerateFood();
        }
Exemplo n.º 22
0
Arquivo: Form1.cs Projeto: ybaa/Snake
        private void StartGame()
        {
            gameOverLabel.Visible = false;
            Settings.Score = 0;
            DifficultyCounter = 1;
            gameTimer.Interval = 100;

            //set default settings
            new Settings();

            //create new snake and food
            Snake.Clear();
            Circle head = new Circle();
            head.X = 10;
            head.Y = 5;
            Snake.Add(head);

            //set score label
            pointsLabel.Text = Settings.Score.ToString();

            GenerateFood();

        }
Exemplo n.º 23
0
        private void StartGame()
        {
            //set game speed and start timer
            gameTimer.Interval = 1000 / Settings.Speed;
            gameTimer.Tick += UpdateScreen;
            gameTimer.Start();

            lblGameOver.Visible = false;

            new Settings();

            //create new Player object
            Snake.Clear();

            int maxXPos = pbCanvas.Size.Width / Settings.Width;
            int maxYPos = pbCanvas.Size.Height / Settings.Height;

            Random random = new Random();

            Circle head = new Circle(random.Next(0, maxXPos), random.Next(0, maxYPos));
            Snake.Add(head);

            lblScore.Text = Settings.Score.ToString();

            //Place random food
            food = new Circle(random.Next(0, maxXPos), random.Next(0, maxYPos));
        }
Exemplo n.º 24
0
Arquivo: Form1.cs Projeto: ybaa/Snake
        private void Eat()
        {
            Circle food = new Circle();
            food.X = Snake[Snake.Count - 1].X;
            food.Y = Snake[Snake.Count - 1].Y;
            Snake.Add(food);

            GenerateFood();

            Settings.Score += Settings.Points;
            pointsLabel.Text = Settings.Score.ToString();

            //making the game more difficult
            DifficultyCounter++;
            if (DifficultyCounter % 7 == 0)
            { 
               // Settings.Speed += 1;
                gameTimer.Interval -= 10;
            
            }
              
        }
Exemplo n.º 25
0
        private void Eat()
        {
            //Add circle to body
            Circle circle = new Circle
            {
                X = Snake[Snake.Count - 1].X,
                Y = Snake[Snake.Count - 1].Y
            };
            Snake.Add(circle);

            //Update Score
            Settings.Score += Settings.Points;
            lblScore.Text = Settings.Score.ToString();

            GenerateFood();
        }
Exemplo n.º 26
0
        public void TestSuperFruitEat()
        {
            Circle sfood = new Circle { X = 50, Y = 50 };
            GameForm myform = new GameForm(false, false, 2);

            Assert.AreEqual(1, myform.snake.Count);
            myform.EatSpec();
            Assert.AreEqual(4, myform.snake.Count);
        }
Exemplo n.º 27
0
        private void StartGame()
        {
            lbGameOver.Visible = false;

            //reset everything everytime a new game starts
            new Settings();

            //start with 1 circle
            snake.Clear();
            Circle head = new Circle { x = 10, y = 5 };
            snake.Add(head);

            labelScore.Text = Settings.Score.ToString();
            GenerateFood();
        }