コード例 #1
0
        public Game()
        {
            Marbles = new List <Marble>();
            var initialMarble = new Marble {
                Value = 0
            };

            CurrentMarbleIndex = 0;
            Marbles.Add(initialMarble);
        }
コード例 #2
0
        public int AddMarble(int marbleValue)
        {
            if (marbleValue % 23 == 0)
            {
                var resultingPoints = marbleValue;

                var secondMarbleIndex = CounterClockwiseOffset(7);
                var secondMarble      = Marbles[secondMarbleIndex];
                resultingPoints   += secondMarble.Value;
                CurrentMarbleIndex = secondMarbleIndex;
                //var nextCurrentIndex = ClockwiseOffset(1);
                //CurrentMarbleIndex = nextCurrentIndex;// Marbles[nextCurrentIndex];
                Marbles.RemoveAt(secondMarbleIndex);

                if (CurrentMarbleIndex == Marbles.Count)
                {
                    System.Console.WriteLine("wrapped");
                    CurrentMarbleIndex = 0;
                }

                return(resultingPoints);
            }
            else
            {
                var nextIndex = NextMarbleIndex();
                var newMarble = new Marble()
                {
                    Value = marbleValue
                };

                Marbles.Insert(nextIndex, newMarble);

                CurrentMarbleIndex = nextIndex;

                return(0);
            }
        }