Example #1
0
        // join a game that is awaiting players
        public async Task <GameState> JoinGame(Guid gameId)
        {
            var gameGrain = GameGrainFactory.GetGrain(gameId);

            var state = await gameGrain.AddPlayerToGame(this.GetPrimaryKey());

            this.ListOfActiveGames.Add(gameId);

            var pairingGrain = PairingGrainFactory.GetGrain(0);
            await pairingGrain.RemoveGame(gameId);

            return(state);
        }
Example #2
0
        // create a new game, and add oursleves to that game
        public async Task <Guid> CreateGame()
        {
            this.gamesStarted += 1;

            var gameId    = Guid.NewGuid();
            var gameGrain = GameGrainFactory.GetGrain(gameId);  // create new game

            // add ourselves to the game
            var playerId = this.GetPrimaryKey();  // our player id
            await gameGrain.AddPlayerToGame(playerId);

            this.ListOfActiveGames.Add(gameId);
            var name = this.username + "'s " + AddOrdinalSuffix(this.gamesStarted.ToString()) + " game";
            await gameGrain.SetName(name);

            var pairingGrain = PairingGrainFactory.GetGrain(0);
            await pairingGrain.AddGame(gameId, name);

            return(gameId);
        }
Example #3
0
        public async Task <PairingSummary[]> GetAvailableGames()
        {
            var grain = PairingGrainFactory.GetGrain(0);

            return((await grain.GetGames()).Where(x => !this.ListOfActiveGames.Contains(x.GameId)).ToArray());
        }