def draw_board(self): ''' Drawing the board for moving car and the statistic showing step and time ''' # Draw squares for row in range(self.board_len): for column in range(self.board_len): # Drawing the small square pygame.draw.rect(self.main_board, self.colors["grey"], [(self.margin + self.box_len) * column + self.margin, (self.margin + self.box_len) * row + self.margin, self.box_len, self.box_len]) # Draw statistic pygame.draw.rect(self.main_board, self.colors["blue"], (self.board_size + self.margin, 0, self.board_size_len - self.board_size - self.margin, self.board_size)) html.write(self.main_board, self.time_counter, pygame.Rect(self.board_size + self.margin,0,self.board_size_len - self.board_size - self.margin,self.board_size),""" <div style='width:"""+str(self.board_size_len - self.board_size - self.margin)+""""; height:"""+ str(self.board_size) +"""; background: #00aeef; border: 1px; border-color: #888888;'></div> """) self.main_board.blit(self.txt_time_counter, [self.board_size + 2*self.margin, self.margin])
from pgu import html pygame.font.init() screen = pygame.display.set_mode((320,320),SWSURFACE) fg = (0,0,0) bg = (255,255,255) screen.fill(bg) font = pygame.font.SysFont("sans", 16) ##:: html.write(screen,font,pygame.Rect(0,0,320,320),""" <p>Welcome to my humble website.</p> <p><img src='cuzco.png' align=right>As usual we have an image of Cuzco included in every location we could possibly think of.</p> <p align='center'>Cuzco is a <b>very big</b> goat.</p> <p align='right'><img src='cuzco.png' align=left> If I wanted to be really silly, I would be sure to add link ability to this module. But that would be gold plating.</p> """) ## pygame.display.flip() _quit = 0 while not _quit: for e in pygame.event.get(): if e.type is QUIT: _quit = 1 pygame.time.wait(10)
def start(self, score): self.highEnd = 0 clock = pygame.time.Clock() if (score > 0): position = self.myScores.check(score) if (position != None): app = gui.Desktop() app.connect(gui.QUIT, app.quit, None) main = gui.Container( width=500, height=400) #, background=(220, 220, 220) ) positionText = "You are " + PositionText( position) + " on the High Score table!!" main.add(gui.Label(positionText, cls="h1"), 20, 20) td_style = {'padding_right': 10} t = gui.Table() t.tr() t.td(gui.Label('Type your name:'), style=td_style) userName = gui.Input() t.tr() t.td(userName, style=td_style) b = gui.Button("Done") b.connect(gui.CLICK, app.quit, None) t.td(b, style=td_style) main.add(t, 20, 100) app.run(main) if (userName.value != ""): position = self.myScores.submit(score, userName.value[0:15], None) else: app = gui.Desktop() app.connect(gui.QUIT, app.quit, None) main = gui.Container( width=500, height=400) #, background=(220, 220, 220) ) main.add( gui.Label("Sorry you didn't get a high score", cls="h1"), 20, 20) td_style = {'padding_right': 10} t = gui.Table() t.tr() b = gui.Button("Done") b.connect(gui.CLICK, app.quit, None) t.td(b, style=td_style) main.add(t, 20, 100) app.run(main) #Draw background pygame.draw.rect(self.screen, (255, 255, 255), pygame.Rect(0, 0, self.SCREEN_W, self.SCREEN_H)) #Draw Highscore Table self.scoretable = "" #data contains the html to be parsed on to the screen. This section sets up the table and the table headers data = "<table border=1 width=100% align='center' style='border:1px; border-color: #000088; background: #ccccff; margin: 20px; padding: 20px;'>" data += "<tr><td width=100%><b>Position</b></td><td width=100%><b>Player</b></td><td width=100%><b>Score</b></td></tr>" count = 0 #Iterate each item in the high score list and add each as a row to the table for e in self.myScores: data += "<tr>" data += "<td>" data += PositionText(count) data += "</td>" data += "<td>" data += e.name data += "</td>" data += "<td>" data += str(e.score) data += "</td>" data += "</tr>" count = count + 1 #Close the table data += "</table>" #Now that we've finished readin from the highscores, save it back to the .txt file self.hiScore.save() #Display the table until the user exits while (self.highEnd == 0): self.__handleUserInteraction() html.write(self.screen, self.font, pygame.Rect(300, 25, 700, 700), data) pygame.display.flip() pygame.event.clear() return self.highEnd
def start(self,score): self.highEnd = 0 clock = pygame.time.Clock() if (score > 0): position = self.myScores.check(score) if(position != None): app = gui.Desktop() app.connect(gui.QUIT,app.quit,None) main = gui.Container(width=500, height=400) #, background=(220, 220, 220) ) positionText = "You are " + PositionText(position) + " on the High Score table!!" main.add(gui.Label(positionText, cls="h1"), 20, 20) td_style = {'padding_right': 10} t = gui.Table() t.tr() t.td( gui.Label('Type your name:') , style=td_style ) userName = gui.Input() t.tr() t.td( userName, style=td_style ) b = gui.Button("Done") b.connect(gui.CLICK,app.quit,None) t.td( b, style=td_style ) main.add(t, 20, 100) app.run(main) if (userName.value != ""): position = self.myScores.submit(score,userName.value[0:15],None) else: app = gui.Desktop() app.connect(gui.QUIT,app.quit,None) main = gui.Container(width=500, height=400) #, background=(220, 220, 220) ) main.add(gui.Label("Sorry you didn't get a high score", cls="h1"), 20, 20) td_style = {'padding_right': 10} t = gui.Table() t.tr() b = gui.Button("Done") b.connect(gui.CLICK,app.quit,None) t.td( b, style=td_style ) main.add(t, 20, 100) app.run(main) #Draw background pygame.draw.rect(self.screen, (255, 255, 255), pygame.Rect(0, 0, self.SCREEN_W, self.SCREEN_H)) #Draw Highscore Table self.scoretable = "" #data contains the html to be parsed on to the screen. This section sets up the table and the table headers data = "<table border=1 width=100% align='center' style='border:1px; border-color: #000088; background: #ccccff; margin: 20px; padding: 20px;'>" data += "<tr><td width=100%><b>Position</b></td><td width=100%><b>Player</b></td><td width=100%><b>Score</b></td></tr>" count = 0 #Iterate each item in the high score list and add each as a row to the table for e in self.myScores: data += "<tr>" data += "<td>" data += PositionText(count) data += "</td>" data += "<td>" data += e.name data += "</td>" data += "<td>" data += str(e.score) data += "</td>" data += "</tr>" count = count + 1 #Close the table data += "</table>" #Now that we've finished readin from the highscores, save it back to the .txt file self.hiScore.save() #Display the table until the user exits while (self.highEnd == 0): self.__handleUserInteraction() html.write(self.screen,self.font,pygame.Rect(300,25,700,700),data) pygame.display.flip() pygame.event.clear() return self.highEnd