コード例 #1
0
 private string FormatPlayerDisplayName(Player player)
 {
     if (string.IsNullOrEmpty(player.NickName))
     {
         return string.Format("{0} {1}", player.FirstName, player.LastName);
     }
     return string.Format("{0} \"{1}\" {2}", player.FirstName, player.NickName, player.LastName);
 }        
コード例 #2
0
        public void When_a_player_is_created_it_should_start_with_empty_properties()
        {
            Player player = new Player();

            Assert.Equal(string.Empty, player.FirstName);
            Assert.Equal(string.Empty, player.LastName);
            Assert.Equal(string.Empty, player.NickName);
        }
コード例 #3
0
        public void When_a_player_is_added_to_a_game_its_added_to_the_backing_store()
        {
            var game = new Game(new BuyIn());

            var entrant = new Player();
            game.AddEntrant(entrant);

            Assert.Contains(entrant, game.AllEntrants());
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: scottmuc/KnittingClub.Net
 public virtual void AddEntrant(Player entrant)
 {
     if (this.IsStarted())
         throw new ArgumentException("Cannot join a game that has been started.");
     if (players.Contains(entrant))
         throw new ArgumentException("That player is already in the game.");
         
     players.Add(entrant);            
 }
コード例 #5
0
        public void When_a_entrant_is_attempted_to_be_added_more_than_once_it_throw_an_argument_exception() 
        {
            var game = new Game(new BuyIn());

            var entrant = new Player();
            game.AddEntrant(entrant);


            Assert.Throws<ArgumentException>(() => game.AddEntrant(entrant));            
            Assert.Contains(entrant, game.AllEntrants());
            Assert.Equal(1, game.AllEntrants().Count());
        }
コード例 #6
0
ファイル: Game.cs プロジェクト: scottmuc/KnittingClub.Net
        public virtual void KnockPlayerOut(Player knockedOut, Player knockingOut)
        {
            foreach(var result in playersKnockedOut)
            {
                if (result.Player.Id == knockedOut.Id)
                    throw new ArgumentException("A player that's already knocked out can't be knocked out again!");
                if (result.Player.Id == knockingOut.Id)
                    throw new ArgumentException("A player that's knocked out can't knock out another player!");
                if (knockedOut.Id == knockingOut.Id)
                    throw new ArgumentException("Stop being so dumb! You can't knock yourself out (unless you're Mark)");

            }

            int place = players.Count - playersKnockedOut.Count;

            var gameResult = new GameResult()
                             {
                                 KnockedOutBy = knockingOut,
                                 Player = knockedOut,
                                 Place = place
                             };

            playersKnockedOut.Add(gameResult);

            // this means knockOut Player won!
            if (place == 2)
            {
                var lastResult = new GameResult()
                             {
                                 KnockedOutBy = null,
                                 Player = knockingOut,
                                 Place = 1
                             };  
                playersKnockedOut.Add(lastResult);
            }

        }