Ejemplo n.º 1
0
        public void UpdateScore(BallType ballType)
        {
            if (ballType == BallType.Wicket)
            {
                BatsmanStat incomingBat = this.BattingStats.FirstOrDefault(x => !x.IsOnField && !x.IsOut);
                BatsmanStat outgoingBat = this.BattingStats.First(x => x.IsOnStrike);
                outgoingBat.Out();
                if (incomingBat != null)
                {
                    incomingBat.In();
                }

                this.BowlingStats.First(x => x.IsOnStrike).Update(BallType.Wicket, 0);
            }
            if (ballType == BallType.NoBall || ballType == BallType.Wide)
            {
                this.BowlingStats.First(x => x.IsOnStrike).Update(ballType, 1);
            }

            if (IsCurrentOverFinished())
            {
                RotateStrike();
                BowlerChange();
            }
        }
Ejemplo n.º 2
0
        public void RotateStrike()
        {
            BatsmanStat bat1 = this.BattingStats.First(x => x.IsOnStrike);
            BatsmanStat bat2 = this.BattingStats.First(x => !x.IsOnStrike && x.IsOnField);

            bat1.ToggleOnStrike();
            bat2.ToggleOnStrike();
        }
Ejemplo n.º 3
0
        public void DisplayBattingScoreCard()
        {
            Console.WriteLine("Batting Scorecard for Team : {0}", this.Team1.TeamName);
            Console.WriteLine("{0,-20}{1}{2,10}{3,10}{4,10}{5,15}", Constants.PlayerName, Constants.Score, Constants.Fours, Constants.Sixes, Constants.Balls, "Status");

            for (int i = 0; i < BattingStats.Count; i++)
            {
                BatsmanStat batsman = BattingStats[i];
                Console.WriteLine("{0}{1,-10}{2,10}{3,10}{4,10}{5,10}{6,15}", batsman.PlayerName, GetHighlighter(batsman), batsman.Score, batsman.Count4, batsman.Count6, batsman.BallsFaced, batsman.IsOut ? "Out" : "Not Out");
            }

            // Log Ball By Ball
            Console.WriteLine();
        }
Ejemplo n.º 4
0
        public string GetHighlighter(BatsmanStat batsman)
        {
            if (!batsman.IsOut)
            {
                if (batsman.IsOnStrike)
                {
                    return("**");
                }
                if (batsman.IsOnField)
                {
                    return("*");
                }
            }

            return(String.Empty);
        }
Ejemplo n.º 5
0
        public void CreateBattingOrder(Team team)
        {
            for (int i = 0; i < team.Players.Count; i++)
            {
                BatsmanStat batsman = new BatsmanStat(team.Players[i].PlayerName, 0, 0, 0, 0, false, false, false);
                if (i == 0)
                {
                    batsman.IsOnStrike = true;
                    batsman.IsOnField  = true;
                }
                if (i == 1)
                {
                    batsman.IsOnField = true;
                }

                this.BattingStats.Add(batsman);
            }
        }