public bool IsAvailableMove(IMove move) { Point start = move.GetLine().GetStart().GetLocation(); Point end = move.GetLine().GetEnd().GetLocation(); if (CornerPointOnBoard(start) && CornerPointOnBoard(end)) { foreach (Move m in m_Moves) { if (m.GetLine().GetStart() == move.GetLine().GetStart() && m.GetLine().GetEnd() == move.GetLine().GetEnd()) { return(false); } } return(true); } return(false); }
Box CreateBox(IMove move, BoxDirection direction, Player player) { bool wouldBox = false; Corner ul = null, ur = null, ll = null, lr = null; switch (direction) { case BoxDirection.Up: { if (!(move.GetLine() as Line).Vertical) { ll = move.GetLine().GetStart() as Corner; ul = GetCornerFromDirection(ll, BoxDirection.Up); lr = move.GetLine().GetEnd() as Corner; ur = GetCornerFromDirection(lr, BoxDirection.Up); } } break; case BoxDirection.Down: { if (!(move.GetLine() as Line).Vertical) { ul = move.GetLine().GetStart() as Corner; ur = move.GetLine().GetEnd() as Corner; ll = GetCornerFromDirection(ul, BoxDirection.Down); lr = GetCornerFromDirection(ur, BoxDirection.Down); } } break; case BoxDirection.Left: { if ((move.GetLine() as Line).Vertical) { ur = move.GetLine().GetStart() as Corner; lr = move.GetLine().GetEnd() as Corner; ul = GetCornerFromDirection(ur, BoxDirection.Left); ll = GetCornerFromDirection(lr, BoxDirection.Left); } } break; case BoxDirection.Right: { if ((move.GetLine() as Line).Vertical) { ul = move.GetLine().GetStart() as Corner; ll = move.GetLine().GetEnd() as Corner; ur = GetCornerFromDirection(ul, BoxDirection.Right); lr = GetCornerFromDirection(ll, BoxDirection.Right); } } break; default: throw new ArgumentException("Direction must be one of Up, Down, Left, Right"); } Box box = null; if (ul != null && ur != null && ll != null && lr != null) { wouldBox = MakesBox(ul, ur, ll, lr, move as Move); if (wouldBox) { box = new Box(ul, ur, lr, ll, player, this); } } return(box); }
public int CompareTo(IMove other) { return(GetLine().CompareTo(other.GetLine())); }