public ASnake(SnakePit snakePit, int startLength, Point startPosition, Color col) { this.snakePit = snakePit; for (int i = 0; i < startLength; i++) { Point cell = new Point(startPosition.X - startLength + i + 1, startPosition.Y); snakePit.SetCell(cell, col); this.bodyParts.Enqueue(cell); this.head = cell; } this.col = col; this.xSpeed = 1; this.ySpeed = 0; this.increaseBy = 0; snakePit.AddSnake(this); }
public CrashType Move() { if (this.increaseBy == 0) { Point tail = this.bodyParts.Dequeue(); snakePit.ClearCell(tail); } else { this.increaseBy--; } this.head.X += this.xSpeed; this.head.Y += this.ySpeed; if (this.DoesIntersect(this.head)) { Console.WriteLine("!!!SELF CRASH!!!"); return(CrashType.Self); } this.bodyParts.Enqueue(this.head); snakePit.SetCell(this.head, this.col); CrashType crash = this.snakePit.IsCrash(head); return(crash); }