private void ChangeToGamePage() { InGameMessage im = new InGameMessage(); im.GameState = 0; im.Action = "start"; App.Current.SignalRHub.InGameMessageCall(App.Current.CurrentGame, im); App.Current.SignalRHub.SignalRServerNotification -= new SignalRServerHandler(SignalRHub_SignalRServerNotification); Frame.Navigate(typeof(GamePlayPage)); Debug.WriteLine("START GAME!"); }
public async virtual void InGameMessageCall(Game game, InGameMessage im) { // Post message to Server Chatroom. await SignalRGameHub.Invoke("InGameMessageCall", game, im); }
private void fire_Button_Click(object sender, RoutedEventArgs e) { InGameMessage im = new InGameMessage(); im.Action = "fire"; im.Hits = _hits; App.Current.SignalRHub.InGameMessageCall(App.Current.CurrentGame, im); }
private void SpheroLost_Button_Click(object sender, RoutedEventArgs e) { InGameMessage im = new InGameMessage(); im.Action = "lost"; App.Current.SignalRHub.InGameMessageCall(App.Current.CurrentGame, im); }
public void InGameMessageCall(Game game, InGameMessage im) { //send start message //Check to see if timer is up //Check to see what states match //Correct State //check to see what is the command //Valid Command Game g = new Game(); g = InPlayGames.Find(fg => fg.GameId.Equals(game.GameId) && fg.DateCreated.Equals(game.DateCreated));// && (fg.DronePlayer.UserId.Equals(user.UserId) || fg.SpheroPlayer.UserId.Equals(user.UserId))); int place = InPlayGames.FindIndex(fg => fg.GameId.Equals(game.GameId) && fg.DateCreated.Equals(game.DateCreated)); if (game.GameState != g.GameState) { //User is in the wrong state send inGameMessage with the correct state and Game object } else { switch (game.GameState) { case 0: //Actions - update GameObject - start Time, targeted, end if (im.Action == "target") { im.Action = "targeted"; //if I'm a sphero display Warning game.GameState = 1; InPlayGames.RemoveAt(place); InPlayGames.Insert(place, game); Clients.Group(game.GameId).inGameMessage(game, im); } break; case 1: if (im.Action == "lost") { im.Action = "lost"; //if I'm a sphero display Warning game.GameState = 0; InPlayGames.RemoveAt(place); InPlayGames.Insert(place, game); Clients.Group(game.GameId).inGameMessage(game, im); } if (im.Action == "fire") { im.Hits++; if (im.Hits == game.MaxHits) { im.Action = "end"; //_serverTimer.Stop(); game.Winner = game.DronePlayer; game.GameState = 2; InPlayGames.RemoveAt(place); AllGamesList.Add(game); //AvailableGames.Insert(place, game); Clients.Group(game.GameId).inGameMessage(game, im); //find game replace.. //send end message im.Action end, RemovePlayer(game.DronePlayer, game.GameId); RemovePlayer(game.SpheroPlayer, game.GameId); } else { im.Action = "hit"; //if I'm a sphero display Warning game.GameState = 0; InPlayGames.RemoveAt(place); InPlayGames.Insert(place, game); Clients.Group(game.GameId).inGameMessage(game, im); } } break; case 2: break; } //targeted - change state of Game Object (insert it into GameList) // } //Debug.WriteLine("Server is in Start Method"); //Clients.Group(game.GameId).inGameMessage(game, im); }
public void JoinGame(User user, Game game) { ServerMessage jm = new ServerMessage(); jm.Command = 3; int a = -1; a = AvailableGames.FindIndex(fg => fg.GameId.Equals(game.GameId) && fg.DateCreated.Equals(game.DateCreated) && (fg.DronePlayer.UserId.Equals(user.UserId) || fg.SpheroPlayer.UserId.Equals(user.UserId))); bool triggerStart = false; if (a > 0 ) { game.GameStatus++; if (game.GameStatus <= 2) { jm.Action = "join"; jm.Message = user.UserName + " has entered the Lobby"; AvailableGames.RemoveAt(a); AvailableGames.Insert(a, game); Groups.Add(Context.ConnectionId, game.GameId); Clients.Group(game.GameId).lobbyMessage(user, game, jm); } else { if (game.GameStatus==3) { jm.Action = "ready"; jm.Message = user.UserName + " is Ready to Start the game. "; AvailableGames.RemoveAt(a); AvailableGames.Insert(a, game); //Groups.Add(Context.ConnectionId, game.GameId); Clients.Group(game.GameId).lobbyMessage(user, game, jm); } if (game.GameStatus == 4) { InGameMessage igm = new InGameMessage(); igm.Action = "start"; game.GameState = 0; /* if (InPlayGames.Count == 0) //No Games Are Running { //Start Timer ...for duration of the game //on every tick check all the games end time === startime + timeInterval of maxtime*60*1000 //if curtime < endtime Do nothing... if curtime> endtime then send end event! for that game with igm and keep going... startServerTimer(game); }*/ AvailableGames.RemoveAt(a); InPlayGames.Add(game); //Groups.Add(Context.ConnectionId, game.GameId); Clients.Group(game.GameId).inGameMessage(game, igm); } } } else { if (AvailableGames.ElementAt(a).GameId != game.GameId) { jm.Message = "ERROR - TRIED TO JOIN A GAME THAT DOESN'T EXIST"; //game not in list Debug.WriteLine("ERROR - TRIED TO JOIN A GAME THAT DOESN'T EXIST"); } else { jm.Message = "ERROR - Tried to Join a game you weren't invited to"; //game not in list Debug.WriteLine("ERROR - WRONG USER, trying to access game"); } } }