Repository: Kyome22/RunCat_for_windows
File: RunCat365/EndlessGameForm.cs (C#)

Code before:
            var sproutIndices = roads
                .Select((road, index) => { return road == Road.Sprout ? index : (int?)null; })
                .OfType<int>()
                .ToList();
            if (cat.ViolationIndices().HasCommonElements(sproutIndices))
            {
                status = GameStatus.GameOver;
                return false;
            }
            else
            {
                return true;
            }
        }

        private void UpdateRoads()
        {
            var firstRoad = roads.First();
            roads.RemoveAt(0);
            if (firstRoad == Road.Sprout)
            {
                score += 1;
                if (score > highScore)
                {
                    highScore = score;
                }
            }
            counter = counter > 0 ? counter - 1 : limit - 1;
            if (counter == 0)
            {
                var randomValue = new Random().Next(0, 27);
                var subRoads = new List<Road>();
                if (randomValue % 3 == 0)
                {
                    subRoads.Add(Road.Sprout);
                }
                if (randomValue % 9 == 0)
                {
                    subRoads.Add(Road.Sprout);
                }
                if (randomValue % 27 == 0)
                {
                    subRoads.Add(Road.Sprout);
                }
                roads.AddRange(subRoads);
                limit = subRoads.Count == 0 ? 5 : 10;
            }
            if (roads.Count < 20)
            {
                roads.Add((Road)(new Random().Next(0, 3)));
            }

Review comment (suggestion):
```suggestion
                highScore = Math.Max(score, highScore);
```

Code after:
            timer = new FormsTimer
            {
                Interval = 100
            };
            timer.Tick += GameTick;

            Initialize();

            timer.Start();
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            timer.Stop();
            timer.Dispose();

            foreach (var bitmap in catIcons.Values) bitmap.Dispose();
            foreach (var bitmap in roadIcons.Values) bitmap.Dispose();
            catIcons.Clear();
            roadIcons.Clear();
        }

        private void Initialize()
        {
            counter = JUMP_THREDHOLD;
            isJumpRequested = false;
            score = 0;
            cat = new Cat.Running(Cat.Running.Frame.Frame0);
            roads.RemoveAll(r => r == Road.Sprout);
            Enumerable.Range(0, 20 - roads.Count).ToList().ForEach(
                _ => roads.Add((Road)(new Random().Next(0, 3)))
            );
        }

        private bool Judge()
        {
            if (status != GameStatus.Playing) return false;
            var sproutIndices = roads
                .Select((road, index) => { return road == Road.Sprout ? index : (int?)null; })
                .OfType<int>()
                .ToList();
            if (cat.ViolationIndices().HasCommonElements(sproutIndices))
            {
                status = GameStatus.GameOver;
                return false;
            }
            else
            {
                return true;
            }