private void UpdateScreen(object sender, EventArgs e) //Will run every tick { //Check for game over if (settings.GetGameOver() == true) { if ((SnakeInput.KeyPress(Keys.Enter))) { StartGame(); } } else { //Game is not over, check for inputs if ((SnakeInput.KeyPress(Keys.Right) || SnakeInput.KeyPress(Keys.D)) && settings.GetDirection() != "Left") //Checking for either right arrow key or d and that the snake is not pointed left { settings.SetDirection("Right"); } else if ((SnakeInput.KeyPress(Keys.Left) || SnakeInput.KeyPress(Keys.A)) && settings.GetDirection() != "Right") { settings.SetDirection("Left"); } else if ((SnakeInput.KeyPress(Keys.Down) || SnakeInput.KeyPress(Keys.S)) && settings.GetDirection() != "Up") { settings.SetDirection("Down"); } else if ((SnakeInput.KeyPress(Keys.Up) || SnakeInput.KeyPress(Keys.W)) && settings.GetDirection() != "Down") { settings.SetDirection("Up"); } MoveSnake(); } GameWindow.Invalidate(); //Redraws screen every tick to simulate movement }
private void keyisup(object sender, KeyEventArgs e) { SnakeInput.changeState(e.KeyCode, false); }
private void keyisdown(object sender, KeyEventArgs e) { SnakeInput.changeState(e.KeyCode, true); }