Ejemplo n.º 1
0
        /// <summary>
        /// Gets the current game score e.g. "30","love", "deuce","" or "adv","". If it's in a tie break, returns like "5","4"
        /// </summary>
        private string[] GetLastGameScore(IConsistsOf match)
        {
            // refer to the diagram to see how each GetSubFrames goes one deeper into the scoring tree
            if (match.GetSubFrames().Count == 0)
            {
                return new string[] { "", "" }
            }
            ;                                             // no play yet
            var set = match.GetSubFrames().Last()         // WinnerGetsPoint of last set
                      .GetSubFrames().First()             // switch
                      .GetSubFrames().First();            // either set or WinnerGetsPoint of tiebreak

            if (set.GetType() == typeof(Frame))           // its a set
            {
                return
                    (TranslateGameScore(
                         set.GetSubFrames().Last()        // WinnerGetsPoint of last game
                         .GetSubFrames().First()          // last game
                         .GetScore()));
            }
            else // it was a tiebreak
            {
                return
                    (set.GetSubFrames().First()           // tiebreak
                     .GetScore()
                     .Select(n => n.ToString()).ToArray());
            }
        }
Ejemplo n.º 2
0
        public void TestGetSubFrames()
        {
            this.frame.setIsFrameCompleteLambda((frameNumber, nPlays, score) => nPlays == 2);
            IConsistsOf        frame = this.frame;
            List <IConsistsOf> L     = frame.GetSubFrames();

            Assert.AreEqual(1, L.Count);
            frame.Ball(0, 3);
            L = frame.GetSubFrames();
            Assert.AreEqual(2, L.Count);
        }
Ejemplo n.º 3
0
        public Bowling()
        {
            // standard rules game
            // This section of code is generated manually from the diagram
            // Go change the diagram first where you can reason about the logic, then come here and make it match the diagram
            // Note following code uses the fluent pattern - every method returns the this reference of the object it is called on.
            scorerEngine = new Frame("game")
                           .setIsFrameCompleteLambda((gameNumber, frames, score) => frames == 10)
                           .WireTo(new Bonuses("bonus")
                                   .setIsBonusesCompleteLambda((plays, score) => score < 10 || plays == 3)
                                   .WireTo(new Frame("frame")
                                           .setIsFrameCompleteLambda((frameNumber, balls, pins) => frameNumber < 9 && (balls == 2 || pins[0] == 10) || (balls == 2 && pins[0] < 10 || balls == 3))
                                           .WireTo(new SinglePlay("SinglePlay")
                                                   )));



            consolerunner = new ConsoleGameRunner("Enter number pins:", (pins, scorer) => scorer.Ball(0, pins))
                            .WireTo(scorerEngine)
                            .WireTo(new Scorecard(
                                        "-------------------------------------------------------------------------------------\n" +
                                        "|F00|F01|F10|F11|F20|F21|F30|F31|F40|F41|F50|F51|F60|F61|F70|F71|F80|F81|F90|F91|F92|\n" +
                                        "|    ---+    ---+    ---+    ---+    ---+    ---+    ---+    ---+    ---+    ---+----\n" +
                                        "|  T0-  |  T1-  |  T2-  |  T3-  |  T4-  |  T5-  |  T6-  |  T7-  |  T8-  |    T9-    |\n" +
                                        "-------------------------------------------------------------------------------------\n")
                                    .WireTo(new ScoreBinding <List <List <string> > >("F",
                                                                                      () => TranslateFrameScores(
                                                                                          scorerEngine.GetSubFrames().Select(f => f.GetSubFrames().Select(b => b.GetScore()[0]).ToList()).ToList())))
                                    .WireTo(new ScoreBinding <List <int> >("T",
                                                                           () => scorerEngine.GetSubFrames().Select(sf => sf.GetScore()[0]).Accumulate().ToList()))
                                    );
        }
Ejemplo n.º 4
0
        // uncomment to run Bowling

        /*
         * static void Main(string[] args)
         * {
         *  new Tennis().Run();
         * }
         */



        // Following two functions know how to get scores from the tree structure



        /// <summary>
        /// Gets all the set scores as a List e.g. int[] { 6, 4}, {5, 7}, {6, 2}, {8, 6}
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        private List <int[]> GetSetScores(IConsistsOf match)
        {
            // note: to understand following code, see wiring diagram of the application - you are reaching in through the match and the first WinnerGetsOnePoint objects using GetSubFrames to get the Sets
            return(match.GetSubFrames()                     // list of WinnerGetsOnePoint for sets (this just gives the winner of the set e.g. 1,0
                   .Select(sf => sf.GetSubFrames().First()) // map to actual set Frames so we can get the set scores
                   .Select(s => s.GetScore())               // get the scores from the sets
                   .ToList());
        }
Ejemplo n.º 5
0
 List <IConsistsOf> IConsistsOf.GetSubFrames()
 {
     return(downStreamFrame.GetSubFrames());
 }
Ejemplo n.º 6
0
 // get a list of lists of frame ball scores
 List <List <int> > ITestBowling.GetFrameThrowScores()
 {
     // extract the individual ball scores from the score tree
     return(scorerEngine.GetSubFrames().Select(f => f.GetSubFrames().Select(b => b.GetScore()[0]).ToList()).ToList());
 }
Ejemplo n.º 7
0
        // used only for unit tests



        int ITestTennis.NSets()
        {
            return(match.GetSubFrames().Count());
        }