Пример #1
0
        public void RemoveKey(int asciiCode)
        {
            GameKey keyToRemove = KeysInGame.Find(key => key.ASCIICode == asciiCode);

            MainWindow.StaticClearKey(keyToRemove);
            KeysInGame.Remove(keyToRemove);
            if (!GameOver)
            {
                UpdateGame();
            }
        }
Пример #2
0
        public void AddKey(int asciiCode, string keyStr)
        {
            if (!KeysInGame.Any(key => key.ASCIICode == asciiCode))
            {
                int keyPos = KeysInGame.Count;

                if (keyPos > 0)
                {
                    // Create min and max position from current key positions
                    int min = 0, max = KeysInGame.Max(key => key.Pos) + 2;

                    // Create full list from min to max
                    IEnumerable <int> filterableKeysInGame = Enumerable.Range(min, max);

                    // Create list of current key positions
                    IEnumerable <int> keyPositions = KeysInGame.Select(key => key.Pos).ToList();

                    // Find the first gap in keyPositions
                    keyPos = filterableKeysInGame.Except(keyPositions).First();
                }

                Random  random  = new Random();
                GameKey gameKey = new GameKey(
                    keyPos,
                    keyStr,
                    asciiCode,

                    // Generate Hue randomly
                    // Lightness is boosted (from 50% or 120) to add pastel color effect
                    // Saturation is reduced to dim colour intensities
                    HLSToRGB(random.Next(0, 240), 140, 160)
                    );
                KeysInGame.Add(gameKey);

                GameOver = false;
                MainWindow.StaticRenderKey(gameKey);
                UpdateGame();
            }
        }