コード例 #1
0
        public void StartTheReplay(int GameID)
        {
            Player        player  = getPlayerFromLobbyContext();
            List <Player> players = databaseHandler.GetPlayersOfTheGame(GameID);

            //put the player on top of the list
            foreach (var item in players)
            {
                if (item.UserName == player.UserName)
                {
                    Player i = item;
                    players.Remove(i);
                    players.Insert(0, i);
                }
            }

            Game.Game Game = new Game.Game(gameID, players, databaseHandler);
            Game.Deck  = databaseHandler.GetDeck(GameID);
            Game.moves = databaseHandler.GetMoves(player.Game.GameID); //GameID: Chosen Game to play

            foreach (var item in players)                              //
            {
                playersInReplay.Add(item);
                item.Game = Game;
            }

            player.ILobbyCallback.NotifyRePlayGameStarted();
        }
コード例 #2
0
        public void SendMessageGame(string message)
        {
            Player player = getPlayerFromGameContext();

            Game.Game game = player.Game;

            game.SendMessage(player, message);
        }
コード例 #3
0
        public void SubscribeToReplayGameEvents(string userName)
        {
            IGameCallback clientCallbackGame = OperationContext.Current.GetCallbackChannel <IGameCallback>();
            Player        player             = playersOnline.Find(x => x.UserName == userName);

            player.IGameCallback = clientCallbackGame;
            Game.Game game = player.Game;
            game.StartGameReplay(player);
        }
コード例 #4
0
        public void ChooseNotToPlayCard()
        {
            Player player = getPlayerFromGameContext();

            Game.Game game = player.Game;

            //game.moves.Add((new Move(player.UserName, game.GameID, Move.Types.Keep)));
            game.ChooseNotToPlayCard(player);
        }
コード例 #5
0
        public bool TryPlayCard(Card card)
        {
            Player playerWhoWantsToPlayACard = getPlayerFromGameContext();

            Game.Game game = playerWhoWantsToPlayACard.Game;

            //game.moves.Add((new Move(playerWhoWantsToPlayACard.UserName, game.GameID, card, Move.Types.Play)));

            return(game.TryPlayCard(playerWhoWantsToPlayACard, card));
        }
コード例 #6
0
        public void TakeCards()
        {
            Player player = getPlayerFromGameContext();

            Game.Game game = player.Game;

            if (player == player.Game.CurrentPlayer)
            {
                //game.moves.Add((new Move(player.UserName, game.GameID, Move.Types.Take)));
                game.GiveCardsToPlayer(player);
            }
        }
コード例 #7
0
        // TODO use password
        public void SubscribeToGameEvents(string userName)
        {
            IGameCallback clientCallbackGame = OperationContext.Current.GetCallbackChannel <IGameCallback>();
            Player        player             = playersOnline.Find(x => x.UserName == userName);

            player.IGameCallback = clientCallbackGame;
            Game.Game game = player.Game;

            foreach (Player otherPlayers in game.Players)
            {
                if (otherPlayers.IGameCallback == null)
                {
                    return;
                }
            }
            game.StartGame();
        }
コード例 #8
0
        public void EndGame()
        {
            Game.Game game = getPlayerFromGameContext().Game;

            if (!game.hasGameEnded()) //Otherwise we are sending EndOfTheGame(null) to the winner
            {
                foreach (var player in game.Players)
                {
                    player.IGameCallback.EndOfTheGame(null);
                }
            }
            ////who won ?
            //foreach (var player in getPlayerFromGameContext().Game.Players)
            //{
            //    if (player != getPlayerFromGameContext())
            //    {
            //        player.IGameCallback.EndOfTheGame(null); //insert the winner
            //    }
            //    databaseHandler.AddGamesPlayed(player.UserName);
            //}
            //databaseHandler.AddPlayerWon();
        }
コード例 #9
0
        public void StartGame()
        {
            Player host = getPlayerFromLobbyContext();

            if (host.Party == null)
            {
                Debug.WriteLine($"{host.UserName} tried to start a game but was not in a party");
                return;
            }

            if (host != host.Party.Host)
            {
                Debug.WriteLine($"{host.UserName} tried to start a game but was not host");
                return;
            }

            if (host.Party.Players.Count >= 2 && host.Party.Players.Count <= 4)
            {
                gameID++;
                Game.Game Game = new Game.Game(gameID, host.Party.Players, databaseHandler);
                games.Add(Game);
                foreach (Player partyMember in host.Party.Players)
                {
                    partyMember.Game = Game;
                    //Everyone will be notified except host who initated this function
                    if (partyMember != host)
                    {
                        partyMember.ILobbyCallback.NotifyGameStarted();
                    }
                }
            }
            else
            {
                Debug.WriteLine($"{host.UserName} tried to start a game but party did not have enough players: {host.Party.Players.Count}");
                return;
            }
        }