Beispiel #1
0
 private void generatePool()
 {
     for (Char i = 'a'; i <= 'z'; i++)
     {
         CharPool.Add(i);
     }
 }
Beispiel #2
0
        public void AddEnemy()
        {
            if (CharPool.Count == 0)
            {
                gameLevel.levelUp();
                TheForm.TimerCreateLetter.Interval = gameLevel.ENEMY_APPEAR;
                TheForm.TimerMoveEnemies.Interval  = gameLevel.ENEMY_SPEED;
                generatePool();
                if (gameLevel.LEVEL % 3 == 0)
                {
                    TheForm.BackgroundImage = GameBackground.NextImage();
                    TheForm.changeColorLabel();
                }
            }
            int  i        = Random.Next(0, CharPool.Count);
            Char selected = CharPool[i];

            CharPool.RemoveAt(i);
            Enemy enemy        = enemy = new Enemy(TheForm, findValidSpawn(), selected);
            bool  thereIsPower = false;

            foreach (Enemy e in Enemies)
            {
                if (e.Name == "SlowMotion" || e.Name == "Bonus" || e.Name == "Destroyer")
                {
                    thereIsPower = true;
                }
            }

            if (!thereIsPower && !isSlowMotionActive && gameLevel.LEVEL > 1)
            {
                int rnd = Random.Next(0, 30);
                if (rnd == 7 && gameLevel.LEVEL > 3)
                {
                    enemy = new PowerUp_SlowMotion(TheForm, findValidSpawn(), selected);
                }
                else if (rnd > 26)
                {
                    enemy = new PowerUp_Bonus(TheForm, findValidSpawn(), selected);
                }
                else if (rnd == 13 && gameLevel.LEVEL > 4)
                {
                    enemy = new PowerUp_Destroyer(TheForm, findValidSpawn(), selected);
                }
            }
            Enemies.Add(enemy);
        }
Beispiel #3
0
        public void AddEnemy()
        {
            if (CharPool.Count == 0)
            {
                gameLevel.levelUp();
                TheForm.TimerCreateLetter.Interval = gameLevel.ENEMY_APPEAR;
                TheForm.TimerMoveEnemies.Interval  = gameLevel.ENEMY_SPEED;
                generatePool();
            }
            int  i        = random.Next(0, CharPool.Count);
            Char selected = CharPool[i];

            CharPool.RemoveAt(i);
            Enemy enemy = new Enemy(TheForm, findValidSpawn(), selected);

            Enemies.Add(enemy);
            TheForm.GetControls().Add(enemy);
        }
Beispiel #4
0
        private static object Deserialize(MemoryStream ms, bool fromPool, Type type,
            DeserializeStringSpanDelegate deserializer)
        {
            var bytes = ms.GetBufferAsBytes();
            var utf8 = CharPool.GetBuffer(Encoding.UTF8.GetCharCount(bytes, 0, (int) ms.Length));
            try
            {
                var charsWritten = Encoding.UTF8.GetChars(bytes, 0, (int) ms.Length, utf8, 0);
                var ret = deserializer(type, new ReadOnlySpan<char>(utf8, 0, charsWritten));
                return ret;
            }
            finally
            {
                CharPool.ReleaseBufferToPool(ref utf8);

                if (fromPool)
                    ms.Dispose();
            }
        }
Beispiel #5
0
        public void Can_ToUtf8_and_FromUtf8_in_place_using_Span()
        {
            foreach (var test in Utf8Case.Source)
            {
                var           chars        = test.expectedString.AsSpan();
                Memory <byte> buffer       = BufferPool.GetBuffer(MemoryProvider.Instance.GetUtf8ByteCount(chars));
                var           bytesWritten = MemoryProvider.Instance.ToUtf8(chars, buffer.Span);
                var           bytes        = buffer.Slice(0, bytesWritten);

                Assert.That(bytes.Length, Is.EqualTo(test.count));
                Assert.That(bytes.ToArray(), Is.EquivalentTo(test.expectedBytes));

                Memory <char> charBuff     = CharPool.GetBuffer(MemoryProvider.Instance.GetUtf8CharCount(bytes.Span));
                var           charsWritten = MemoryProvider.Instance.FromUtf8(bytes.Span, charBuff.Span);
                chars = charBuff.Slice(0, charsWritten).Span;

                Assert.That(chars.Length, Is.EqualTo(test.expectedString.Length));
                Assert.That(chars.ToString(), Is.EqualTo(test.expectedString));
            }
        }
        private static object Deserialize(MemoryStream memoryStream, bool fromPool, Type type, DeserializeStringSpanDelegate deserializer)
        {
            var bytes = memoryStream.GetBufferAsSpan().WithoutBom();
            var chars = CharPool.GetBuffer(Encoding.UTF8.GetCharCount(bytes));

            try
            {
                var charsWritten = Encoding.UTF8.GetChars(bytes, chars);
                ReadOnlySpan <char> charsSpan = chars;
                var ret = deserializer(type, charsSpan.Slice(0, charsWritten));
                return(ret);
            }
            finally
            {
                CharPool.ReleaseBufferToPool(ref chars);

                if (fromPool)
                {
                    memoryStream.Dispose();
                }
            }
        }