Ejemplo n.º 1
0
 public GameDecorator(GameDecorator source)
 {
     game   = source.game;
     shifts = new Dictionary <int, Point>();
     foreach (var pair in source.shifts)
     {
         shifts.Add(pair.Key, pair.Value);
     }
 }
Ejemplo n.º 2
0
        public GameDecorator Shift(int value)
        {
            if (value <= 0 || value >= fieldSize * fieldSize)
            {
                throw new ArgumentOutOfRangeException();
            }

            int dx = locations[0].X - locations[value].X;
            int dy = locations[0].Y - locations[value].Y;

            if (Math.Abs(dx) == 1 ^ Math.Abs(dy) == 1)
            {
                GameDecorator decorator = new GameDecorator(this);
                return(decorator.Shift(value));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 3
0
        public GameDecorator Shift(int value)
        {
            if (value <= 0 || value >= game.fieldSize * game.fieldSize)
            {
                throw new ArgumentOutOfRangeException();
            }

            Point p1 = GetLocation(0);
            Point p2 = GetLocation(value);
            int   dx = p1.X - p2.X;
            int   dy = p1.Y - p2.Y;

            if (Math.Abs(dx) == 1 ^ Math.Abs(dy) == 1)
            {
                GameDecorator decorator = new GameDecorator(this);
                decorator.shifts.Add(value, GetLocation(0));
                decorator.shifts.Add(0, GetLocation(value));
                return(decorator);
            }
            else
            {
                throw new InvalidOperationException();
            }
        }