public void Bounce() { var direction = GetDirection(); ConsoleWriter.Display("\u2588", location.First(), Color.Red); while (true) { var currentLoc = location.First(); int x = currentLoc.X + direction.X; int y = currentLoc.Y + direction.Y; var newLoc = new Position(x, y); Thread.Sleep(50); location.Add(newLoc); var oldLoc = location.First(); ConsoleWriter.Display(" ", oldLoc); location.RemoveAt(0); ConsoleWriter.Display("\u2588", newLoc, Color.Red); if (newLoc.X == 1 || newLoc.X == _maxWidth || HasVerticalCollision(location, _wall.GetLocation())) { direction.X = -direction.X; } if (newLoc.Y == 1 || newLoc.Y == _maxHeight || HasHorizontalCollision(location, _wall.GetLocation())) { direction.Y = -direction.Y; } } }
private void Display(List <Position> borderWall) { foreach (var section in borderWall) { ConsoleWriter.Display("\u2588", section, Color.Purple); } }
public void Build() { while (true) { foreach (var w in section) { ConsoleWriter.Display("\u2588", w, Color.Green); } ConsoleKeyInfo keyInfo = Console.ReadKey(true); int x; int y; Position lastWall; Position newWall; switch (keyInfo.Key) { case ConsoleKey.Escape: return; case ConsoleKey.UpArrow: lastWall = section.Last(); y = lastWall.Y - 1; newWall = new Position(lastWall.X, y); if (lastWall.Y > 1 && !IsInList(section, newWall)) { section.Add(newWall); } break; case ConsoleKey.DownArrow: lastWall = section.Last(); y = lastWall.Y + 1; newWall = new Position(lastWall.X, y); if (lastWall.Y < _maxHeight && !IsInList(section, newWall)) { section.Add(newWall); } break; case ConsoleKey.LeftArrow: lastWall = section.Last(); x = lastWall.X - 1; newWall = new Position(x, lastWall.Y); if (lastWall.X > 1 && !IsInList(section, newWall)) { section.Add(newWall); } break; case ConsoleKey.RightArrow: lastWall = section.Last(); x = lastWall.X + 1; newWall = new Position(x, lastWall.Y); if (lastWall.X < _maxWidth && !IsInList(section, newWall)) { section.Add(newWall); } break; } } }