如何在您的网站上建立两个人的联系 [英] how to connect two people in your website

查看:114
本文介绍了如何在您的网站上建立两个人的联系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此链接上有一个名为Verbosity的游戏(这是一个有目的的游戏)
www.gwap.com

There is a game called Verbosity (it's a Game With A Purpose) and it's on this link
www.gwap.com

在游戏中,他们随机连接两个玩家进行游戏,游戏中玩家1应该向其伴侣(玩家2)描述一个单词,而玩家2应该猜测该单词.
我正在尝试建立一个类似网站的网站,但我想知道
1-我如何才能随机连接两个玩家,尽管他们不是注册用户(他们只是网站的来宾),但让他们一起玩?
2-如何使他们在私人游戏中玩,我的意思是每两个玩家都在玩自己的游戏?
3-我需要使用什么?使用ASP.Net是否足够?我需要银光吗?
谢谢

in the game they connect two players randomly to play with each other, the game is that player1 should describe a word to his partner(player2) and player2 should gues the word.
I'm trying to build a website that do something like that, but I wonder
1- how I can connect two players randomly to let them play together although they are not registered users ( they are just guests to the website )?
2- how to make them playing in private game, i mean each two players are playing their own game?
3- What would I need to use? Is it enough to use ASP.Net? Do I need silverlight?
Thanks

推荐答案

据我所知,我们有两个逻辑实体:

In my understanding we have two logic entities:

游戏:涉及两个私人玩家之间的互动

Games: involve interactivity between two players in private

玩家:网站的访问者(匿名)

Players: Visitors (anonymous) of a web site

我将从播放器入手,因为它更容易.访问者登陆您的站点,因此有必要(唯一地)识别他.最简单的解决方案是Guid,它可以用作会话参数或会话cookie(我的建议).Guid不是可为空的类型,因此任何32个零的Guid都是我们未定义的Guid.

I will start with Players because it’s easier. A visitor lands on your site and there is a need to (uniquely) identify him. The easiest solution is a Guid that can be used as a session parameter or as a session cookie (my suggestion). Guid is not a nullable type so any Guid of 32 zeros will be our undefined Guid.

拥有GUIDed访问者时,您需要一个键/值集合来将他们连接到游戏.

Having your GUIDed visitors, you need a key/value collection that will connect them to games.

场景1:每个访客一次只能玩一个游戏.Dictionary< player,game>可以胜任工作,并且可以轻松地跟踪非玩家的访客(game = undefined Guid)

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

方案2:每个访客可以同时是多个游戏的玩家.解决方案是使用Dictionary< player,List< game >>,但game = undefinedGuid将变为List.Count = 0

Scenario 2: Each visitor can be a player for many games at the same time. A Dictionary<player, List<game>> is the solution but game = undefinedGuid will become List.Count = 0

现在,让我们看看您可以使用游戏做什么.首先,您可以使用GUID来识别您的游戏.这意味着您的玩家字典对于方案1将是Dictionary< Guid,Guid>;对于方案2将是Dictionary< Guid,List< Guild >>.显然,您将需要游戏的键/值集合,例如字典< gameGuid,gameDetails>.GameDetails必须是一个类,其中包含可以定义玩家之间交互性的必要信息.在其他世界中,此类必须包含每个玩家的角色(角色1:提出要求的角色或角色2:正在猜测的角色)以及他们作为键/值集合交换的消息,其中键是玩家Guid,值是字符串消息.

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

总而言之,您将需要在global.asax中定义两个静态字典,一个用于播放器,一个用于游戏.您还将需要一个与此类似的GameDetails类(基本概念实现):

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

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 a lot of other things you can do (ie the one who guesses quits and you randomly assign another player to continue etc).

或多或少,这也是与私人房间进行asp.net聊天的方法.找到并检查一个简单的asp.net聊天脚本的好样本,查看其逻辑和实现,并使它们适用于上述内容,可能对您有所帮助.此外,您可以将聊天脚本扩展为支持私人房间,并拥有两个应用程序,而不是一个.

More or less this is also the way to make an asp.net chat with private rooms. It may be helpful for you to find and check a good sample of a simple asp.net chat script, see the logic and the 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.

无需多说,asp.net对于您的项目来说绰绰有余.您需要考虑的是,如果您无法控制应用程序池的回收,那么您还需要一个持久层,否则您可能会丢失字典.

Needless to say that asp.net is more than enough for your project. What you have to take in account is that if you cannot control you application pool recycling you will also need a persistence layer otherwise you may loose your dictionaries.

如果您需要更多帮助,请告诉我.

If you need more help just let me know.

这篇关于如何在您的网站上建立两个人的联系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆