public void MoveDirection() { switch (changeToDirection) { case "left": if (direction != "right") { direction = "left"; } break; case "right": if (direction != "left") { direction = "right"; } break; case "up": if (direction != "down") { direction = "up"; } break; case "down": if (direction != "up") { direction = "down"; } break; } switch (direction) { case "left": snakeHeadXPos -= 1; boundaryCheck(); Panel.SetBoxColor(snakeHeadXPos, snakeHeadYPos, Color.Red); break; case "right": snakeHeadXPos += 1; boundaryCheck(); Panel.SetBoxColor(snakeHeadXPos, snakeHeadYPos, Color.Red); break; case "up": snakeHeadYPos -= 1; boundaryCheck(); Panel.SetBoxColor(snakeHeadXPos, snakeHeadYPos, Color.Red); break; case "down": snakeHeadYPos += 1; boundaryCheck(); Panel.SetBoxColor(snakeHeadXPos, snakeHeadYPos, Color.Red); break; } }
private void foodTimer_Tick(object sender, EventArgs e) { foodTimer.Enabled = false; Food.foodColor = Color.Blue; Panel.SetBoxColor(Food.foodXPos, Food.foodYPos, Food.foodColor); }
public void New() { if (foodType == 5) { foodColor = Color.Green; foodType = 0; App.EnableBonus(); } for (int y = 0; y < Panel.PanelCorY; y++) { for (int x = 0; x < Panel.PanelCorX; x++) { if (Panel.GetBoxColor(x, y) == Color.Blue || Panel.GetBoxColor(x, y) == Color.Green) { foodXPos = x; foodYPos = y; Panel.SetBoxColor(x, y, Color.Black); } } } if (replaceFood == false) { Panel.SetBoxColor(foodXPos, foodYPos, foodColor); foundBox = false; while (foundBox == false) { foodXPos = R.Next(0, Panel.PanelCorX); foodYPos = R.Next(0, Panel.PanelCorY); if (Panel.GetBoxColor(foodXPos, foodYPos) == Color.Black) { Panel.SetBoxColor(foodXPos, foodYPos, foodColor); foundBox = true; } else { foodXPos = R.Next(0, Panel.PanelCorX); foodYPos = R.Next(0, Panel.PanelCorY); } } } else { replaceFood = false; foundBox = false; while (foundBox == false) { foundBox = false; foodXPos = R.Next(0, Panel.PanelCorX); foodYPos = R.Next(0, Panel.PanelCorY); if (Panel.GetBoxColor(foodXPos, foodYPos) == Color.Black) { Panel.SetBoxColor(foodXPos, foodYPos, foodColor); foundBox = true; } else { foodXPos = R.Next(0, Panel.PanelCorX); foodYPos = R.Next(0, Panel.PanelCorY); } } } foodType++; }