コード例 #1
0
ファイル: GameHub.cs プロジェクト: NLyapin/Egghead-AngularJS
        private bool StartGame(Player player)
        {
            if (player != null)
            {
                Player player2;
                var game = GameState.Instance.FindGame(player, out player2);
                if (game != null)
                {
                    Clients.Group(player.Group).buildBoard(game);
                    return true;
                }

                player2 = GameState.Instance.GetNewOpponent(player);
                if (player2 == null)
                {
                    Clients.Caller.waitingList();
                    return true;
                }

                game = GameState.Instance.CreateGame(player, player2);
                game.WhosTurn = player.Id;

                Clients.Group(player.Group).buildBoard(game);
                return true;
            }
            return false;
        }
コード例 #2
0
 public Player GetOpponent(Player player, Game game)
 {
     if (game.Player1.Id == player.Id)
     {
         return game.Player2;
     }
     return game.Player1;
 }
コード例 #3
0
        public Game CreateGame(Player player1, Player player2)
        {
            var game = new Game()
                {
                    Player1 = player1,
                    Player2 = player2,
                    Board =  new Board()
                };
            var group = Guid.NewGuid().ToString("d");
            games[group] = game;

            player1.IsPlaying = true;
            player1.Group = group;
            
            player2.IsPlaying = true;
            player2.Group = group;

            Groups.Add(player1.ConnectionId, group);
            Groups.Add(player2.ConnectionId, group);

            return game;
        }
コード例 #4
0
ファイル: GameHub.cs プロジェクト: NLyapin/Egghead-AngularJS
 private void StoreMatch(Player player, Card card)
 {
     player.Matches.Add(card.Id);
     player.Matches.Add(card.Pair);
 }
コード例 #5
0
        public Game FindGame(Player player, out Player opponent)
        {
            opponent = null;
            if (player.Group == null)
            {
                return null;
            }

            Game game;
            games.TryGetValue(player.Group, out game);
            if (game != null)
            {
                if (player.Id == game.Player1.Id)
                {
                    opponent = game.Player1;
                    return game;
                }
                opponent = game.Player1;
                return game;
            }
            return null;
        }
コード例 #6
0
 public Player GetNewOpponent(Player player)
 {
     return players.Values.FirstOrDefault(x => !x.IsPlaying && x.Id != player.Id);
 }
コード例 #7
0
 public Player CreatePlayer(string userName)
 {
     var player = new Player(userName, GetMD5Hash(userName));
     players[userName] = player;
     return player;
 }