Пример #1
0
        public GameLogic(LevelAttempt levelAttempt)
        {
            this.levelAttempt = levelAttempt;

            gamePhysics = new GamePhysics(levelAttempt.Level);
            collisions  = new Collisions(levelAttempt.Level);
        }
Пример #2
0
        public void GetAllLevelsInWorld_3LevelsLevel1CompletedTie()
        {
            //Arrange
            Level level1 = GetTestLevel();
            Level level2 = GetTestLevel(sequenceInWorld: 2);
            Level level3 = GetTestLevel(sequenceInWorld: 3);

            Setup3TiersForLevel(level1.Id);
            Setup3TiersForLevel(level2.Id);
            Setup3TiersForLevel(level3.Id);
            Player       player        = GetTestPlayer();
            LevelAttempt attemptFailed = GetTestLevelAttempt(player.Id, level1.Id, score: 1022, timeSeconds: 543,
                                                             completed: true);
            LevelAttempt attemptSuccess = GetTestLevelAttempt(player.Id, level1.Id, score: 1022, timeSeconds: 325,
                                                              completed: true);

            LevelProvider provider = new LevelProvider(_context);

            //Act
            ICollection <LevelDto> levels = provider.GetAllLevelsInWorld(_testWorldId);

            //Assert
            int expectedCount           = 3;
            int expectedLevel1HighScore = 1022;
            int expectedLevel2HighScore = 0;

            Assert.AreEqual(expectedCount, levels.Count);
            Assert.AreEqual(expectedLevel1HighScore, levels.Single(l => l.Sequence == 1).PlayerHighScore);
            Assert.AreEqual(expectedLevel2HighScore, levels.Single(l => l.Sequence == 2).PlayerHighScore);
        }
        public void GetPlayerCurrentPowerups_Bought6Speed9JumpUsedAllSpeeds()
        {
            //Arrange
            Player       player  = GetTestPlayer();
            Level        level   = GetTestLevel();
            LevelAttempt attempt = GetTestLevelAttempt(player.Id, level.Id);

            GetTestEnergyPurchase(player.Id, 3);
            GetTestEnergyPurchase(player.Id, 3);
            GetTestEnergyPurchase(player.Id, 5);
            GetTestEnergyPurchase(player.Id, 6);
            GetTestPlayerPowerupUsage(player.Id, 1, attempt.Id);
            GetTestPlayerPowerupUsage(player.Id, 1, attempt.Id);
            GetTestPlayerPowerupUsage(player.Id, 1, attempt.Id);
            GetTestPlayerPowerupUsage(player.Id, 1, attempt.Id);
            GetTestPlayerPowerupUsage(player.Id, 1, attempt.Id);
            GetTestPlayerPowerupUsage(player.Id, 1, attempt.Id);
            GetTestPlayerPowerupUsage(player.Id, 2, attempt.Id);
            GetTestPlayerPowerupUsage(player.Id, 2, attempt.Id);
            GetTestPlayerPowerupUsage(player.Id, 2, attempt.Id);

            PlayerProvider provider = new PlayerProvider(_context);

            //Act
            ICollection <KeyValuePair <string, int> > powerups = provider.GetPlayerCurrentPowerups(player.Id);

            //Assert
            int expectedCount      = 2;
            int expectedSpeedCount = 0;
            int expectedJumpCount  = 6;

            Assert.AreEqual(expectedCount, powerups.Count);
            Assert.AreEqual(expectedSpeedCount, powerups.Where(p => p.Key == "Speed").Sum(p => p.Value));
            Assert.AreEqual(expectedJumpCount, powerups.Where(p => p.Key == "Jump").Sum(p => p.Value));
        }
Пример #4
0
        public LevelAttempt GetHighestCompletedLevelAttemptForPlayer(int playerId)
        {
            LevelAttempt highestCompletedLevelAttempt =
                db.LevelAttempts.Include(l => l.Level).Where(l => l.PlayerId == playerId && l.Completed)
                .OrderByDescending(l => l.Level.World)
                .ThenByDescending(l => l.Level.SequenceInWorld)
                .FirstOrDefault();

            return(highestCompletedLevelAttempt);
        }
Пример #5
0
        public void GetHighestCompletedLevelAttemptForPlayer_NoneTried()
        {
            //Arrange
            Level  level1 = GetTestLevel();
            Player player = GetTestPlayer();

            LevelProvider provider = new LevelProvider(_context);

            //Act
            LevelAttempt attempt = provider.GetHighestCompletedLevelAttemptForPlayer(player.Id);

            //Assert
            Assert.AreEqual(null, attempt);
        }
Пример #6
0
        public void GetNextNonCompleteLevel_OneLevelCompleted()
        {
            //Arrange
            Level         level1       = GetTestLevel();
            Level         level2       = GetTestLevel(sequenceInWorld: 2);
            Level         level3       = GetTestLevel(sequenceInWorld: 3);
            Player        player       = GetTestPlayer();
            LevelAttempt  savedAttempt = GetTestLevelAttempt(player.Id, level1.Id, completed: true);
            LevelProvider provider     = new LevelProvider(_context);

            //Act
            Level nextLevel = provider.GetNextNonCompleteLevel(player.Id);

            //Assert
            Assert.AreEqual(level2.Id, nextLevel.Id);
        }
Пример #7
0
        public void GetHighestCompletedLevelAttemptForPlayer_OneCompletedSecondNotTried()
        {
            //Arrange
            Level        level1       = GetTestLevel();
            Level        level2       = GetTestLevel(sequenceInWorld: 2);
            Level        level3       = GetTestLevel(sequenceInWorld: 3);
            Player       player       = GetTestPlayer();
            LevelAttempt savedAttempt = GetTestLevelAttempt(player.Id, level1.Id, completed: true);

            LevelProvider provider = new LevelProvider(_context);

            //Act
            LevelAttempt attempt = provider.GetHighestCompletedLevelAttemptForPlayer(player.Id);

            //Assert
            Assert.AreEqual(savedAttempt.Id, attempt.Id);
        }
        public void GetCurrentPlayerLives_IrrelevantDeath()
        {
            //Arrange
            Player       player  = GetTestPlayer();
            Level        level   = GetTestLevel();
            LevelAttempt attempt = GetTestLevelAttempt(player.Id, level.Id);
            PlayerDeath  death   = GetTestPlayerDeath(player.Id, attempt.Id, DateTime.Now.AddMinutes(-1));

            PlayerProvider provider = new PlayerProvider(_context);

            //Act
            int lives = provider.GetCurrentPlayerLives(player.Id);

            //Assert
            int expectedLives = 5;

            Assert.AreEqual(expectedLives, lives);
        }
Пример #9
0
        public Level GetNextNonCompleteLevel(int playerId)
        {
            Level        nextLevel;
            LevelAttempt highestCompletedLevelAttempt = GetHighestCompletedLevelAttemptForPlayer(playerId);

            IOrderedQueryable <Level> orderedLevels = GetOrderedLevels();

            if (highestCompletedLevelAttempt == null)
            {
                //the player has not completed any levels, so just get the first
                nextLevel = orderedLevels.First(l => l.Active);
            }
            else
            {
                //check to see if there is another level in the current world
                nextLevel =
                    orderedLevels
                    .SingleOrDefault(
                        l =>
                        l.World == highestCompletedLevelAttempt.Level.World &&
                        l.SequenceInWorld == highestCompletedLevelAttempt.Level.SequenceInWorld + 1);

                if (nextLevel == null)
                {
                    //check to see if there is a next world
                    nextLevel =
                        orderedLevels
                        .SingleOrDefault(
                            l =>
                            l.World == highestCompletedLevelAttempt.Level.World + 1 &&
                            l.SequenceInWorld == 1);
                }

                if (nextLevel == null)
                {
                    //the player has completed all levels, so just return the last level
                    nextLevel =
                        orderedLevels.OrderByDescending(o => o.World).ThenByDescending(o => o.SequenceInWorld)
                        .First();
                }
            }

            return(nextLevel);
        }
Пример #10
0
        public GameScreen(MyGameWindow gameWindow, Level level, string fileDirectory = "") : base(gameWindow)
        {
            levelAttempt = new LevelAttempt(level);

            gameLogic   = new GameLogic(levelAttempt);
            levelDrawer = new LevelDrawer(levelAttempt.Level);

            AddKeyToSingleUserActionMapping(Key.W, UserAction.Jump);
            AddKeyToSingleUserActionMapping(Key.Space, UserAction.Jump);

            AddKeyToProlongedUserActionMapping(Key.D, UserAction.Defend);
            AddKeyToProlongedUserActionMapping(Key.S, UserAction.Duck);
            AddKeyToProlongedUserActionMapping(Key.ControlLeft, UserAction.Duck);

            AddKeyToSingleUserActionMapping(Key.H, UserAction.ToggleAlwaysDefending);

            AddKeyToSingleUserActionMapping(Key.P, UserAction.TogglePauseGame);
            AddKeyToSingleUserActionMapping(Key.Escape, UserAction.TogglePauseGame);
            AddKeyToSingleUserActionMapping(Key.F10, UserAction.ResetLevel);
            AddKeyToSingleUserActionMapping(Key.N, UserAction.JumpToNextLevel);
            AddKeyToSingleUserActionMapping(Key.X, UserAction.ReturnToMainMenu);

            AddSingleUserActionToFunctionMapping(UserAction.Jump, Jump);
            AddProlongedUserActionToFunctionMapping(UserAction.Duck, Duck);
            AddProlongedUserActionToFunctionMapping(UserAction.Defend, Defend);

            AddSingleUserActionToFunctionMapping(UserAction.ToggleAlwaysDefending, ToggleAlwaysDefending);

            AddSingleUserActionToFunctionMapping(UserAction.ResetLevel, ResetLevel);
            AddSingleUserActionToFunctionMapping(UserAction.TogglePauseGame, TogglePauseGame);
            AddSingleUserActionToFunctionMapping(UserAction.JumpToNextLevel, JumpToNextLevel);
            AddSingleUserActionToFunctionMapping(UserAction.ReturnToMainMenu, ReturnToMainMenu);

            if (fileDirectory.Length > 0)
            {
                musicPlayer = new MusicPlayer(fileDirectory);
                musicPlayer.InitAudio();
            }

            Utils.Logger.StartNewLog(levelAttempt.Level.Name);
        }
        protected LevelAttempt GetTestLevelAttempt(int playerId, int levelId, DateTime?date = null, int timesDied = 0, long score = 100, int timeSeconds = 0, bool completed = false)
        {
            if (date == null)
            {
                date = DateTime.Now;
            }

            LevelAttempt attempt = _context.LevelAttempts.Add(new LevelAttempt
            {
                PlayerId    = playerId,
                LevelId     = levelId,
                Completed   = completed,
                Date        = date.Value,
                TimesDied   = timesDied,
                Score       = score,
                TimeSeconds = timeSeconds
            });

            _context.SaveChanges();
            LevelAttemptIdsToCleanup.Add(attempt.Id);

            return(attempt);
        }
        public void GetCurrentPlayerLives_MaxDeaths()
        {
            //Arrange
            Player       player  = GetTestPlayer();
            Level        level   = GetTestLevel();
            LevelAttempt attempt = GetTestLevelAttempt(player.Id, level.Id);
            PlayerDeath  death   = GetTestPlayerDeath(player.Id, attempt.Id);

            GetTestPlayerDeath(player.Id, attempt.Id);
            GetTestPlayerDeath(player.Id, attempt.Id);
            GetTestPlayerDeath(player.Id, attempt.Id);
            GetTestPlayerDeath(player.Id, attempt.Id);

            PlayerProvider provider = new PlayerProvider(_context);

            //Act
            int lives = provider.GetCurrentPlayerLives(player.Id);

            //Assert
            int expectedLives = 0;

            Assert.AreEqual(expectedLives, lives);
        }