internal void DrawBoard(Board board, Graphics graphics, Rectangle bounds) { RectangleF rect = new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height); DrawGrid(graphics, board, rect); DrawFences(board, graphics, rect); DrawPlayers(board, graphics, rect); }
internal Square GetSquareForCoordinates(int screenX, int screenY, Board board, Rectangle canvasRectangle) { int pixPerSquareH = canvasRectangle.Width / board.Size; int pixPerSquareV = canvasRectangle.Height / board.Size; int x = screenX / pixPerSquareH; int y = screenY / pixPerSquareV; return board.Squares.FirstOrDefault(s => s.X == x && s.Y == y); }
/// <summary> /// Copy constructor. /// </summary> /// <param name="other">Board to copy from</param> protected Board(Board other) { throw new NotImplementedException("NYI"); }
public ShortestPathRunner(Player player, Board board) : base(player) { _board = board; }
private void DrawFences(Board board, Graphics graphics, RectangleF canvasRectangle) { foreach (Fence fence in board.Fences) { Link link = fence.SplittedLinks.First(); Square[] squares = fence.SplittedLinks.SelectMany(l => l.Squares).ToArray(); int leftColumn = squares.Min(s => s.X); int topRow = squares.Min(s => s.Y); if (link.Squares.First().X != link.Squares.Last().X) { DrawVerticalFence(topRow, leftColumn, graphics, canvasRectangle, board.Size, _fencePen); } else { DrawHorizontalFence(topRow, leftColumn, graphics, canvasRectangle, board.Size, _fencePen); } } }
private void DrawPlayers(Board board, Graphics graphics, RectangleF canvasRectangle) { foreach (Player player in board.Players) { Brush brush = _playerColors[player.PlayerId]; RectangleF squareRectangle = GetSquareRectangleF(canvasRectangle, board.Size, player.Position); graphics.FillEllipse(brush, squareRectangle); } }
private void DrawGrid(Graphics graphics, Board board, RectangleF canvasRectangle) { foreach (var square in board.Squares) { Rectangle rect = GetSquareRectangle(canvasRectangle, board.Size, square); graphics.DrawRectangle(_gridPen, rect); } }