public void AddSnakeBody(int x, int y) { SnakePoint p = new SnakePoint(x, y); SnakeBody.Add(p); iSnake++; }
public static void AddSnakeElement() { switch (directionMove) { case DirectionMove.up: { SnakePoint snakePoint1 = new SnakePoint(dictionary.Last().X, dictionary.Last().Y - 1); } break; case DirectionMove.down: { SnakePoint snakePoint1 = new SnakePoint(dictionary.Last().X, dictionary.Last().Y + 1); } break; case DirectionMove.left: { SnakePoint snakePoint1 = new SnakePoint(dictionary.Last().X - 1, dictionary.Last().Y); } break; case DirectionMove.right: { SnakePoint snakePoint1 = new SnakePoint(dictionary.Last().X + 1, dictionary.Last().Y); } break; } }
static public SnakePoint EndElement(SnakePoint snakePoint) { if (snakePoint.isHead) { return(snakePoint); } return(dictionary.Last()); }
public SnakePoint(int x, int y, bool isHead = false) { X = x; Y = y; this.isHead = isHead; prevPoint = SnakePointsManager.EndElement(this); SnakePointsManager.AddInList(this); }
public SnakePoint GetSnakeNextPoint() { SnakePoint p = SnakeBody[SnakeBody.Count - 1]; switch (_direct) { case Towards.Left: { p.X = p.X - 1; if (p.X < 0) { p.X = p.X + MaxPos; } } break; case Towards.Right: { p.X = p.X + 1; if (p.X >= MaxPos) { p.X = p.X - MaxPos; } } break; case Towards.Up: { p.Y = p.Y - 1; if (p.Y < 0) { p.Y = p.Y + MaxPos; } } break; case Towards.Down: { p.Y = p.Y + 1; if (p.Y >= MaxPos) { p.Y = p.Y - MaxPos; } } break; default: break; } return(p); }
public bool MoveSnake() { SnakePoint p = GetSnakeNextPoint(); if (SnakeBody.Contains(p)) { return(false); } SnakeBody.Add(p); _snakeTail = SnakeBody[0]; _snakeHead = SnakeBody.Last(); SnakeBody.RemoveAt(0); return(true); }
private bool MoveAndEat() { SnakePoint p = snake.GetSnakeNextPoint(); if (food != null && p.X == food.X && p.Y == food.Y) { snake.AddSnakeBody(p.X, p.Y); food = null; return(true); } else { return(snake.MoveSnake()); } }
public static void AddInList(SnakePoint thisObject) { dictionary.Add(thisObject); }
public static void StartGame(int x, int y) { SnakePoint head = new SnakePoint(x, y, true); AddSnakeElement(); }
public bool MoveSnake() { SnakePoint p = GetSnakeNextPoint(); if (SnakeBody.Contains(p)) return false; SnakeBody.Add(p); _snakeTail = SnakeBody[0]; _snakeHead = SnakeBody.Last(); SnakeBody.RemoveAt(0); return true; }