Beispiel #1
0
        /// <summary>
        /// Проверка окончания игры.
        /// </summary>
        private void CheckGameOver()
        {
            for (int j = 0; j < GameTable.Foundations * 2; j++)
            {
                if (!_foundationViews[j].Foundation.IsFinished())
                {
                    return;
                }
            }
            // Игра окончена - выводим финальную заставку.
            // Откатываем ходы в самое начало (не сбрасывая счётчики)
            _table.RestartGame(false);
            // Показываем в фоне историю действий игрока.
            var dt = new DispatcherTimer();

            dt.Tick += (s, ee) => {
                _table.Redo();
                RefreshView();
            };
            dt.Interval = new TimeSpan(500 * 10000);
            dt.Start();
            // Запрашиваем имя игрока.
            EnterNameComponent.Show((s, ee) => {
                _table.EndGame(true);
                // Показываем
                ScoreManager.Load();
                int place   = ScoreManager.GetPlace();
                string text = (place > 0) ? "Вы на " + place + " месте в рейтинге" : "";
                HiscoreComponent.Show(ScoreManager.HiScores, text);
                dt.Stop();
                NewGame();
            });
        }
Beispiel #2
0
        public async Task EndGame()
        {
            var userMetadata = this.GetUserMetadata();

            if (userMetadata == null)
            {
                throw new Exception("Game metadata is null");
            }

            GameTableEntity game = GameTable.GetGameObject(userMetadata.GameId);

            if (game == null)
            {
                throw new Exception("Game is null!");
            }

            if (userMetadata.UserId != game.LeaderUserId)
            {
                throw new Exception("Only leader can end!");
            }

            await GameTable.EndGame(game);

            await Clients.Group(userMetadata.GameId).SendAsync("GameMetadataUpdate", JsonConvert.SerializeObject(game));

            await Clients.Group(userMetadata.GameId).SendAsync("GameEnded");
        }