Example #1
0
File: Game.cs Project: kphl/Sokoban
        public void Move(Direction d)
        {
            Player   player = Grid.getPlayer();
            Position pos    = null;

            switch (d)
            {
            case Direction.DOWN:
                pos = new Position(0, 1);
                break;

            case Direction.UP:
                pos = new Position(0, -1);
                break;

            case Direction.LEFT:
                pos = new Position(-1, 0);
                break;

            case Direction.RIGHT:
                pos = new Position(1, 0);
                break;
            }

            Box      start = Grid.Box(player.Pos.X, player.Pos.Y);
            Position p     = pos + player.Pos;
            Box      end   = Grid.Box(p.X, p.Y);

            if (player.Move(d, end))
            {
                Movement m  = new Movement(start, end, player, d);
                bool     ok = true;

                if (end.Entity is Crate)
                {
                    Crate    c      = end.Entity as Crate;
                    Box      startC = Grid.Box(c.Pos.X, c.Pos.Y);
                    Position pC     = pos + c.Pos;
                    Box      endC   = Grid.Box(pC.X, pC.Y);

                    if (c.Move(d, endC))
                    {
                        Grid.Move(startC, endC);
                        Movement mC = new Movement(startC, endC, c, d);
                        m.CrateMovement = mC;
                    }
                    else
                    {
                        ok = false;
                    }
                }

                if (ok)
                {
                    moves.Add(m);
                    Grid.Move(start, end);
                }
            }
        }
Example #2
0
        public void polymorphMove()
        {
            Crate crate = new Crate(currentField);
            Truck truck = new Truck(currentField);
            Wall  wall  = new Wall();

            wall.Move(Direction.Right);
            crate.Move(Direction.Right);
            truck.Move(Direction.Right);
        }