Пример #1
0
        public void Update(Cell subject)
        {
            if (status == CellStatus.empty)
            {
                return;
            }

            switch (subject.status)
            {
            case CellStatus.placeable:
            case CellStatus.newplaced:
            {
                if (color != subject.color)
                {
                    checkingcolor = subject.color;
                    direction     = CalDir(subject);
                    status        = CellStatus.checking;
                    AnnounceObservers();
                }
            }
            break;

            case CellStatus.checking:
            {
                ReleatedDir dir = CalDir(subject);
                if (dir == subject.direction)
                {
                    if (subject.checkingcolor == color)
                    {
                        direction = ReverseDir(subject.direction);
                        status    = CellStatus.needflip;
                    }
                    else
                    {
                        direction     = dir;
                        checkingcolor = subject.checkingcolor;
                        status        = CellStatus.checking;
                    }
                    AnnounceObservers();
                }
            }
            break;

            case CellStatus.needflip:
            {
                ReleatedDir dir = CalDir(subject);
                if (dir == subject.direction)
                {
                    if (status == CellStatus.placeable)
                    {
                        return;
                    }
                    if (status == CellStatus.newplaced)
                    {
                        status = CellStatus.placeable;
                        return;
                    }
                    direction = dir;
                    color     = (Color)(3 - (int)color);
                    status    = CellStatus.needflip;
                    AnnounceObservers();
                }
            }
            break;
            }
        }
Пример #2
0
 ReleatedDir ReverseDir(ReleatedDir dir) => (ReleatedDir)(7 - (int)dir);