public void Tick() { //move the player drawArea.DrawSquare(player.SnakeParts[player.SnakeParts.Count - 1].Position, "Background"); string deathReason = player.Move(); //if food has been eaten: add score, update score label and spawn new food bool hasEatenFood = player.ScoreToAdd > 0; if (hasEatenFood) { CurrentScore += player.ScoreToAdd; player.ScoreToAdd = 0; SpawnFood(); scoreTSMI.Text = String.Format("Score: {0}", CurrentScore); } //check if dead if (deathReason != "") { //Actually dead End(deathReason); } else { //not dead //draw snake body foreach (SnakePart snakePart in player.SnakeParts) { drawArea.DrawSquare(snakePart.Position, snakePart.Name); } //update time UpdateTimeSurvived(); timeTSMI.Text = String.Format("Time Survived: {0}", TimeSurvivedFormatted); } }
public void Update() { //updates player location Player.Move(); //checks if food was found if (Representation[Player.LocationY, Player.LocationX] == Food.Icon) { Player.AddPointsToScore(); Player.Grow(); Representation[Player.LocationY, Player.LocationX] = Player.Body[0].Icon; SetFoodLocation(); } else if (!(Representation[Player.LocationY, Player.LocationX] == ' ' || Representation[Player.LocationY, Player.LocationX] == Player.Icon)) { Player.StatusValue = Player.Status.Dead; Console.Title = "Died to: " + Representation[Player.LocationY, Player.LocationX].ToString(); } //updates blank board for (int i = 0; i < Height; i++) { for (int j = 0; j < Width; j++) { if (i == 0 || i == Height - 1) { Representation[i, j] = '='; } else { Representation[i, j] = j == 0 || j == (Width - 2) ? '|' : ' '; } } } //draws members to board UpdateMembers(); }
public void Execute() { player.ReadInput(); player.Move(); Thread.Sleep(75); }