简体   繁体   中英

How to press a button to hide the other browser's button in ASP.NET (button.Visible)

Suppose we have two browsers opened, and two players are connected to each other playing the same game on 2 different browsers. The game state is recorded by Session variables. When the game is done, the last page pops up with 3 buttons, rematch, play with another player, and disconnect. How can I build a solution to give first come first serve opportunity for the first person to press any of the three buttons.

So player 1 presses rematch button, under the event handler, it is going to make button2 and button3 invisible for player 1's session, but should also make player 2's button invisible as well. How can I allow player 1 to make player 2's button2 and button3 invisible?

So to sum up, player 1 presses a button to hide 2 buttons, that forces player 2's buttons to hide. Player 2 has not made a move yet.

I'd create a new table in your database, let's call it 'GameOverStatus'. This table should contain the following fields: GameID, FirstPlacePlayerId, SelectedButtonIndex.

It's important to have a unique ID for every game. This GameID should be passed to all players of the current game. When the first player arrives at the "Game Over" screen, query GameOverStatus table in the DB using the current GameID. If there are no matches, we know the current player is the first to arrive: insert GameOverStatus record with GameID and PlayerID. After player 1 clicks a button (rematch, player another, etc), update the GameOverStatus record in the db with the correct SelectedButtonIndex.

The subsequent players will arrive on this page and the same action will occur: check GameOverStatus. The only difference is now there will be a record. Read the record, then based on SelectedButtonIndex, configure the UI to to show/hide buttons as you wish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM