//client methods public string JoinGame(string id, string name) { var game = _games.FirstOrDefault(g => g.Game.ID == id); //take this out later if (game == null) { var gamestate = CreateGame(3, new[] { "shanselman", "scottgu", "codinghorror", "billgates", "gblock", "mkristensen" }); gamestate.ID = id; game = _games.First(); } if (game != null) { var player = new Player(Context.ConnectionId) { Name = name }; _players.Add(player); game.AddPlayer(player); if (game.Game.TotalPlayers >= 2 && !game.IsStarted) game.Start(); else if(!game.IsStarted) { Clients.Group(game.Game.ID).Wait(); Clients.Client(Context.ConnectionId).Wait(); } else if (game.IsStarted) { Clients.Client(Context.ConnectionId).Waiting(); } return player.Team.Name; } throw new Exception("Game doesn't exist"); }
public void AddPlayer(Player player) { var user = _service.GetUserProfileFor(new GetUserProfileForOptions { ScreenName = player.Name }); if (user != null) { var tweets = _service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions { ScreenName = user.ScreenName, Count = 1 }); if (tweets == null || !tweets.Any()) { throw new Exception("Account is private or has no public tweets"); } player.Name = user.ScreenName; player.ImageURL = user.ProfileImageUrl; player.Game = this.Game; this.Game.AddPlayerToTeam(player); _hub.Groups.Add(player.ConnectionID, Game.ID); _hub.Clients.Client(Host).NewPlayer(new[] { Game.RedTeam, Game.BlueTeam }); } else { throw new Exception("User not found on twitter"); } }
private void InsertTestData() { var player = new Player("player1") { Name = "Player 1", Score = 25 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("Batman") { Name = "Batman", Score = 250 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("Yoda") { Name = "Yoda", Score = 2500 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("you") { Name = "you", Score = 25 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("me") { Name = "me", Score = 250 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("them") { Name = "them", Score = 2500 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("Up") { Name = "Up", Score = 250 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("Down") { Name = "Down", Score = 2500 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("Left") { Name = "Left", Score = 25 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("Right") { Name = "Right", Score = 250 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("A really really long twitter handle") { Name = "A really really long twitter handle", Score = 26008 }; GameData.Game.BlueTeam.AddPlayer(player); player = new Player("player1") { Name = "Player 1", Score = 25 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("Batman") { Name = "Batman", Score = 250 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("Yoda") { Name = "Yoda", Score = 2500 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("you") { Name = "you", Score = 25 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("me") { Name = "me", Score = 250 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("them") { Name = "them", Score = 2500 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("Up") { Name = "Up", Score = 250 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("Down") { Name = "Down", Score = 2500 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("Left") { Name = "Left", Score = 25 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("Right") { Name = "Right", Score = 250 }; GameData.Game.RedTeam.AddPlayer(player); player = new Player("A really really long twitter handle") { Name = "A really really long twitter handle", Score = 26008 }; GameData.Game.RedTeam.AddPlayer(player); }
public void RemovePlayer(Player player) { _hub.Clients.Client(Host).RemovePlayer(new[] { this.Game.RedTeam, this.Game.BlueTeam }); }
public void Guess(Player player, string name) { this.Game.MakeGuess(player, name); if (this.Game.TotalPlayers == this.Game.Guesses.Count()) { this._currentQuestionTimer.Change(500, Timeout.Infinite); } }
public void AddPlayerToTeam(Player player) { if (BlueTeam.Players.Count > RedTeam.Players.Count) { RedTeam.AddPlayer(player); } else { BlueTeam.AddPlayer(player); } }
public void MakeGuess(Player player, string name) { this.Guesses.Add(new Guess() { Player = player, Name = name}); }
public void RemovePlayer(Player player) { this.Players.Remove(player); }
public void AddPlayer(Player player) { this.Players.Add(player); player.Team = this; }
public ClientPlayer(Player player) { this.Player = player; }