Beispiel #1
0
    def __init__(self):

        self.run = True
        import defaultStyle
        defaultStyle.init(gui)
        self.screen = pygame.display.set_mode((1024, 700))
        #First, we create a desktop to contain all the widgets
        self.desktop = Desktop()
        self.background = load_image("fundo_menu.png", "res/img")
        #IMPORTANTE RESULTADO FINAL
        self.playername = ""
        self.ip_server = ""
        self.port_server = ""
        self.player_folder = ""
        
        
        self.animation_player = 0
        self.a = 0 
        self.p1 = []
        self.p2 = []
        self.p3 = []
        self.p4 = []
        self.p5 = []
        self.p6 = []
        
        self.addPlayerImages()
        self.createOptionMenu()
       
    
        
        return self.gameLoop()
Beispiel #2
0
 def __init__(self):
     self.run = True
     self.screen = pygame.display.set_mode((640,480),0,32)
     defaultStyle.init(gui)
     self.desktop = gui.Desktop()
     self.GUI()
     self.AritMayaCiclo()
Beispiel #3
0
    def askReset(self):

	def YesOnClick(button):
	    self.pause = False
	    def1 = self.factory.getRootObject()
	    def1.addCallback(self.gameReset)
	    self.desktop.query.close()
	    self.desktop.query.position = (0,0)
	    self.desktop.query.size = (0,0)
	def NoOnClick(button):
	    self.pause = False
	    self.desktop.query.close()
	    self.desktop.query.position = (0,0)
	    self.desktop.query.size = (0,0)

	defaultStyle.init(gui)
	endStyle = {'font-color': (255,255,255), 'font': font.Font(None,24), 'autosize': True, "antialias": True,'border-width': False, 'border-color': (0,0,0), 'wordwrap': False}
	self.desktop.query = Window(position = (350,250), size = (300,200), parent = self.desktop, text = "Reset", closeable = False, shadeable = False)

	labelStyleCopy = gui.defaultLabelStyle.copy()
	Label(position = (100,50),size = (100,0), parent = self.desktop.query, text = "Reset the game", style = endStyle)
	Label(position = (100,100),size = (100,0), parent = self.desktop.query, text = "Are you sure?", style = endStyle)

	Yes_button = Button(position = (50,150), size = (40,0), parent = self.desktop.query, text = "Yes")
	No_button = Button(position = (200,150), size = (40,0), parent = self.desktop.query, text = "No")
	Yes_button.onClick = YesOnClick
	No_button.onClick = NoOnClick

	self.pause = True

	return	
Beispiel #4
0
 def __init__(self):
     # Setup GUI
     self.playerselection = 0
     defaultStyle.init(gui)
     
     self.desktop = gui.Desktop()
     self.win = gui.Window(position = (800,0), size = (200,600), parent = self.desktop, text = 'Statistics and Help')
     self.lbl = gui.Label(position = (2, 30), text = '---- Mini-map Key ----', parent = self.win)
     
     self.movbtn = gui.OnImageButton(utils.load_image('movebx.png'), position = (15, 50), parent = self.win)
     self.mvlbl = gui.Label(position = (25, 45), text = 'Moving / Living Player', parent = self.win)
     
     self.atkbtn = gui.OnImageButton(utils.load_image('atkbx.png'), position = (15, 70), parent = self.win)
     self.atklbl = gui.Label(position = (25, 65), text = 'Attacking Player', parent = self.win)
     
     self.deadbtn = gui.OnImageButton(utils.load_image('deadbx.png'), position = (15, 90), parent = self.win)
     self.deadlbl = gui.Label(position = (25, 85), text = 'Slain Player', parent = self.win)
     
     self.ovbtn = gui.OnImageButton(utils.load_image('ovbx.png'), position = (15, 110), parent = self.win)
     self.ovlbl = gui.Label(position = (25, 105), text = 'Overlord Player', parent = self.win)
     
     self.statslbl = gui.Label(position = (2, 130), text = '---- Player List ----', parent = self.win)
     self.playerstats = gui.ListBox(position = (2, 150), size = (196, 200), parent = self.win)
     self.playerstats.onItemSelected = self.itemSelected
     
     self.lbl_title_pos = gui.Label(position = (5, 350), text='Player (id:#): Status - ', parent = self.win)
     self.lbl_pos = gui.Label(position = (5, 365), text='Location: ( #, # )', parent = self.win)
     self.lbl_health = gui.Label(position = (5, 380), text='Health: # / 25', parent = self.win)
     self.lbl_ai_courage = gui.Label(position = (5, 395), text='AI Courage: #', parent = self.win)
     self.lbl_ai_camper = gui.Label(position = (5, 410), text='AI Camper: #', parent = self.win)
     self.lbl_ai_clingy = gui.Label(position = (5, 425), text='AI Clingy: #', parent = self.win)
     self.lbl_ai_stack = gui.Label(position = (5, 440), text='AI Stack: #', parent = self.win)
     self.player_img_alive = gui.OnImageButton(utils.load_sliced_sprites(32, 32, 'characters/zelda_atk.png')[0], position = (100,420), parent = self.win, enabled = False)
     self.player_img_dead = gui.OnImageButton(utils.load_sliced_sprites(32, 32, 'characters/zelda_dead.png')[0], position = (100,420), parent = self.win, enabled = False)
Beispiel #5
0
 def __init__(self):
     pygame.init()
     self.Pantalla_Principal = pygame.display.set_mode((640,480))
     self.run=True
     defaultStyle.init(gui)
     self.desktop = gui.Desktop()
     self.buttonsalir = Button(position = (480,450),parent = self.desktop, text = "Salir")
     self.buttonsalir.onClick = self.buttonsalir_onClick
     self.Imagen = ""
     #Respuestas
     self.ListaRespuesta=self.Llenado('R')
     #Preguntas
     self.ListaPregunta=self.Llenado('P')
     #Imagenes
     self.ListaImagenes=self.CargadoImagnes()
     
     Indice=self.getRandomIndex(len(self.ListaRespuesta))
     #Respuesta Secreta
     self.ReSecreta=self.ListaRespuesta[Indice]
     #Pregunta Secreta
     self.PreSecreta=self.ListaPregunta[Indice]
     #Letras Correctas
     self.LCorrectas=""
     #Letras Incorrectas
     self.LIncorrectas=""     
     self.GUI()
     self.AhorcadoCiclo()         
Beispiel #6
0
    def remote_waitPlayer(self,name):

	defaultStyle.init(gui)
	endStyle = {'font-color': (255,255,255), 'font': font.Font(None,20), 'autosize': True, "antialias": True,'border-width': False, 'border-color': (0,0,0), 'wordwrap': False}
	self.desktop.query = Window(position = (250,180), size = (500,200), parent = self.desktop, text = "Lost Player", closeable = False, shadeable = False)

	labelStyleCopy = gui.defaultLabelStyle.copy()
	Label(position = (30,50),size = (100,0), parent = self.desktop.query, text = str(name) + " has disconnected", style = endStyle)
	Label(position = (30,100),size = (100,0), parent = self.desktop.query, text = "Waiting for the game host to replace them or restart the game", style = endStyle)

	self.pause = True

	return
Beispiel #7
0
    def DrawWait(self,message):

	defaultStyle.init(gui)
	desktop_main = Desktop()
	desktop = Window(position = (300,220), size = (400,200), parent = desktop_main, text = "Waiting", closeable = False, shadeable = False)

	labelStyleCopy = gui.defaultLabelStyle.copy()
	Label(position = (100,75),size = (50,0), parent = desktop, text = message, style = labelStyleCopy)

	if not self.connected:
	    font = pygame.font.Font("FreeSans.ttf", 30)
	    self.titletext = font.render("Play against the computer",1,(255,255,255))
	    self.titletext2 = font.render("Start a network game",1,(255,255,255))
	    self.titletext3 = font.render("Join a network game",1,(255,255,255))
	    self.titletext4 = font.render("Options",1,(255,255,255))

	    self.titlepos = self.titletext.get_rect()
	    self.titlepos.centerx = 512
	    self.titlepos.centery = 350
	    self.titlepos2 = self.titletext2.get_rect()
	    self.titlepos2.centerx = 512
	    self.titlepos2.centery = 450
	    self.titlepos3 = self.titletext3.get_rect()
	    self.titlepos3.centerx = 512
	    self.titlepos3.centery = 550
	    self.titlepos4 = self.titletext4.get_rect()
	    self.titlepos4.centerx = 512
	    self.titlepos4.centery = 650

	    self.screen.fill((0,0,255))               

	    #YOUR RENDERING HERE!!!
	    self.screen.blit(self.menuback, (0,0))
	    
	    self.screen.blit(self.titletext,self.titlepos)
	    self.screen.blit(self.titletext2,self.titlepos2)
	    self.screen.blit(self.titletext3,self.titlepos3)
	    self.screen.blit(self.titletext4,self.titlepos4)
	else:
	    self.DrawGame(flip=False)

	#Last thing to draw, desktop
	try:
	    desktop_main.update()
	    desktop_main.draw()
	except:
	    pass

	#Flips!
	pygame.display.flip()
Beispiel #8
0
 def __init__(self):
     self.run = True
     self.Pantalla_Principal = pygame.display.get_surface()
     self.MayCJAGlobales = MayCJAGlobales()
     self.MayCNucleo = MayCNucleo()
     self.MayCNucleo.CDirRecursos(self.MayCJAGlobales.ObtDRecu())
     defaultStyle.init(gui)
     self.desktop = gui.Desktop()
     self.MayCNucleo.CSPGDesk(self.desktop)
     #Indices Jugados
     self.IndJ = []
     self.CargarDatos()     
     self.GUI()
     self.Reloj.Comenzar()
     self.AhorcadoCiclo()         
Beispiel #9
0
    def remote_goOut(self):
	"""
	Called remotely by the server when the client's partner has asked to go out.
	Waits for user input.
	"""
	self.done = False

	def OKOnClick(button):
	    self.done = True
	    self.response = True
	def cancelOnClick(button):
	    self.done = True
	    self.response = False

	defaultStyle.init(gui)
	defaultStyle.init(gui)
	desktop_main = Desktop()
	desktop = Window(position = (300,220), size = (400,200), parent = desktop_main, text = "Go Out", closeable = False, shadeable = False)
	desktop.onClose = cancelOnClick

	labelStyleCopy = gui.defaultLabelStyle.copy()

	Label(position = (100,100),size = (200,0), parent = desktop, text = 'Your partner asked: "May I go out?"', style = labelStyleCopy)

	OK_button = Button(position = (100,140), size = (50,0), parent = desktop, text = "Yes")
	cancel_button = Button(position = (200,140), size = (50,0), parent = desktop, text = "No")

	OK_button.onClick = OKOnClick
	cancel_button.onClick = cancelOnClick

	while not self.done:

	    #Handle Input Events
	    for event in gui.setEvents():
		if event.type == QUIT:
		    return
		elif event.type == KEYDOWN and event.key == K_ESCAPE:
		    return

	    self.DrawGame(flip=False)
	    desktop_main.update()
	    desktop_main.draw()
	    pygame.display.flip()

	return self.response
Beispiel #10
0
    def genChat(self,x,y):

	defaultStyle.init(gui)
	self.chatwin = Window(position = (x,y), size = (280,130), parent = self.desktop, text = "", closeable = False, shadeable = True)

	labelStyleCopy = gui.defaultLabelStyle.copy()
	labelStyleCopy['autosize'] = False
	labelStyleCopy['wordwrap'] = True
	labelStyleCopy['font'] = pygame.font.Font("FreeSans.ttf", 12)

	textboxStyleCopy = gui.defaultTextBoxStyle.copy()
	textboxStyleCopy['border-width'] = 1
	textboxStyleCopy['font'] = pygame.font.Font("FreeSans.ttf", 12)

	self.chatwin.chatdisplay = Label(position = (5,5),size = (270,105), parent = self.chatwin, text = "", style = labelStyleCopy)
	self.chatwin.chattxt = TextBox(position = (5,107), size = (270, 0), parent =self.chatwin, text = "", style = textboxStyleCopy)

	self.chatwin.enabled = True
Beispiel #11
0
    def remote_lostPlayer(self,name):

	def ComputerOnClick(button):
	    self.result = True
	    self.desktop.query.close()
	    self.desktop.query.position = (0,0)
	    self.desktop.query.size = (0,0)
	def ResetOnClick(button):
	    self.result = False
	    self.desktop.query.close()
	    self.desktop.query.position = (0,0)
	    self.desktop.query.size = (0,0)

	self.result = None

	try: self.desktop.query.close()
	except: pass

	defaultStyle.init(gui)
	endStyle = {'font-color': (255,255,255), 'font': font.Font(None,20), 'autosize': True, "antialias": True,'border-width': False, 'border-color': (0,0,0), 'wordwrap': False}
	self.desktop.query = Window(position = (250,180), size = (500,200), parent = self.desktop, text = "Lost Player", closeable = False, shadeable = False)

	labelStyleCopy = gui.defaultLabelStyle.copy()
	Label(position = (30,50),size = (100,0), parent = self.desktop.query, text = str(name) + " has disconnected", style = endStyle)
	Label(position = (30,75),size = (100,0), parent = self.desktop.query, text = "Do you want to replace them with a computer player?", style = endStyle)
	Label(position = (30,100),size = (100,0), parent = self.desktop.query, text = "Or end this game and start a new one?", style = endStyle)
	Label(position = (30,125),size = (100,0), parent = self.desktop.query, text = "If you replace them, you can add them back in if they reconnect", style = endStyle)
	    
	Computer_button = Button(position = (30,170), size = (175,0), parent = self.desktop.query, text = "Replace with computer")
	Computer_button.onClick = ComputerOnClick
	Reset_button = Button(position = (270,170), size = (175,0), parent = self.desktop.query, text = "Start over with a new game")
	Reset_button.onClick = ResetOnClick
	
	while self.result == None:
	    self.defaultInput()
	    self.DrawQuery()

	return self.result
Beispiel #12
0
    def genHelp(self):

	def helpClose(button):
	    self.p.viewhelp = 0
	    self.desktop.query.wintype = None
	    self.desktop.query.position = (0,0)
	    self.desktop.query.size = (0,0)

        text = [
            "Canasty v0.1",
            "-----------------------",
            "F1 - Display this help text.",
            "ESC - Quit.",
	    "Click the scoreboard to re-sort your cards",
            "Click the pile to draw a card",
	    "Click the discard pile to pick it up",
	    "(first stage or select cards",
	    "that you need to meld)",
	    "Drag a card to the pile to discard it",
	    "Select cards and right-click to meld",
	    "(or drag them onto an existing meld)",
	    "Drag melds to the stage area to stage them",
	    "Left-click the stage to meld it",
	    "(right-click to clear it)",
	    "-----------------------",
	    "See manual for alternate keyboard controls"]

	defaultStyle.init(gui)
	helpStyle = {'font-color': (255,255,255), 'font': font.Font(None,24), 'autosize': True, "antialias": True,'border-width': False, 'border-color': (0,0,0), 'wordwrap': False}
	self.desktop.query = Window(position = (300,120), size = (400,500), parent = self.desktop, text = "Help", closeable = True, shadeable = False)
	self.desktop.query.onClose = helpClose
	self.desktop.query.wintype = "help"

	labelStyleCopy = gui.defaultLabelStyle.copy()

	for pos, t in enumerate(text):
	    Label(position = (30,35+25*pos),size = (200,0), parent = self.desktop.query, text = t, style = helpStyle)
def initStyle():
    """Initializes the styles"""
    import defaultStyle
    os.chdir('vendor')
    defaultStyle.init(gui)
    os.chdir('..')
Beispiel #14
0
    def genEndRound(self):

	self.next_round = False
	
	def ContinueOnClick(button):
	    self.desktop.query.close()
	    self.desktop.query.position = (0,0)
	    self.desktop.query.size = (0,0)
	    def1 = self.factory.getRootObject()
	    def1.addCallback(self.reportReady)

	team1round = self.g.cardPoints(1) + self.g.specialPoints(1,params=False) - self.g.handPoints(1)
	team2round = self.g.cardPoints(2) + self.g.specialPoints(2,params=False) - self.g.handPoints(2)

	font2 = pygame.font.Font("FreeSans.ttf", 20)

	team1specials = self.g.specialPoints(1,params=True)
	team2specials = self.g.specialPoints(2,params=True)

	if team1specials[2]==8:
	    team1specials[2]=4
	if team2specials[2]==8:
	    team2specials[2]=4

	if team1specials[3]==1:
	    team1out = "Went out first"
	elif team1specials[3]==2:
	    team1out = "Went out concealed"
	else:
	    team1out = ""
	
	if team2specials[3]==1:
	    team2out = "Went out first"
	elif team2specials[3]==2:
	    team2out = "Went out concealed"
	else:
	    team2out = ""

	endtext1 = ["Team 1:",
		    str(team1round)+             " points",
		    str(self.g.cardPoints(1)) +       " face value",
		    "-" + str(self.g.handPoints(1)) + " points in hand",
		    str(team1specials[0])+" red canastas",
		    str(team1specials[1])+" black canastas",
		    str(team1specials[2])+" red threes",
		    str(team1specials[4])+" wild card canastas",
		    team1out]
	endtext2 = ["Team 2:",
		    str(team2round)+             " points",
		    str(self.g.cardPoints(2)) +       " face value",
		    "-" + str(self.g.handPoints(2)) + " points in hand",
		    str(team2specials[0])+" red canastas",
		    str(team2specials[1])+" black canastas",
		    str(team2specials[2])+" red threes",
		    str(team2specials[4])+" wild card canastas",
		    team2out]

	if (self.g.team1score>=5000) & (self.g.team1score>self.g.team2score):
	      endtext1.append("Team 1 is the winner!")
	if (self.g.team2score>=5000) & (self.g.team2score>self.g.team1score):
	      endtext2.append("Team 2 is the winner!")
		

	defaultStyle.init(gui)
	endStyle = {'font-color': (255,255,255), 'font': font.Font(None,24), 'autosize': True, "antialias": True,'border-width': False, 'border-color': (0,0,0), 'wordwrap': False}
	self.desktop.query = Window(position = (250,180), size = (500,400), parent = self.desktop, text = "Round Over", closeable = False, shadeable = False)

	labelStyleCopy = gui.defaultLabelStyle.copy()
	Label(position = (200,40),size = (100,0), parent = self.desktop.query, text = "Round " + str(self.g.round) + " over", style = endStyle)

	for pos, t in enumerate(endtext1):
	    Label(position = (50,80+25*pos),size = (200,0), parent = self.desktop.query, text = t, style = endStyle)
	for pos, t in enumerate(endtext2):
	    Label(position = (300,80+25*pos),size = (200,0), parent = self.desktop.query, text = t, style = endStyle)
		    
	Cont_button = Button(position = (200,350), size = (70,0), parent = self.desktop.query, text = "Continue")
	Cont_button.onClick = ContinueOnClick
Beispiel #15
0
    def Options(self, options):
        """
	Set gameplay options.
	"""
        self.done = False

        def OKOnClick(button):
            self.done = True
            self.save = True

        def cancelOnClick(button):
            self.done = True
            self.save = False

        def onChkValueChanged(chk):
            meldbonus1_txt.enabled = chk.value
            meldbonus2_txt.enabled = chk.value

        def animateChkValueChanged(chk):
            animate_txt.enabled = chk.value

        defaultStyle.init(gui)
        desktop_main = Desktop()
        desktop = Window(position=(250, 200), size=(600, 400), parent=desktop_main, text="Options", shadeable=False)
        desktop.onClose = cancelOnClick

        labelStyleCopy = gui.defaultLabelStyle.copy()

        red3penalty_chk = CheckBox(
            position=(20, 225), size=(200, 0), parent=desktop, text="Red 3 Penalty", value=options.red3penalty
        )
        initfreeze_chk = CheckBox(
            position=(20, 50), size=(200, 0), parent=desktop, text="Allow freeze on opening", value=options.initfreeze
        )
        counttop_chk = CheckBox(
            position=(20, 75),
            size=(200, 0),
            parent=desktop,
            text="Count pile card points in melds",
            value=options.counttop,
        )
        allowpass_chk = CheckBox(
            position=(20, 100),
            size=(200, 0),
            parent=desktop,
            text="Allow passing with one card",
            value=options.allowpass,
        )
        negpoints_chk = CheckBox(
            position=(20, 125),
            size=(200, 0),
            parent=desktop,
            text="No point threshold with negative score",
            value=options.negpoints,
        )
        concealedfree_chk = CheckBox(
            position=(20, 150),
            size=(200, 0),
            parent=desktop,
            text="No minimum for concealed going out",
            value=options.concealedfree,
        )
        piletocanasta_chk = CheckBox(
            position=(20, 175),
            size=(200, 0),
            parent=desktop,
            text="Allow melding pile card with existing meld",
            value=options.piletocanasta,
        )
        pilewithwild_chk = CheckBox(
            position=(20, 200),
            size=(200, 0),
            parent=desktop,
            text="Allow matching unfrozen pile with a wild",
            value=options.pilewithwild,
        )

        megamelds_chk = CheckBox(
            position=(350, 225),
            size=(200, 0),
            parent=desktop,
            text="Melds of more than 7 cards",
            value=options.megamelds,
        )
        wildmeld_chk = CheckBox(
            position=(350, 50), size=(200, 0), parent=desktop, text="Wild card melds", value=options.wildmeld
        )
        wildmeld_chk.onValueChanged = onChkValueChanged
        Label(position=(400, 75), size=(50, 0), parent=desktop, text="Wild card canasta value", style=labelStyleCopy)
        meldbonus1_txt = TextBox(position=(350, 75), size=(40, 0), parent=desktop, text="1000")
        Label(position=(400, 100), size=(50, 0), parent=desktop, text="If 0 or 4 Jokers", style=labelStyleCopy)
        meldbonus2_txt = TextBox(position=(350, 100), size=(40, 0), parent=desktop, text="1000")

        threewilds_chk = CheckBox(
            position=(350, 125), size=(200, 0), parent=desktop, text="Limit 3 wilds in a meld", value=options.threewilds
        )
        gonatural_chk = CheckBox(
            position=(350, 150),
            size=(200, 0),
            parent=desktop,
            text="Pile frozen before initial meld",
            value=options.gonatural,
        )
        freezealways_chk = CheckBox(
            position=(350, 175), size=(200, 0), parent=desktop, text="Pile always frozen", value=options.freezealways
        )
        runempty_chk = CheckBox(
            position=(350, 200),
            size=(200, 0),
            parent=desktop,
            text="Continued play with no stock",
            value=options.runempty,
        )

        animate_chk = CheckBox(
            position=(250, 270), size=(100, 0), parent=desktop, text="Animate cards?", value=options.wildmeld
        )
        animate_chk.onValueChanged = animateChkValueChanged
        Label(position=(250, 295), size=(50, 0), parent=desktop, text="Speed:", style=labelStyleCopy)
        animate_txt = TextBox(position=(310, 295), size=(40, 0), parent=desktop, text="30")

        OK_button = Button(position=(200, 370), size=(50, 0), parent=desktop, text="OK")
        cancel_button = Button(position=(400, 370), size=(50, 0), parent=desktop, text="Cancel")

        OK_button.onClick = OKOnClick
        cancel_button.onClick = cancelOnClick

        while not self.done:

            # Handle Input Events
            for event in gui.setEvents():
                if event.type == QUIT:
                    return
                elif event.type == KEYDOWN and event.key == K_ESCAPE:
                    return
                elif event.type == KEYDOWN and event.key == 13:
                    OKOnClick(None)
            desktop_main.update()
            self.Draw(desktop_main)

        if not animate_chk.value:
            animation = 10000
        else:
            try:
                animation = int(animate_txt.text)
            except:
                animation = 30
            if animation < 1:
                animation = 1

        if self.save:
            try:
                meldbonus1 = int(meldbonus1_txt.text)
            except:
                meldbonus1 = 1000

            try:
                meldbonus2 = int(meldbonus1_txt.text)
            except:
                meldbonus2 = 1000

            return CanastaOptions(
                red3penalty_chk.value,
                initfreeze_chk.value,
                counttop_chk.value,
                negpoints_chk.value,
                megamelds_chk.value,
                threewilds_chk.value,
                gonatural_chk.value,
                concealedfree_chk.value,
                allowpass_chk.value,
                runempty_chk.value,
                piletocanasta_chk.value,
                pilewithwild_chk.value,
                freezealways_chk.value,
                wildmeld_chk.value,
                [int(meldbonus1), int(meldbonus2)],
                animation,
            )
        else:
            return options
Beispiel #16
0
    def DrawAssign(self):

	def OKOnClick(button):
	    self.start_game = True
	    self.desktop.assign.close()
	    self.desktop.assign.position = (0,0)
	    self.desktop.assign.size = (0,0)

	def assignPlayer(arg):
	    which = self.glist.index(arg.name)
	    last = self.gr[which]
	    if DEBUGGER: print arg.name,self.glist,which,last
	    if arg.value==None:
		return
	    loc = posnames.index(arg.text)
	    #Assign an observer. Allows starting a game with no human players only if the debugger is on.
	    if (loc == 4) & ((positions != [None]*4) | DEBUGGER):
		try: self.gr[which].value = False
		except: pass
		for i in range(len(positions)):
		    if positions[i]==arg.name:
			positions[i]=None
		self.gr[which] = arg
	    #Reject the assign if it conflicts with another player's assignment or leaves no human players with the debugger off.
	    elif (positions[loc]!=None) | ((loc==4) & (positions==[None]*4) & (not DEBUGGER)):
		print "BZZT!"
		arg.value = False
		self.gr[which].value = True
	    #Otherwise, assign the position
	    else:
		try: self.gr[which].value = False
		except: pass
		for i in range(len(positions)):
		    if positions[i]==arg.name:
			positions[i]=None
		positions[loc] = arg.name
		self.gr[which] = arg
	    if DEBUGGER: print positions
	    self.positions = positions

	playernames=self.names

	if self.new_players:

	    try: 
		self.desktop.assign.close()
		self.desktop.query.position = (0,0)
		self.desktop.query.size = (0,0)
	    except: pass

	    optionsurf = pygame.image.load("./art/optionbox.png").convert_alpha()

	    self.desktop_main = Desktop()
	    self.desktop.assign = Window(position = (100,100), size = (800,600), parent = self.desktop, text = "Assign players", closeable = False, shadeable = False)
	    self.gr = []
	    self.glist = []

	    defaultStyle.init(gui)
	    labelStyleCopy = gui.defaultLabelStyle.copy()
	    labelStyleCopy['wordwrap'] = True

	    if self.positions == [None]*4:
		default = True
	    else:
		default = False
	    positions = self.positions
	    posnames = ["Bottom","Left","Top","Right","Observer"]
	    
	    for index, p in enumerate(self.names):
		if index<4:
		    def_pos = posnames[index]
		else:
		    def_pos = None

		if index==0:
		    label1 = Label(position = (125,125),size = (200,0), parent = self.desktop.assign, text = "Players will appear here when they connect to your game.", style = labelStyleCopy)
		    label2 = Label(position = (125,145),size = (200,0), parent = self.desktop.assign, text = "Assign them to a player position and press the start button when ready.", style = labelStyleCopy)
		    label3 = Label(position = (125,165),size = (200,0), parent = self.desktop.assign, text = "Unfilled positions will be filled with computer players.", style = labelStyleCopy)
		    label3 = Label(position = (125,185),size = (200,0), parent = self.desktop.assign, text = "Observers can watch the game and use the chat window, and may be included in the next round.", style = labelStyleCopy)
		label_name = Label(position = (125,220 + index*25),size = (200,0), parent = self.desktop.assign, text = p, style = labelStyleCopy)

		if (index<4) & default:
		    positions[index] = p
		self.gr.append(None)
		self.glist.append(p)

		for index2, pos in enumerate(posnames):
		    o = CheckBox(position = (200+index2*75,220+index*25), parent = self.desktop.assign, text = pos, style = gui.createOptionBoxStyle(gui.defaultFont, optionsurf, 12, (255,255,255),
                                                     (100,100,100), autosize = True))
		    o.name = p
		    print p
		    o.index = index2
		    try:
			if positions[index2]==p:
			    o.value = True
			    self.gr[index] = o
		    except:
			pass
		    if (index2==4) & (self.gr[index]==None):
			o.value = True
		    o.onValueChanged = assignPlayer


		OK_button = Button(position = (125,400), size = (50,0), parent = self.desktop.assign, text = "Start")
		OK_button.onClick = OKOnClick

	    self.positions = positions
	    self.new_players = False

	self.DrawGame()
Beispiel #17
0
    def netclient(self):
        """
	Get necessary information to launch a client and connect to a remote server.
	"""
        self.done = False

        def OKOnClick(button):
            self.done = True
            self.save = True

        def cancelOnClick(button):
            self.done = True
            self.save = False

        defaultStyle.init(gui)
        desktop_main = Desktop()
        desktop = Window(
            position=(300, 220), size=(400, 200), parent=desktop_main, text="Join Network Game", shadeable=False
        )
        labelStyleCopy = gui.defaultLabelStyle.copy()
        desktop.onClose = cancelOnClick

        label = Label(
            position=(100, 40),
            size=(200, 0),
            parent=desktop,
            text="Enter a name and server location:",
            style=labelStyleCopy,
        )

        label = Label(position=(100, 70), size=(50, 0), parent=desktop, text="Name", style=labelStyleCopy)
        name_txt = TextBox(position=(150, 70), size=(100, 0), parent=desktop, text="noname")
        label = Label(position=(100, 95), size=(50, 0), parent=desktop, text="Host", style=labelStyleCopy)
        host_txt = TextBox(position=(150, 95), size=(200, 0), parent=desktop, text="localhost")
        label = Label(position=(100, 120), size=(50, 0), parent=desktop, text="Port", style=labelStyleCopy)
        port_txt = TextBox(position=(150, 120), size=(50, 0), parent=desktop, text="7171")

        OK_button = Button(position=(100, 170), size=(50, 0), parent=desktop, text="OK")
        cancel_button = Button(position=(200, 170), size=(50, 0), parent=desktop, text="Cancel")

        OK_button.onClick = OKOnClick
        cancel_button.onClick = cancelOnClick

        while not self.done:

            # Handle Input Events
            for event in gui.setEvents():
                if event.type == QUIT:
                    return
                elif event.type == KEYDOWN and event.key == K_ESCAPE:
                    return
                elif event.type == KEYDOWN and event.key == 9:
                    if desktop_main.focused is name_txt:
                        desktop_main.focused = host_txt
                    elif desktop_main.focused is host_txt:
                        desktop_main.focused = port_txt
                    else:
                        desktop_main.focused = name_txt

                    name_txt.needsRefresh = True
                    host_txt.needsRefresh = True
                    port_txt.needsRefresh = True
                elif event.type == KEYDOWN and event.key == 13:
                    OKOnClick(None)
                else:
                    desktop_main.update()
            self.Draw(desktop_main)

        if self.save:
            return [name_txt.text, host_txt.text, int(port_txt.text)]
        else:
            return
Beispiel #18
0
clock = pygame.time.Clock()

run = True



back = pygame.image.load('art/back.jpg').convert()

#END

#GUI STUFF
#This way it's easy to load the example gui skin:
import defaultStyle

defaultStyle.init(gui)

#First, we create a desktop to contain all the widgets
desktop = Desktop()

#Create a label passing some parameters.
#TRICKY THING HERE: if you want to use an already defined style, just copy it, and set new parameters as you wish
labelStyleCopy = gui.defaultLabelStyle.copy()
labelStyleCopy['border-width'] = 1
labelStyleCopy['wordwrap'] = True
labelStyleCopy['autosize'] = False

label = Label(position = (50,60),size = (200,100), parent = desktop, text = "Click the button for a proverb!", style = labelStyleCopy)

#Create the button
button = Button(position = (50,165), size = (200,0), parent = desktop, text = "Teach me!")