Exemplo n.º 1
0
        public void AddPlayer(Player player)
        {
            if (Players.Where(p => p.Key.Name == player.Name).Count() > 0)
                throw new Exception("Duplicate player added to match.");

            Players.Add(player, new LegsWon());
        }
Exemplo n.º 2
0
        public Visit(Player player, int score)
        {
            ValidateScore(score);

            Player = player;
            Score = score;
        }
Exemplo n.º 3
0
 public void ICannotAdd2PlayersToAMatchWithTheSameName()
 {
     var match = new Match(7, 501);
     var player = new Player("Andy");
     match.AddPlayer(player);
     match.AddPlayer(player);
 }
Exemplo n.º 4
0
        public void AnErrorIsThrownIfAPlayerHasAVisitWhoIsNotInTheLeg()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            var visit = new Visit(player, 100);

            var newScore = leg.Visit(visit);
        }
Exemplo n.º 5
0
 public void ErrorIsThrownWhenTheMatchEnds()
 {
     var match = new Match(2, 501);
     var player = new Player("Andy");
     match.StartNewLeg();
     match.StartNewLeg();
     match.StartNewLeg();
 }
Exemplo n.º 6
0
        public void ICanAddAPlayerToAMatch()
        {
            var match = new Match(7, 501);
            var player = new Player("Andy");
            match.AddPlayer(player);

            Assert.AreEqual(1, match.Players.Count);
            Assert.AreEqual("Andy", match.Players.FirstOrDefault().Key.Name);
        }
Exemplo n.º 7
0
        public void ICanAddALegWonToAPlayer()
        {
            var match = new Match(7, 501);
            var player = new Player("Andy");
            match.AddPlayer(player);

            var numberOfLegsWon = match.AddLegWonToPlayer(player);

            Assert.AreEqual(1, numberOfLegsWon);
        }
Exemplo n.º 8
0
        public void APlayerCanHaveAVisitAndSeeTheirScoreChange()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);
            var visit = new Visit(player, 100);

            var newScore = leg.Visit(visit);

            Assert.AreEqual(401, newScore);
        }
Exemplo n.º 9
0
        public void AddPlayer(Player player)
        {
            if (player.Name == null || player.Name == string.Empty)
                throw new Exception("A player must have a name.");
            if (player.Name.Count() > 10)
                throw new Exception("A players name cannot exceep 10 characters");
            if (Players.Where(p => p.Name == player.Name).Count() > 0)
                throw new Exception("Duplicate player added to leg.");

            player.Score = StartScore;
            Players.Add(player);
        }
Exemplo n.º 10
0
        public void ICanStartANewLeg()
        {
            var match = new Match(7, 501);
            var player = new Player("Andy");
            match.AddPlayer(player);
            var player2 = new Player("Arthur");
            match.AddPlayer(player2);

            var leg = match.StartNewLeg();

            Assert.AreEqual(2, leg.Players.Count);
            Assert.AreEqual(501, leg.StartScore);
        }
Exemplo n.º 11
0
        public void AnErrorIsThronWhenAPlayerReaches0WithAnImpossibleCheckout()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);
            var visit = new Visit(player, 100);
            var checkoutVisit = new Visit(player, 101);

            leg.Visit(new Visit(player, 100));//401
            leg.Visit(new Visit(player, 100));//301
            leg.Visit(new Visit(player, 100));//201
            leg.Visit(new Visit(player, 39));//162
            leg.Visit(new Visit(player, 162));
        }
Exemplo n.º 12
0
        public void APlayersScoreCanReachExacly0()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);
            var visit = new Visit(player, 100);
            var checkoutVisit = new Visit(player, 101);

            leg.Visit(visit);//401
            leg.Visit(visit);//301
            leg.Visit(visit);//201
            leg.Visit(visit);//101
            var score = leg.Visit(checkoutVisit);//1 = bust, therefore 101

            Assert.AreEqual(0, leg.Players[0].Score);
        }
Exemplo n.º 13
0
        public void APlayersScoreRemainsTheSameWhenTheirOverallScoreGoBelow2()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);
            var visit = new Visit(player, 100);

            leg.Visit(visit);//401
            leg.Visit(visit);//301
            leg.Visit(visit);//201
            leg.Visit(visit);//101
            var score = leg.Visit(visit);//1 = bust, therefore 101

            Assert.AreEqual(101, leg.Players[0].Score);
        }
Exemplo n.º 14
0
 public void AnErrorIsThrownWhenAnInvalidScoreIsAddedToAVisit()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, 175);
 }
Exemplo n.º 15
0
 public bool HasPlayerWon(Player player)
 {
     if (player.Score == 0)
         return true;
     return false;
 }
Exemplo n.º 16
0
 public void AnErrorIsThrownIfAPlayerHasAScoreLessThan0()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, -1);
 }
Exemplo n.º 17
0
        public int AddLegWonToPlayer(Player player)
        {
            var playerEntry = Players.Where(p => p.Key.Name == player.Name).FirstOrDefault();

            return playerEntry.Value.Value += 1;
        }
Exemplo n.º 18
0
        public void ICannotAddAPlayerToALegWithoutAName()
        {
            var leg = new Leg(501);
            var player = new Player(null);

            leg.AddPlayer(player);
        }
Exemplo n.º 19
0
 public void AnErrorIsThrownIfAPlayerHasAScoreHigherThan180()
 {
     var player = new Player("Andy");
     var visit = new Visit(player, 181);
 }
Exemplo n.º 20
0
        public void ICannotAddAPlayerToALegWithANameLongerThan10Characters()
        {
            var leg = new Leg(501);
            var player = new Player("12345678910");

            leg.AddPlayer(player);
        }
Exemplo n.º 21
0
        public void ICannotAddAPlayerToALegWithANameAsEmptyString()
        {
            var leg = new Leg(501);
            var player = new Player("");

            leg.AddPlayer(player);
        }
Exemplo n.º 22
0
        public void ICannotAdd2PlayersToALegWithTheSameName()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");

            leg.AddPlayer(player);
            leg.AddPlayer(player);
        }
Exemplo n.º 23
0
        public void ICanAddAPlayerToALeg()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");

            leg.AddPlayer(player);

            Assert.AreEqual(1, leg.Players.Count);
            Assert.AreEqual("Andy", leg.Players[0].Name);
            Assert.AreEqual(501, leg.Players[0].Score);
        }
Exemplo n.º 24
0
        public void ICanCheckIfTheLegHasBeenWonWhenPlayerHasWon()
        {
            var leg = new Leg(501);
            var player = new Player("Andy");
            leg.AddPlayer(player);

            leg.Visit(new Visit(player, 100));//401
            leg.Visit(new Visit(player, 100));//301
            leg.Visit(new Visit(player, 100));//201
            leg.Visit(new Visit(player, 100));//101
            leg.Visit(new Visit(player, 101));//0

            var hasWon = leg.HasPlayerWon(player);

            Assert.IsTrue(hasWon);
        }