public void move(string direction) { Position currentHeadPosition = body[0]; Position newHeadPosition = null; switch (direction) { case "UP": if (currentHeadPosition.getRowNo() > mainBoard.getMinRowNo()) { newHeadPosition = new Position(currentHeadPosition.getRowNo() - 1, currentHeadPosition.getColNo()); } break; case "DOWN": if (currentHeadPosition.getRowNo() < mainBoard.getMaxRowNo()) { newHeadPosition = new Position(currentHeadPosition.getRowNo() + 1, currentHeadPosition.getColNo()); } break; case "LEFT": if (currentHeadPosition.getColNo() > mainBoard.getMinColNo()) { newHeadPosition = new Position(currentHeadPosition.getRowNo(), currentHeadPosition.getColNo() - 1); } break; case "RIGHT": if (currentHeadPosition.getColNo() < mainBoard.getMaxColNo()) { newHeadPosition = new Position(currentHeadPosition.getRowNo(), currentHeadPosition.getColNo() + 1); } break; default: //Do nothing break; } if (newHeadPosition != null) { body.Insert(0, newHeadPosition); //Add a new head positon 0 body.RemoveAt(body.Count - 1); //Remove the last position } }
public int eatAppleAtPostion(Position p) { Position snakeHeadPos = p; for (int i = 0; i < applelist.Count; i++) { if (snakeHeadPos.getRowNo() == applelist[i].getRowNo() && snakeHeadPos.getColNo() == applelist[i].getColNo()) { applelist.RemoveAt(i); } } return(50); //50 points per apple }
public int eatPoopAtPosition(Position a) { for (int i = 0; i < enemylist.Count; i++) { if (a.getRowNo() == enemylist[i].getRowNo() && a.getColNo() == enemylist[i].getColNo()) { enemylist.RemoveAt(i); } } return(100); }
public Boolean checkIFSnakeEatApple(Position snakeHead) { Boolean result = false; for (int i = 0; i < appleList.Count; i++) { if (snakeHead.getRowNo() == appleList[i].getRowNo() && snakeHead.getColNo() == appleList[i].getColNo()) { result = true; } } return(result); }
public int eatAppleAtPostion(Position p) { for (int i = 0; i < appleList.Count; i++) { if (p.getRowNo() == appleList[i].getRowNo() && p.getColNo() == appleList[i].getColNo()) { appleList.RemoveAt(i); eatpoptart = new SoundPlayer(Properties.Resources.Anime_wow___sound_effect); eatpoptart.LoadAsync(); eatpoptart.Play(); } } return(50); //50 points per apple }
public void draw(Position p, Image pic) { squares[p.getRowNo(), p.getColNo()].Image = pic; }