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); } }
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(); }
public void Draw(object sender, ElapsedEventArgs e) { CheckState(); RunOnUiThread(() => gameArea.Draw()); }