public void ResetGame() { Player1 = new SnakePlayer(this); FoodMngr = new FoodManager(GameCanvas.Width, GameCanvas.Height); FoodMngr.AddRandomFood(10); score = 0; }
private bool CheckForFoodCollision(SnakePlayer snakeX) { bool hitFood = false; List <Rectangle> SnakeRects = snakeX.GetRects(); foreach (Rectangle rect in SnakeRects) { if (FoodMngr.IsIntersectingRect(rect, true)) { FoodMngr.AddRandomFood(); snakeX.AddBodySegments(1); snakeX.UpdateScore(1); hitFood = true; } } return(hitFood); }
public void ResetGame() { FoodMngr = new FoodManager(GameCanvas.Width, GameCanvas.Height); FoodMngr.AddRandomFood(); Player1 = new SnakePlayer(GameCanvas.Size, FoodMngr); score = 0; Input.Clear(); }
public Snake() { InitializeComponent(); Application.AddMessageFilter(this); Player1 = new SnakePlayer(this); FoodMngr = new FoodManager(GameCanvas.Width, GameCanvas.Height); FoodMngr.AddRandomFood(10); ScoreTxtBox.Text = score.ToString(); }
private void CheckForCollisions() { if (Player1.IsIntersectingRect(new Rectangle(-100, 0, 100, GameCanvas.Height))) { Player1.OnHitWall(Direction.left); } if (Player1.IsIntersectingRect(new Rectangle(0, -100, GameCanvas.Width, 100))) { Player1.OnHitWall(Direction.up); } if (Player1.IsIntersectingRect(new Rectangle(GameCanvas.Width, 0, 100, GameCanvas.Height))) { Player1.OnHitWall(Direction.right); } if (Player1.IsIntersectingRect(new Rectangle(0, GameCanvas.Height, GameCanvas.Width, 100))) { Player1.OnHitWall(Direction.down); } //Is hitting food List <Rectangle> SnakeRects = Player1.GetRects(); foreach (Rectangle rect in SnakeRects) { if (FoodMngr.IsIntersectingRect(rect, true)) { FoodMngr.AddRandomFood(); Player1.AddBodySegments(1); score++; ScoreTxtBox.Text = score.ToString(); } if (FoodMngr.IsIntersectingRectWithRed(rect, true)) { FoodMngr.AddRandomFoodRed(); Player1.AddBodySegments(1); score += 2; ScoreTxtBox.Text = score.ToString(); } } }
public SnakeForm() { InitializeComponent(); Application.AddMessageFilter(this); this.FormClosed += (s, e) => Application.RemoveMessageFilter(this); Player1 = new SnakePlayer(this); FoodMngr = new FoodManager(GameCanvas.Width, GameCanvas.Height); FoodMngr.AddRandomFood(10); scoreText.Text = score.ToString(); }
public void ResetGame() { homeForm.Show(); homeForm.GameOver(); player = new SnakePlayer(this); foodManager = new FoodManager(GameCanvas.Width, GameCanvas.Height); foodManager.AddRandomFood(10); score = 0; }
public Snake() { InitializeComponent(); Application.AddMessageFilter(this); player = new SnakePlayer(this); foodManager = new FoodManager(GameCanvas.Width, GameCanvas.Height); foodManager.AddRandomFood(10); ScoreTxtBox.Text = score.ToString(); DifficultyChanged += SetTimer; }
public void ResetGame() { gameHasEnded = false; gameInAction = true; ToggleGame(); SnakeSetup(); FoodMngr = new FoodManager(GameCanvas.Width, GameCanvas.Height); FoodMngr.AddRandomFood(10); DisplaySetup(); GameTimer.Enabled = true; }
private void CheckForCollisions() { if (player.IsIntersectingRect(new Rectangle(-100, 0, 100, GameCanvas.Height))) { player.OnHitWall(Direction.Left); } if (player.IsIntersectingRect(new Rectangle(0, -100, GameCanvas.Width, 100))) { player.OnHitWall(Direction.Up); } if (player.IsIntersectingRect(new Rectangle(GameCanvas.Width, 0, 100, GameCanvas.Height))) { player.OnHitWall(Direction.Right); } if (player.IsIntersectingRect(new Rectangle(0, GameCanvas.Height, GameCanvas.Width, 100))) { player.OnHitWall(Direction.Down); } //Is hitting food List <Rectangle> SnakeRects = player.GetRects(); foreach (Rectangle rect in SnakeRects) { if (foodManager.IsIntersectingRect(rect, true)) { foodManager.AddRandomFood(); player.AddBodySegments(1); score += GetScore(); ScoreTxtBox.Text = score.ToString(); } } }
public void ResetGame() { String name, display; if (score != 0) { GameTimer.Enabled = false; display = "Score : " + score.ToString(); name = Interaction.InputBox(display, "High Scores", "Name", -1, -1); String line = name + " " + score.ToString() + Environment.NewLine; System.IO.File.AppendAllText(@"C:\Project\Snake\Score.txt", line); GameTimer.Enabled = true; } Player1 = new SnakePlayer(this); FoodMngr = new FoodManager(GameCanvas.Width, GameCanvas.Height); FoodMngr.AddRandomFood(10); score = 0; }
public SnakeForm() { InitializeComponent(); Application.AddMessageFilter(this); this.FormClosed += (s, e) => Application.RemoveMessageFilter(this); Player1 = new SnakePlayer(this); FoodMngr = new FoodManager(GameCanvas.Width, GameCanvas.Height); FoodMngr.AddRandomFood(10); ScoreTxtBox.Text = score.ToString(); try { ArduinoInput = new ArduinoInput("COM5"); ArduinoInput.SerialPort.DataReceived += ProcessArduinoInput; } catch (Exception) { } }
private void CheckForCollisions() { if (Player1.IsSelfIntersecting()) // Check for collisions with itself { SetGameOver("Hit itself"); // If so, trigger the game-over screen } if (Player1.IsIntersectingRect(new Rectangle(-100, 0, 100, GameCanvas.Height))) { SetGameOver("Hit left wall"); } if (Player1.IsIntersectingRect(new Rectangle(0, -100, GameCanvas.Width, 100))) { SetGameOver("Hit top wall"); } if (Player1.IsIntersectingRect(new Rectangle(GameCanvas.Width, 0, 100, GameCanvas.Height))) { SetGameOver("Hit right wall"); } if (Player1.IsIntersectingRect(new Rectangle(0, GameCanvas.Height, GameCanvas.Width, 100))) { SetGameOver("Hit bottom wall"); } // Is hitting food var snakeRects = Player1.GetRects(); foreach (var rect in snakeRects) { if (FoodMngr.IsIntersectingRect(rect, true)) { FoodMngr.AddRandomFood(); Player1.AddBodySegments(1); Player1.AddScore(); score++; ScoreTxtBox.Text = score.ToString(); } } }
public SnakeForm(Startscreen menu, bool twoPlayer) { InitializeComponent(); //xxx PauseTimer = new Timer(); PauseTimer.Tick += PauseTimer_Tick; PauseTimer.Start(); GameTimer = new Timer(); GameTimer.Tick += GameTimer_Tick; Application.AddMessageFilter(this); this.FormClosed += (s, e) => Application.RemoveMessageFilter(this); //set link to form's parent mainmenu = menu; //update the game's player state is2Player = twoPlayer; //set the name of the current Game window this.Text = "Welcome to Snake: " + (is2Player?"Two":"Single") + " Player Mode"; //set the brush visuals BuildBrush(); //Build Players and update the visuals SnakeSetup(); DisplaySetup(); //Food initialization and execution FoodMngr = new FoodManager(GameCanvas.Width, GameCanvas.Height); FoodMngr.AddRandomFood(10); //apply exit message this.FormClosing += SnakeForm1_FormClosing; //initial start CheckForCollisions(); //GameTimer.Enabled = true; }