示例#1
0
        public async Task FindGame()
        {
            CurrentPlayer.Status = PlayerStatus.FindingGame;
            await Clients.Client(CurrentPlayer.Id).SendAsync("AddedToQueue");

            if (chessService.Players.Count(p => p.Status == PlayerStatus.FindingGame) > 1)
            {
                var players = chessService.Players.Where(p => p.Status == PlayerStatus.FindingGame).Take(2).ToList();
                var game    = chessService.StartGame(players[0], players[1]);
                game.GameFinished += (winner, looser) => {
                    // await Clients.Client(winner.Id).SendAsync("IsWinner");
                    // await Clients.Client(looser.Id).SendAsync("IsLooser");
                };
                foreach (var player in players)
                {
                    player.Status = PlayerStatus.PlayingGame;
                    Shared.Game clientGame = new Shared.Game {
                        Pieces = game.Pieces.Select(p => new Shared.Piece {
                            Color    = p.Color,
                            Position = p.Position,
                            Type     = Enum.Parse <PieceType>(p.GetType().Name)
                        }).ToList(),
                        PlayerColor = player.Color,
                        PlayerId    = player.Id,
                        Status      = player.Color == PieceColor.White ? GameStatus.MyTurn : GameStatus.EnemyTurn
                    };
                    var _game = JsonConvert.SerializeObject(clientGame);
                    await Clients.Client(player.Id).SendAsync("StartGame", _game);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Game started is called *once* when an instance
        /// of your game is started. It's a good place to initialize
        /// your game.
        /// </summary>
        public override void GameStarted()
        {
            Virtual = new FlashTowerDefense.Shared.Game
            {
                AtDelay    = (h, i) => this.ScheduleCallback(() => h(), i).Stop,
                AtInterval = (h, i) => this.AddTimer(() => h(), i).Stop,
            };

            // You can explicitly setup how many users are allowed in your game.
            MaxUsers = 8;

            Virtual.GameStarted();
        }
示例#3
0
 public override void GameClosed()
 {
     Virtual.GameClosed();
     Virtual = null;
 }