Exemple #1
0
            public void Move(char dir)
            {
                switch (dir)
                {
                case 'U':
                    if (pos.y > 0)
                    {
                        pos = pos.Up();
                        if (Current() == null)
                        {
                            pos = pos.Down();
                        }
                    }
                    break;

                case 'D':
                    if (pos.y < _nRows - 1)
                    {
                        pos = pos.Down();
                        if (Current() == null)
                        {
                            pos = pos.Up();
                        }
                    }
                    break;

                case 'L':
                    if (pos.x > 0)
                    {
                        pos = pos.Left();
                        if (Current() == null)
                        {
                            pos = pos.Right();
                        }
                    }
                    break;

                case 'R':
                    if (pos.x < _nCols - 1)
                    {
                        pos = pos.Right();
                        if (Current() == null)
                        {
                            pos = pos.Left();
                        }
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
Exemple #2
0
    public static Pos Next(this Movement move, Pos from)
    {
        switch (move)
        {
        case Movement.UP: return(from.Up());

        case Movement.DOWN: return(from.Down());

        case Movement.RIGHT: return(from.Right());

        case Movement.LEFT: return(from.Left());

        default: return(from);
        }
    }