How to connect two people on your site

There is a game called Verbosity (this is a game with a goal) and it is at this link
www.gwap.com

in the game they connect two players randomly to play with each other, the game consists in the fact that player1 must describe the word to his partner (player2), and player2 must take the word.
I am trying to create a website that will do something similar, but I'm curious
1- how can I accidentally connect two players so that they can play together, although they are not registered users (they are just guests on the site)?
2. How to make them play in a private game, I mean that each of the two players plays a game?
3. What do I need to use? Is ASP.Net enough to use? Do I need Silverlight?
Thanks

+8
c # web
source share
6 answers

In my understanding, we have two logical entities:

Games: engage interactivity between two players in a private

Players: website visitors (anonymous)

I will start with the players, because it will be easier. The visitor lands on your site, and there is a need to (unambiguously) identify it. The simplest solution is a guide that can be used as a session parameter or as a session cookie (my suggestion). Guid is not a null type, so any Guid of 32 zeros will be our undefined Guid.

Having your GUID visitors, you need a collection of keys / values ​​that will connect to them.

Scenario 1: Each visitor can be a player in only one game at a time. The <player, game> dictionary can do the job, and visitors who are not players can be easily traced (game = undefined Guid)

Scenario 2: Each visitor can be a player for many games simultaneously. The Dictionary <player, List <game β†’ is the solution, but game = undefinedGuid will become List.Count = 0

Now let's see what you can do with games. First of all, you can use the GUID to identify your games. This means that your game dictionary will be Dictionary <Guid, Guid> for scenario 1 or Dictionary <Guid, List <Guild β†’ for scenario 2. Obviously, you need a collection of keys / values ​​for games, say, in the form of Dictionary <gameGuid, gameDetails >. GameDetails should be a class containing the necessary information that can determine interactivity between players. In other worlds, this class should include the role of each player (role 1: the one who asks or role 2: the one who guesses), and the messages that they exchange, as a collection of keys / values, where the key is the player. Guid and value string message.

To summarize, you will need two static dictionaries defined in your global.asax, one for players and one for games. You will also need a GameDetails class similar to this (basic concept):

class GameDatails { public Guid Role1 { get; set; } // holds the guid of the player who asks public Guid Role2 { get; set; } // holds the guid of the player who guesses public List<KeyValuePair<Guid, string>> Messages; // holds the player/message pairs public GameDetails(Guid role1, Guid role2) { this.Role1 = role1; this.Role2 = role2; this.Message = new List<KeyValuePair<Guid, string>>(); } } 

Adding and removing players is easy as well as games (players are connected to games).

There are many other things that you can do (i.e., someone who realizes the completion of work, and you arbitrarily assign another player to continue, etc.).

More or less, it is also a way to make asp.net chat with private rooms. You may find it useful to find and test a good sample of a simple asp.net script chat, see the logic and implementation, and adapt them to the above. In addition, you can extend the chat script to support private rooms and have two applications instead of one.

Needless to say, asp.net is more than enough for your project. What you have to consider is that if you cannot control the reprocessing of the application pool, you will also need a persistence level, otherwise you may lose your dictionaries.

If you need more help, just let me know.

+3
source share

1- how can I accidentally connect two players so that they can play together, although they are not registered (they are just guests on the site)?

There is nothing magical about a registered user. ASP.NET can monitor the status of anonymous users.

2- how to make them play in a private game, I mean that every two players play their own game?

You just need to keep track of which two users are playing together. It's as simple as storing SessionIDs

3- What do I need to use? Is ASP.Net enough to use? Do I need Silverlight?

Don’t go to Silverlight, you don’t need it, and I believe that Microsoft is abandoning it in favor of HTML5. In addition, its share is about 60%, while Flash is about 100%, so fewer people will be able to use your site if you follow the Silverlight connection plan.

As others have said, your idea can be implemented using a combination of AJAX on the client side and the ASP.NET server side. I recommend jQuery for your client side code, this makes JavaScript and DOM manipulation easy.

Last, see http://browserquest.mozilla.org/ and an example of what you can accomplish without plugins in modern browser technology.

+2
source share

I think that if two people access your site, they can access the data separately and play the game independently.

To control the number of concurrent users on a site, you need to create an application state variable and store two selected user identifiers in it.

Each time a user tries to play a game, you should check if his identifier exists in the Application State variable or not, if it exists, then he allows it differently.

Of course you need to write a lot of code for

  • add / remove userid to the Application State variable in the Global.ascx file
  • implement authentication to find out who the user is and user checks.
  • if you want them to automatically exit after a while (inactive / fixed), you need to write the code in the Session_End event of the Global.ascx file.

Let me know more details if you want a specific answer.

Create a class GameSession {int gameid; string player1; string player2}

suppose there is only one game and 2 max users

User registration process: if the first user visits your site, check if the user is registered, register his user ID and get his user ID from the table, if the guest generates a random key (guid) or sets him a unique key (uniquenickname).

Government management: create an object of this class, assign gameid = 1 and assign player1 = a unique user key. Create a collection of a GameSession object, say GameSessions, add GameSession to GameSessions Keep GameSessions in application state.

Next time, if another user logs in, perform the same user registration process. Check the empty slot (empty player2) in GameSessions, if it is found, assign this user to the first or selected empty GameSessions slot. Now this GameSession is ready for service.

Save the object back to the application state.

Allow user to play game

Write negative cases for the above scenarios.

That way you can do it.

+1
source share

ASP.NET serveride and Ajax (javascript) on the client are enough to accomplish this.

Roughly speaking, you want to configure the client to poll the server for information at a given interval. The server will respond to status updates that the client is responding to.

You give customers unique characters, and the server keeps track of which tokens play together. You will want to use some kind of database to manage pending state updates in games.

Talk example:

Client: Join

Server: registration, token: 55164145

Client: update 55164145

Server: Idle, Waiting for the Enemy

Client: update 55164145

Server: Opponent found, "Anonymous user 31"

Client: update 55164145

Server: Describe "Flower"

Client: update 55164145

Server: Awaiting Description

Client: Send-Description 55164145, "Plant with petals"

Server: Accepted-Description

Client: update 55164145

Server: Waiting for the Adversary

Client: update 55164145

Server: Enemy Disabled

You get the idea.

+1
source share

Use SingleIR to connect two users via javascript running in a web browser

http://signalr.net/

+1
source share

I would recommend using NodeJS for this. Go to http://nodejs.org/ download and install

Now it works fine on Windows (where I use it), as well as on Linux, and you can easily create the appropriate microsite.

The online book http://www.nodebeginner.org/ will help you speed things up quickly.

+1
source share

All Articles