예제 #1
0
        private void InitializeEntities()
        {
            // Place kits
            kits = EntitiesInitializer.InitKits(width, height, pointSize);

            // Place the player
            player = EntitiesInitializer.InitPlayer(width, height, pointSize, kits.Position);

            // Create the bombs array
            var exceptionsNearNotAllowed = new Point[] { player.Position, kits.Position, endPoint };

            bombs = EntitiesInitializer.InitBombs(width, height, pointSize, exceptionsNearNotAllowed: exceptionsNearNotAllowed).ToArray();
        }
예제 #2
0
        public static DefuseKit InitKits(int width, int height, int pointSize, params Point[] toIgnore)
        {
            DefuseKit kits;

            do
            {
                kits = new DefuseKit(
                    rnd.Next(1, (width - pointSize) / pointSize) * pointSize,
                    rnd.Next(1, (height - pointSize * 4) / pointSize) * pointSize
                    );
            } while (toIgnore?.Contains(kits.Position) ?? false);

            return(kits);
        }
예제 #3
0
        protected void UpdateGamePlay()
        {
            var current = Keyboard.GetState();

            if (current.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (current.IsKeyDown(Keys.C)) // Easter Egg =D
            {
                cheatMode = true;
            }
            else
            {
                cheatMode = false;
            }

            if (!path.AnyReversed(player.Position))
            {
                path.Add(player.Position);
            }

            if (previous == null)
            {
                previous = current;
            }

            if (!InputComparer.AreKeyboardStatesTheSame(previous, current))
            {
                previous = current;

                if (player.Move(current,
                                DirectionRestricter.ForbiddenDirect(player.Position,
                                                                    width - pointSize * 2,
                                                                    pointSize, pointSize,
                                                                    height - pointSize, endPoint + new Point(0, pointSize)
                                                                    ), pointSize))
                {
                    steps++;
                }

                if (kits != null && player.Position == kits.Position)
                {
                    player.HasDefuseKit = true;
                    kits = null;
                }

                int bombIndex = Array.IndexOf <Entity>(bombs, player);

                if (bombIndex >= 0)
                {
                    if (!player.HasDefuseKit)
                    {
                        _state = GameState.EndOfGame; // lost
                    }

                    bombs[bombIndex]    = null;
                    player.HasDefuseKit = false;
                }

                if (HaveWon) // won
                {
                    _state = GameState.EndOfGame;
                }
            }
        }