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(); }
public void SendMessageGame(string message) { Player player = getPlayerFromGameContext(); Game.Game game = player.Game; game.SendMessage(player, message); }
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); }
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); }
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)); }
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); } }
// 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(); }
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(); }
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; } }