Exemple #1
0
        private IntegerCoordinates GetNextCoords(SokoGame game, IntegerCoordinates coords)
        {
            int dX = 0;
            int dY = 0;

            if (KeyboardState.IsKeyDown(Keys.Down) && coords.Y + 1 < game.GetMapHeight())
            {
                dY = 1;
            }

            if (KeyboardState.IsKeyDown(Keys.Up) && coords.Y > 0)
            {
                dY = -1;
            }

            if (KeyboardState.IsKeyDown(Keys.Right) && coords.X + 1 < game.GetMapWidth())
            {
                dX = 1;
            }

            if (KeyboardState.IsKeyDown(Keys.Left) && coords.X > 0)
            {
                dX = -1;
            }

            return(new IntegerCoordinates(coords.X + dX, coords.Y + dY));
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            State = GameState.Menu;

            mainMenu   = new MainMenu(Content, graphics);
            sokoGame   = new SokoGame(Content, graphics);
            finishGame = new FinishGame(Content, graphics);

            Mouse.WindowHandle = Window.Handle;
            base.Initialize();
        }
 public abstract List <CreatureMapChange> Act(SokoGame gameState, KeyboardState command);
Exemple #4
0
 public override List <CreatureMapChange> Act(SokoGame gameState, KeyboardState command)
 {
     return(new List <CreatureMapChange>());
 }
Exemple #5
0
        public override List <CreatureMapChange> Act(SokoGame gameState, KeyboardState keyboardState)
        {
            var creatureMovingList = new List <CreatureMapChange>();

            if (IsActive)
            {
                KeyboardState = keyboardState;

                var nextCoords = GetNextCoords(gameState, Coordinates);

                if (gameState.GetUpperCreature(nextCoords) == null ||
                    gameState.GetUpperCreature(nextCoords) is StorageLocation)
                {
                    creatureMovingList.Add(new CreatureMapChange
                    {
                        Creature     = this,
                        Coords       = Coordinates,
                        TargetCoords = nextCoords,

                        ScoresDelta = 1,
                        FreeStorageLocationDelta = 0
                    });
                }
                else if (gameState.GetUpperCreature(nextCoords) is Box)
                {
                    var nextnextCoords = GetNextCoords(gameState, nextCoords);

                    if (gameState.GetUpperCreature(nextnextCoords) == null ||
                        gameState.GetUpperCreature(nextnextCoords) is StorageLocation)
                    {
                        creatureMovingList.Add(new CreatureMapChange
                        {
                            Creature     = this,
                            Coords       = Coordinates,
                            TargetCoords = nextCoords,

                            ScoresDelta = 1,
                            FreeStorageLocationDelta = 0
                        });

                        int freeStorageLocationDelta = 0;
                        if (gameState.GetLowerCreature(nextCoords) is StorageLocation)
                        {
                            freeStorageLocationDelta++;
                        }
                        if (gameState.GetUpperCreature(nextnextCoords) is StorageLocation)
                        {
                            freeStorageLocationDelta--;
                        }

                        creatureMovingList.Add(new CreatureMapChange
                        {
                            Creature     = gameState.GetUpperCreature(nextCoords),
                            Coords       = nextCoords,
                            TargetCoords = nextnextCoords,

                            ScoresDelta = 0,
                            FreeStorageLocationDelta = freeStorageLocationDelta
                        });
                    }
                }
                IsActive = false;
            }

            return(creatureMovingList);
        }