namespace Tickypip { using System; public enum ServerCellHalf { Top, Bottom }; public class ServerCell : ConnectorCell { private ServerCellHalf mHalf; bool mDirLock = false; public ServerCell(Board board, ServerCellHalf half, ConnectorType connType) : base(board, connType) { Half = half; DirectionChanged += new DirectionChangedEventHandler(OnDirectionChanged); Gnome.CanvasRect rect = new Gnome.CanvasRect(this); rect.FillColorGdk = new Gdk.Color(255, 0, 0); rect.X1 = 5; rect.Y1 = 5; rect.X2 = WIDTH - 6; rect.Y2 = HEIGHT - 6; } public ServerCell(Board board, ServerCellHalf half) : this(board, half, ConnectorType.None) { } public override bool Active { get { return true; } } public ServerCellHalf Half { get { return mHalf; } set { mHalf = value; } } private void OnDirectionChanged(Cell thisCell) { if (mDirLock) return; Cell cell = Board.GetNearCell(this, (Half == ServerCellHalf.Top ? Direction.South : Direction.North)); if (cell == null) return; mDirLock = true; cell.Direction = Direction; mDirLock = false; } protected override void AddLine(Direction dir, bool spanSize, Gdk.Color color) { if ((Half == ServerCellHalf.Top && ((dir == Direction.South && !spanSize) || dir == Direction.East || dir == Direction.West)) || (Half == ServerCellHalf.Bottom && (dir == Direction.North && !spanSize))) { return; } base.AddLine(dir, spanSize, color); } public override bool HasConnector(Direction dir) { if ((Half == ServerCellHalf.Top && dir != Direction.North) || (Half == ServerCellHalf.Bottom && dir == Direction.North)) { return false; } return base.HasConnector(dir); } } }