コード例 #1
0
ファイル: game.py プロジェクト: hedayaty/snake
def getplayer(pnum):
	global netgame
	menuname = { "name" : "name", "label" : "Player " + pnum , "description" : "Name: "}
	menudev = { "description" : "Control: ", 									\
							"name" : "dev", 																\
							"options": 																			\
							[ { "label" : label, "value": dev } 						\
								for label,dev in devs if dev not in udevs			\
							] 																							\
						}
	menucolor = { "name" : "color", 
								"options" : 
								[ {"label" : "color", "value" : color } 
									for color in colors if color not in ucolors
								] 
							}

	values =  menu.select ("Select Player " + pnum,	[ menuname, menudev, menucolor ])
	if values == None:
		return None

	color = values["color"]["value"]
	name = values["name"]
	dev = values["dev"]["value"]

	ucolors.add(color)
	# Same players can not use the same device but ai and net are ok!
	if dev not in [ "ai", "net" ]:
		udevs.add(dev)
	if dev == "net":
		netgame = True
	return Player (name, dev, color, lives)
コード例 #2
0
ファイル: game.py プロジェクト: hedayaty/snake
def init(gametype):
	global players, items, remplayers
	global ucolors, udevs, devs, colors
	global numbersend, lives, netgame
	global blue, pink, green, red, orange,cyan
	global nlpr, cont

	blue = (0,0,255)
	pink = (255,20,147)
	green =(0,128,0)
	red = (255,0,0)
	orange = (255,165,0)
	cyan= (0,255,255)
	

	if gametype != "join" :
		list = os.listdir("maps")
		list.sort()
		mapname = menu.choose ("Select the map:",\
					[{ "label" : file, "value" : file} for file in list])
		if mapname == None :
			return False

		board.init ("maps/"+ mapname)
		items = {}
	
	# Get Game options
	boolean = [ { "label" : "On", "value": True }, 
							{ "label" : "Off", "value": False } 
						]
	multioptions = [																								\
			{ "description" : "NLPR: ", 																\
				"name" : "nlpr", 																					\
				"options" : boolean,																			\
				"default" : False,																				\
			}, 																													\
			{	"description" : "Continue: ",															\
				"name" : "cont", 																					\
				"options" : boolean,																			\
				"default" : False,																				\
			},																													\
			{ "description" : "End with numbers: ",											\
				"name" : "numbersend",																		\
				"options" : boolean,																			\
				"default" : True,																					\
			},																													\
			{	"description" : "Players: ",															\
				"name" : "nplayers",																			\
				"default" : 2,																						\
				"options" : [ { "label" : str(x), "value" : x} 						\
												for x in range(1,5)												\
										]																							\
			}]

	if gametype == "1p":
		multioptions = []

	options = menu.select ("Select Game Options",										\
			multioptions + 																							\
			[{	"description" : "Lives: ", 															\
					"name" : "lives", 																			\
					"default" : 5,																					\
					"options" : [ { "label" : str(x), "value" : x }					\
						for x in [1, 2, 3, 4, 5, 10, 20, 50, 64, 100, 256]]} 	\
			])
	if options == None:
		return False
	if gametype == "1p":
		nlpr = False
		cont = False
		nplayers = 1
		numbersend = True
	else:
		nlpr = options["nlpr"]["value"]
		cont = options["cont"]["value"]
		nplayers = options["nplayers"]["value"]
		numbersend = options["numbersend"]["value"]
	lives = options["lives"]["value"]

	# Get Players
	ucolors = set()
	udevs = set()
	colors = [blue, pink, green, red, orange, cyan]
	devs = [("Keypad", "keypad"),												\
					("Computer", "ai"), 												\
					("Keyboard (wasd)", "keyboard"),						\
					("Vim Keys (hjkl)", "vim"), 								\
					("Netwrok", "net")													\
					]

	players = []
	netgame = False
	for i in range(nplayers):
		player = getplayer(str(i+1))
		if player == None:
			return None
		players.append(player)

	if netgame:
#		network.startserver()
		for player in players:
			if player.dev == "net":
				if network.waitfor(player) == None:
					network.sendinfo (player, board.dim, board.obstacles)
					return None
			
	renderer.updateboard()
	remplayers = nplayers
	return True
コード例 #3
0
ファイル: fileconvert.py プロジェクト: bbw7561135/mypluto
                vvect = 3

    if (x == "b1"):
        i = scrh.index(x)
        bvect = 1
        if (scrh[i + 1] == "b2"):
            i = i + 1
            bvect = 2
            if (scrh[i + 1] == "b3"):
                bvect = 3

    if (x == "v2" or x == "b2"): continue
    if (x == "v3" or x == "b3"): continue

    if (vvect == 0 and bvect == 0):
        entries.append(x)
        options.append(['YES', 'NO'])
        default.append('YES')
    elif (vvect == 2):
        entries.append('Velocity')
        options.append(['YES', 'NO'])
        default.append('YES')
    elif (bvect == 2):
        entries.append('Magnetic field')
        options.append(['YES', 'NO'])
        default.append('YES')

print entries
selection = ''
selection = menu.select(entries, options, default, 'Input')
コード例 #4
0
ファイル: fileconvert.py プロジェクト: kylekanos/mypluto
    i = scrh.index(x)
    bvect = 1
    if (scrh[i+1] == "b2"):
      i = i + 1
      bvect = 2 
      if (scrh[i+1] == "b3"):
        bvect = 3

  if (x == "v2" or x == "b2"): continue
  if (x == "v3" or x == "b3"): continue

  if (vvect == 0 and bvect == 0): 
    entries.append(x)
    options.append(['YES','NO'])
    default.append('YES')
  elif (vvect == 2):
    entries.append('Velocity')
    options.append(['YES','NO'])
    default.append('YES')
  elif (bvect == 2):
    entries.append('Magnetic field')
    options.append(['YES','NO'])
    default.append('YES')




print entries
selection = '' 
selection = menu.select(entries,options,default,'Input')