How to know if two Sessions have clicked buttons over a browser game in ASP.NET C#

Rideharder

New Member
I have a problem on my browser game played by two people on different browsers. The game state is controlled by Session variables which used a Game Class and the buttons players click. At the end of the game, the players have 3 choices, either to rematch same player, to find another player, or to disconnect the game totally. If the player disconnects, the game can cleanly destroy the game object and revert all Session variables. The problem I am having is to synchronize the other two buttons the player chooses. If both players choose the same button, then the game proceeds to play again. But if one player wants a rematch and the other one wants to play again, then the disagreeing players must both find new players. I use two Session variables, PlayWithSamePlayer means that they want a rematch with the same player. and I also use ContinueChoicesMade to make sure both players choose then same option. If ContinueChoicesMade is false, then it means the two players disagreed, and is placed back into my game manager to search for another player. I can figure out how to work in my two player synchronizing method to be placed in my Game class so both player's actions can be listened to. At the moment if I run the game, When it gets to my method, it comes out as NullException. I want so that at the end of the game, one player chooses a button, and the browser waits for the other browser to click a button, then check if what they pressed is the same, and then if it is the same; the game moves on, and if what they clicked is different; the game moves on. What is the best method to synchronize the Session variables after the players have clicked rematch or find new player. Below is my method in the game class that deals with the two players and also the method call out on my aspx.cs pages.\[code\]((Game)Session["Game"]).RoundOverSynchronizing(Session);//when should I call this out? this is not apart of the game class. public void RoundOverSynchronizing(HttpSessionState player){ if (((bool)player1["PlayWithSamePlayer"]) == true && ((bool)player2["PlayWithSamePlayer"]) == true) { player1["ContinueChoicesMade"] = true; player2["ContinueChoicesMade"] = true; } else if (((bool)player1["PlayWithSamePlayer"]) == false && ((bool)player2["PlayWithSamePlayer"]) == false) { player1["ContinueChoicesMade"] = true; player2["ContinueChoicesMade"] = true; } else { player1["ContinueChoicesMade"] = false; player2["ContinueChoicesMade"] = false; }}\[/code\]
 
Back
Top