示例#1
0
 private static string GetRollsOfLastFrame(Frame f)
 {
     if (f.GetRollCount() == 0) return "    ";
     if (f.GetRollCount() == 1)
     {
         if (StrikeRule.IsStrike(f[0])) return " X  ";
         return string.Format(" {0}  ", f[0].GetPin());
     }
     if (f.GetRollCount() == 2)
     {
         if (StrikeRule.IsStrike(f[0]))
         {
             if (StrikeRule.IsStrike(f[1])) return " XX ";
             return string.Format(" X{0} ", f[1].GetPin());
         }
         if (SpareRule.IsSpare(f)) return string.Format(" {0}/ ", f[0].GetPin());
         return string.Format(" {0} {1}", f[0].GetPin(), f[1].GetPin());
     }
     if (f.GetRollCount() == 3)
     {
         if (StrikeRule.IsStrike(f[0]))
         {
             if (StrikeRule.IsStrike(f[1]))
             {
                 if (StrikeRule.IsStrike(f[2])) return " XXX";
                 return string.Format(" XX{0}", f[2].GetPin());
             }
             if (SpareRule.IsSpare(f[1], f[2])) return string.Format(" X{0}/", f[1].GetPin());
             return string.Format(" X{0}{1}", f[1].GetPin(), f[2].GetPin());
         }
         if (StrikeRule.IsStrike(f[2])) return string.Format(" {0}/X", f[0].GetPin());
         return string.Format(" {0}/{1}", f[0].GetPin(), f[2].GetPin());
     }
     throw new Exception();
 }
示例#2
0
        public void LastFrame1Roll_x()
        {
            List<Roll> rolls = new List<Roll>();
            rolls.Add(new Roll(10));

            Frame f = new Frame(FrameCountRule.GetCount() - 1, rolls);
            Assert.AreEqual(" X  ", RollFormatter.GetRollsOfFrame(f));
        }
示例#3
0
        private static int CalcBonusFrame(Frame f, Frames frames)
        {
            int bonus = 0;
            int bonusCount = GetBonusCount(f);

            foreach (int pins in GetPinsAfterFrame(f, frames))
            {
                if (bonusCount == 0) return bonus;
                bonus += pins;
                bonusCount--;
            }
            return bonus;
        }
示例#4
0
 private static IEnumerable<int> GetPinsAfterFrame(Frame target, Frames frames)
 {
     bool found = false;
     foreach (Frame f in frames)
     {
         if (target == f)
         {
             found = true;
             continue;
         }
         if (!found) continue;
         foreach (int pin in f.GetPins()) yield return pin;
     }
 }
示例#5
0
文件: Frames.cs 项目: skeiya/Bowling
 public static Frames Replace(Frames old, Frame from, Frame to)
 {
     Frames frames = new Frames(old._frames.Count);
     for (int i = 0; i < old._frames.Count; i++)
     {
         if (old._frames[i] == from)
         {
             frames._frames[i] = to;
         }
         else
         {
             frames._frames[i] = old._frames[i];
         }
     }
     return frames;
 }
示例#6
0
        public static string GetRollsOfFrame(Frame f)
        {
            if (FrameCountRule.IsLastFrame(f))
            {
                return GetRollsOfLastFrame(f);
            }

            if (StrikeRule.IsStrike(f))
            {
                return "   X";
            }
            if (SpareRule.IsSpare(f))
            {
                return string.Format("{0,2}", f[0].GetPin()) + " /";
            }
            StringBuilder buf = new StringBuilder();
            foreach (int pin in f.GetPins())
            {
                buf.AppendFormat("{0,2}", pin);
            }
            return buf.ToString();
        }
示例#7
0
文件: Frame.cs 项目: skeiya/Bowling
 public static Frame Append(Frame old, Roll roll)
 {
     List<Roll> tmp = new List<Roll>(old._rolls);
     tmp.Add(roll);
     return new Frame(old.GetFrameIndex(), tmp);
 }
示例#8
0
 public static bool IsStrike(Frame f)
 {
     return IsCountMatch(f) && IsPinMatch(f);
 }
示例#9
0
 private static int SumPin(Frame f)
 {
     int sum = 0;
     foreach (int pin in f.GetPins()) sum += pin;
     return sum;
 }
示例#10
0
 private static bool IsPinMatch(Frame f)
 {
     return SumPin(f) == PinNumberRule.GetMax();
 }
示例#11
0
 private static bool IsCountMatch(Frame f)
 {
     return f.GetRollCount() == 1;
 }
示例#12
0
 private static bool IsFullLastFrame(Frame f)
 {
     if (f.GetRollCount() == 2) return SumPin(f) < PinNumberRule.GetMax();
     return f.GetRollCount() == 3;
 }
示例#13
0
        public void LastFrame3Roll_asb()
        {
            List<Roll> rolls = new List<Roll>();
            rolls.Add(new Roll(1));
            rolls.Add(new Roll(9));
            rolls.Add(new Roll(2));

            Frame f = new Frame(FrameCountRule.GetCount() - 1, rolls);
            Assert.AreEqual(" 1/2", RollFormatter.GetRollsOfFrame(f));
        }
示例#14
0
 private static int GetBonusCount(Frame f)
 {
     if (SpareRule.IsSpare(f)) return 1;
     if (StrikeRule.IsStrike(f)) return 2;
     return 0;
 }
示例#15
0
 public static bool IsFull(Frame f)
 {
     if (IsLastFrame(f)) return IsFullLastFrame(f);
     if (StrikeRule.IsStrike(f)) return true;
     return IsCountFull(f) || IsPinFull(f);
 }
示例#16
0
 private static bool IsLastFrame(Frame f)
 {
     return f.GetFrameIndex() == FrameCountRule.GetCount() - 1;
 }
示例#17
0
 public static bool IsLastFrame(Frame f)
 {
     return f.GetFrameIndex() == GetCount() - 1;
 }
示例#18
0
 private static bool IsCountFull(Frame f)
 {
     return f.GetRollCount() == 2;
 }