Exemplo n.º 1
0
        private void StartGame(bool participant1Begins)
        {
            Sound.Play(Properties.Resources.zacatek_hry);
            gameArea.Draw();

            if (participant1Begins)
            {
                MakeFullMove(participant1, participant2.LastUsedField);
            }

            while (true)
            {
                MakeFullMove(participant2, participant1.LastUsedField);
                MakeFullMove(participant1, participant2.LastUsedField);
            }
        }
Exemplo n.º 2
0
        private async Task BeginGame(GameSettings gameSettings, PauseToken pauseToken, CancellationToken cancellationToken)
        {
            _snake    = new Snake(gameSettings.Snake);
            _gameArea = new GameArea(new Point(0, 0), new Point(gameSettings.GameAreaSize.Width, gameSettings.GameAreaSize.Height));

            _gameArea.Draw(_writerService);
            _snake.Draw(_writerService);

            SpawnNewFood();
            WriteScore();

            _highLevelEventsService.Start();

            var delayInMs = _gameSettings.GetSpeedInMs();

            while (true)
            {
                await pauseToken.WaitWhilePausedAsync();

                if (_skipAutoMove)
                {
                    _skipAutoMove = false;
                    continue;
                }

                Move(this, _lastMoveKeyPressed);

                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                await Task.Delay(delayInMs);
            }

            _highLevelEventsService.Stop();
        }
Exemplo n.º 3
0
 public void Draw(object sender, ElapsedEventArgs e)
 {
     CheckState();
     RunOnUiThread(() => gameArea.Draw());
 }