Пример #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));
        }
 void test_score_combinations(outcomes outcome, int runs, int wickets, int balls, int maidens, int score1, int score2)
 {
     _keeper.SubmitTeam(0, new string[] { "Ian Botham",
                                          "David Gower" });
     event_sequence(outcome);
     assert_score(runs, wickets, balls, maidens);
     Assert.Equal(score1, _keeper.GetBatsmanScore(0, "Ian Botham"));
     Assert.Equal(score2, _keeper.GetBatsmanScore(0, "David Gower"));
 }
        // 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");
        }