示例#1
0
        public IActionResult Play()
        {
            // Play Game
            IRandomNumberGenerator randomNumGen = new GetRandomNumber();
            Scorekeeper            keeper       = new Scorekeeper(ONE_DAY);
            Game game = new Game(randomNumGen);

            string[] team1 = new string[] { "Ian Botham", "Mike Gatting", "David Gower", "Joe Root", "Jos Buttler", "Ben Stokes",
                                            "Johnny Bairstow", "Stuart Broad", "Graham Swann", "Jofra Archer", "Jimmy Anderson" };
            string[] team2 = new string[] { "Michael Vaughan", "Alistair Cook", "Viv Richards", "Freddie Flintoff", "Geoff Miller", "Nasser Hussain",
                                            "Alex Stewart", "Darren Gough", "Bob Willis", "Phil Tuffnell", "Mike Hendrick" };

            keeper.ChangeBowler("Malcolm Marshall");
            keeper.SubmitTeam(0, team1);
            keeper.SubmitTeam(1, team2);

            Umpire umpey = new Umpire(game, keeper);

            umpey.playInnings();
            keeper.StartInnings(1);
            keeper.ChangeBowler("Ian Botham");
            umpey.playInnings();


            //// Map Scores to View Model
            PlayViewModel pvm = new PlayViewModel();

            var(r1, w1, b1, e1) = keeper.GetInningsScore(0);
            var(r2, w2, b2, e2) = keeper.GetInningsScore(1);


            pvm.runs = new int[2] {
                r1, r2
            };
            pvm.wickets = new int[2] {
                w1, w2
            };
            pvm.overs = new int[2] {
                b1, b2
            };
            pvm.extras = new int[2] {
                e1, e2
            };

            pvm.team1 = team1;
            pvm.team2 = team2;

            pvm.scores1 = new int[11];
            pvm.scores2 = new int[11];

            for (int i = 0; i < 11; i++)
            {
                pvm.scores1[i] = keeper.GetBatsmanScore(0, team1[i]);
                pvm.scores2[i] = keeper.GetBatsmanScore(1, team2[i]);
            }

            return(View(pvm));
        }
        // Simplified Interfaces expressing the Domain Model
        // (int runs, int wickets, int overs) GetInningsScore(int InningsNum) - returns a tuple run for wickets in overs
        // int runs GetBatsmanScore(BatsmanName)
        // string status GetBatsmanStatus(BatsmanName)
        // (int overs, int maidens, int runs, int wickets) GetBowlerStats(BowlerName)
        // string[] GetBatsmenNames(InningsNum)
        // string[] GetBowlerNames(InningsNum)
        // int GetNumberOfInnings()
        // void SubmitTeam(int teamID, string[] batsmenNames)
        // void ChangeBowler(int teamID, string bowlerName)
        // TODO : End of Innings - where do I put logic in keeper or card?


        public scorekeeperTests()
        {
            _keeper = new Scorekeeper(ONE_DAY);
            _keeper.SubmitTeam(0, new string[] { "Ian Botham",
                                                 "David Gower",
                                                 "Michael Vaughan",
                                                 "Kevin Pietersen",
                                                 "Freddie Flintoff",
                                                 "Jos Buttler",
                                                 "Ben Stokes",
                                                 "Johnny Bairstow",
                                                 "Stuart Broad",
                                                 "Graham Swann",
                                                 "James Anderson" });
            _keeper.ChangeBowler("Michael Holding");
        }
        void test_change_bowler()
        {
            int bowlerId = _keeper.ChangeBowler("Michael Holding");

            var(balls, maidens, runs, wickets) = _keeper.GetBowlerStats(0, "Michael Holding");
            Assert.Equal(0, balls);
            Assert.Equal(0, maidens);
            Assert.Equal(0, runs);
            Assert.Equal(0, wickets);
        }