Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中向不同的用户显示不同的数据_Python - Fatal编程技术网

在Python中向不同的用户显示不同的数据

在Python中向不同的用户显示不同的数据,python,Python,我正在用Python制作一个(相当)简单的纸牌游戏,我已经为游戏做好了一切准备,我只需要一种方法来处理多个用户,并向分配给他们的用户显示一些东西(手中的牌)。我已经看到一些关于Twisted的回应,但这似乎并不能解决我的问题,至少它是如何呈现的。我在找像这样的东西- 将播放器卡1打印到播放器1 将播放卡2打印到播放卡2 但是无论需要什么格式。好吧,这里最明显的答案是有一个类播放器: class Player: playercards = [] 另一种方法是为每个玩家指定一个名字:

我正在用Python制作一个(相当)简单的纸牌游戏,我已经为游戏做好了一切准备,我只需要一种方法来处理多个用户,并向分配给他们的用户显示一些东西(手中的牌)。我已经看到一些关于Twisted的回应,但这似乎并不能解决我的问题,至少它是如何呈现的。我在找像这样的东西-

将播放器卡1打印到播放器1
将播放卡2打印到播放卡2

但是无论需要什么格式。

好吧,这里最明显的答案是有一个类
播放器

class Player:
     playercards = []
另一种方法是为每个玩家指定一个名字:

class Player:
     name = ""
然后有一个
Gameserver
类:

class Gameserver:
    cards = {'Player1':['4Clubs', 'QClubs'], .....}

    def getCards(name):
        return cards[name]
然后你可以这样做:

gameserver = GameServer()

#Initialize and blablabla
........


x = Player("Player1")
x.showHand() 
#the line above would basically do the following:
#print gameserver.getCards(x.name())

这些多用户是如何玩游戏的?在一台电脑上?多个用户帐户?多台计算机?通过互联网?为每个玩家维护一个数据结构(列表或类似的)。然后,查看相应的数据结构