コード例 #1
0
        public void NotChangePlayerLocation_GivenInvalidMove()
        {
            // Arrange
            var fakeRoad = A.Fake <IAdventureLocation>();

            A.CallTo(() => fakeRoad.ValidMoves).Returns(new List <IPlayerMove> {
                new PlayerMove("You enter the building.", Location.Building, "east", "e", "enter", "in", "inside", "building"),
            });

            var fakeBuilding = A.Fake <IAdventureLocation>();
            var fakeGame     = A.Fake <IReadonlyAdventureGame>();

            var player = new AdventurePlayer("Player1", "PlayerOne", A.Fake <IChatClient>());

            player.CurrentLocation = fakeRoad;

            var args = new ChatCommandEventArgs("!adv", new List <string> {
                "go", "north"
            }, string.Empty, "Bill", "Player1", string.Empty);

            // Act
            var cmd = new Move(fakeGame, "move", "go");

            cmd.Invoke(player, args);

            // Assert
            Assert.AreSame(fakeRoad, player.CurrentLocation);
        }
コード例 #2
0
        public void IncrementPlayerMoveCount()
        {
            // Arrange
            var fakeRoad = A.Fake <IAdventureLocation>();

            A.CallTo(() => fakeRoad.ValidMoves).Returns(new List <IPlayerMove> {
                new PlayerMove("You enter the building.", Location.Building, "east", "e", "enter", "in", "inside", "building"),
            });

            var fakeBuilding = A.Fake <IAdventureLocation>();

            var fakeGame = A.Fake <IReadonlyAdventureGame>();

            A.CallTo(() => fakeGame.Dungeon.TryGetLocation(A <Location> .Ignored, out fakeBuilding)).Returns(true)
            .AssignsOutAndRefParameters(fakeBuilding);

            var player = new AdventurePlayer("Player1", "PlayerOne", A.Fake <IChatClient>());

            player.CurrentLocation = fakeRoad;

            var args = new ChatCommandEventArgs("!adv", new List <string> {
                "go", "east"
            }, string.Empty, "Bill", "Player1", string.Empty);

            // Act
            var cmd = new Move(fakeGame, "move", "go");

            cmd.Invoke(player, args);

            // Assert
            Assert.AreEqual(1, player.Moves);
        }
コード例 #3
0
        public async Task <IActionResult> Create(CreateSessionViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (viewModel.SelectedSessionPlayers == null)
                    {
                        viewModel.SelectedSessionPlayers = new List <int>();
                    }

                    List <SessionPlayer>   playersInSession   = new List <SessionPlayer>();
                    List <AdventurePlayer> playersInAdventure = new List <AdventurePlayer>();

                    foreach (int playerID in viewModel.SelectedSessionPlayers)
                    {
                        //Wie speelt mee in de session
                        SessionPlayer sessionPlayer = new SessionPlayer();
                        sessionPlayer.PlayerID  = playerID;
                        sessionPlayer.SessionID = viewModel.Session.SessionID;

                        //Welke spelers spelen het avontuur mee
                        AdventurePlayer adventurePlayer = new AdventurePlayer();
                        adventurePlayer.PlayerID    = playerID;
                        adventurePlayer.AdventureID = viewModel.Session.AdventureID;

                        playersInSession.Add(sessionPlayer);
                        playersInAdventure.Add(adventurePlayer);
                    }
                    _context.Add(viewModel.Session);
                    await _context.SaveChangesAsync();

                    Session session = await _context.Sessions
                                      .Include(s => s.SessionPlayers)
                                      .Include(a => a.Adventure.AdventurePlayers)
                                      .SingleOrDefaultAsync(x => x.SessionID == viewModel.Session.SessionID);

                    session.SessionPlayers.AddRange(playersInSession);
                    session.Adventure.AdventurePlayers.AddRange(playersInAdventure);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception)
                {
                    return(Redirect("~/Views/Shared/Error.cshtml"));
                }
            }
            return(View(viewModel));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, EditSessionViewModel viewModel)
        {
            if (id != viewModel.Session.SessionID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                Session session = await _context.Sessions
                                  .Include(s => s.SessionPlayers)
                                  .Include(a => a.Adventure.AdventurePlayers)
                                  .SingleOrDefaultAsync(x => x.SessionID == id);

                session.AdventureID       = viewModel.Session.AdventureID;
                session.Date              = viewModel.Session.Date;
                session.Duration          = viewModel.Session.Duration;
                session.IsPlayed          = viewModel.Session.IsPlayed;
                session.Recap             = viewModel.Session.Recap;
                session.SessionGamemaster = viewModel.Session.SessionGamemaster;

                if (viewModel.SelectedSessionPlayers == null)
                {
                    viewModel.SelectedSessionPlayers = new List <int>();
                }

                List <SessionPlayer>   playersInSession   = new List <SessionPlayer>();
                List <AdventurePlayer> playersInAdventure = new List <AdventurePlayer>();

                foreach (int playerID in viewModel.SelectedSessionPlayers)
                {
                    //Wie speelt mee in de session
                    SessionPlayer sessionPlayer = new SessionPlayer();
                    sessionPlayer.PlayerID  = playerID;
                    sessionPlayer.SessionID = viewModel.Session.SessionID;

                    //Welke spelers spelen het avontuur mee
                    AdventurePlayer adventurePlayer = new AdventurePlayer();
                    adventurePlayer.PlayerID    = playerID;
                    adventurePlayer.AdventureID = viewModel.Session.AdventureID;

                    playersInSession.Add(sessionPlayer);
                    playersInAdventure.Add(adventurePlayer);
                }

                session.SessionPlayers
                .RemoveAll(sp => !playersInSession.Contains(sp));
                session.SessionPlayers
                .AddRange(
                    playersInSession.Where(p => !session.SessionPlayers.Contains(p)));

                session.Adventure.AdventurePlayers
                .RemoveAll(ap => !playersInAdventure.Contains(ap));
                session.Adventure.AdventurePlayers
                .AddRange(
                    playersInAdventure.Where(p => !session.Adventure.AdventurePlayers.Contains(p)));

                _context.Update(session);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(viewModel));
        }