Пример #1
0
    def displayContent(self):
        screen,ft_sz,x_scale,y_scale= Panel.screen, \
       Panel.ft_sz,Panel.x_scale,Panel.y_scale

        step = steps[self.currentStep]["step"]
        title = steps[self.currentStep]["title"]
        texts = steps[self.currentStep]["text"]
        figures = steps[self.currentStep].get("figures", [])

        b_x = x_scale * 820
        b_y = y_scale * 45
        b_h = y_scale * 28

        ln_size = y_scale * 28
        if self.refresh == 1:
            pygame.draw.rect(screen, background,
                             (b_x, b_y, x_scale * 528, y_scale * 635))
            self.refresh = 0
            line = 0
            for text in texts:
                printText(screen, text, "fangsong", ft_sz, b_x,
                          b_y + b_h * line, white)
                line += 1
            b_x += x_scale * 80
            b_y = y_scale * 500
            offset = 0
            for fig in figures:
                self.displayFigure(screen, b_x + offset, b_y,
                                   figList[fig[0]][fig[1]])
                fig_label = u"图" + str(fig[0] + 1) + "-" + str(fig[1] + 1)
                printText(screen, fig_label, "fangsong", ft_sz,
                          b_x + offset - x_scale * 20, b_y + y_scale * 65,
                          white)
                offset += x_scale * 120
Пример #2
0
    def displayCube(self):
        avg_z = []
        b_i = 0

        for b in self.blocks:
            f_i = 0
            for f in b.faces:
                z = (b.vertices[f[0]].z + b.vertices[f[1]].z +
                 b.vertices[f[2]].z + b.vertices[f[3]].z) / 4.0
                avg_z.append((b_i,f_i,z))
                f_i = f_i + 1
            b_i = b_i + 1

        # Draw the faces using the Painter's algorithm:
        # Distant faces are drawn before the closer ones.
        for tmp in sorted(avg_z,key=itemgetter(2),reverse=True):
            b_i = tmp[0]
            f_i = tmp[1]
            t = self.blocks[b_i].vertices
            f = self.blocks[b_i].faces[f_i]
            c = self.blocks[b_i].colors[f_i]

            if c != "-":
                pointlist = [(t[f[0]].x, t[f[0]].y), (t[f[1]].x, t[f[1]].y),
                         (t[f[2]].x, t[f[2]].y), (t[f[3]].x, t[f[3]].y)]
                
                pygame.draw.polygon(Panel.screen,c,pointlist)
                pygame.draw.polygon(Panel.screen,(0,0,0),pointlist,2)
                
                if  self.blocks[b_i].mark != "-":
                    if c == (0,0,255):#蓝色的块,要先是白色的字,不然看不清
                        printText(Panel.screen,self.blocks[b_i].mark, "kaiti", 20, int((t[f[0]].x + t[f[2]].x)/2.0)-5 , int((t[f[0]].y + t[f[2]].y)/2.0)-10, (255,255,255))
                    else:
                        printText(Panel.screen,self.blocks[b_i].mark, "kaiti", 20, int((t[f[0]].x + t[f[2]].x)/2.0)-5 , int((t[f[0]].y + t[f[2]].y)/2.0)-10, (0,0,0))
Пример #3
0
 def printRight(cls, msg):
     #screen,ft_sz,x_scale,y_scale= getDisplayParams()
     if msg != "":
         pygame.draw.rect(cls.screen, cls.gray,
                          (cls.x_scale * 1170, cls.y_scale * 640,
                           cls.x_scale * 170, cls.y_scale * 30))
         printText(cls.screen, msg, "fangsong", cls.ft_sz,
                   cls.x_scale * 1175, cls.y_scale * 643, black)
Пример #4
0
 def printHint(cls, msg):
     #screen,ft_sz,x_scale,y_scale= getDisplayParams()
     if msg != "":
         pygame.draw.rect(cls.screen, cls.gray,
                          (cls.x_scale * 220, cls.y_scale * 730,
                           cls.x_scale * 560, cls.y_scale * 30))
         printText(cls.screen, msg, "fangsong", cls.ft_sz,
                   cls.x_scale * 225, cls.y_scale * 733, black)
Пример #5
0
    def displayCenterText(self):
        screen,ft_sz,x_scale,y_scale= Panel.screen, \
             Panel.ft_sz,Panel.x_scale,Panel.y_scale
        center = [
            (b.current.x, b.current.y, b.current.z, b.colors)
            for b in self.my_cube_3d.cube.blocks
            if abs(b.current.x) + abs(b.current.y) + abs(b.current.z) == 1
        ]

        for s in s_map:
            c = [[c for c in x[3] if c != "-"] for x in center
                 if x[s[2][0]] == s[2][1]][0][0]
            if c == "b":
                printText(screen, s[0], "arial", ft_sz, x_scale * s[1][0],
                          y_scale * s[1][1], white)
            else:
                printText(screen, s[0], "arial", ft_sz, x_scale * s[1][0],
                          y_scale * s[1][1], black)
Пример #6
0
def game_loop():
    global gameExit
    clock = pygame.time.Clock()
    
    while not gameExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True
        button(screen,u"重开",300,550,60,30,green,bright_green,newGame,"None")
        button(screen,u"答案",400,550,60,30,green,bright_green,calcAnswer,"None")  
        button(screen,u"退出",500,550,60,30,green,bright_green,quitGame,"None")

        pygame.draw.rect(screen,(128,128,128),(300,500,260,30))
        if answer != "":
            printText(screen, answer, "kaiti", 25, 310, 500, black)

        
        clock.tick(30)
        pygame.display.update()
Пример #7
0
 def displayLayer(self,face,layer):
     face_index = l_map[face]["FACE"]
     (x_offset, y_offset) = self.lbd_pos[face]
     
     blocks = [item for item in self.blocks if 
         (item.block.current.x, item.block.current.y, item.block.current.z)
         in faces[face][layer]]
     for b in blocks:
         t = []
         for point in b.vertices:
             p = point.scale(x_offset, y_offset,0.7)
             t.append(p)
         c = b.colors[face_index]
         f = b.faces[face_index]
         pointlist = [(t[f[0]].x, t[f[0]].y), (t[f[1]].x, t[f[1]].y),
                  (t[f[2]].x, t[f[2]].y), (t[f[3]].x, t[f[3]].y)]                
         pygame.draw.polygon(self.screen,c,pointlist)
         pygame.draw.polygon(self.screen,(0,0,0),pointlist,2) 
         if  b.mark != "-":
             if c == (0,0,255):#蓝色的块,要先是白色的字,不然看不清
                 printText(self.screen,b.mark, "kaiti", 20, int((t[f[0]].x + t[f[2]].x)/2.0)-5 , int((t[f[0]].y + t[f[2]].y)/2.0)-10, (255,255,255))
             else:
                 printText(self.screen,b.mark, "kaiti", 20, int((t[f[0]].x + t[f[2]].x)/2.0)-5 , int((t[f[0]].y + t[f[2]].y)/2.0)-10, (0,0,0))
Пример #8
0
 def printTime(cls, msg):
     pygame.draw.rect(cls.screen, background,
                      (cls.x_scale * 50, cls.y_scale * 730,
                       cls.x_scale * 120, cls.y_scale * 30))
     printText(cls.screen, msg, "fangsong", cls.ft_sz, cls.x_scale * 53,
               cls.y_scale * 733, cls.white)
Пример #9
0
 def printLeft(cls, msg):
     pygame.draw.rect(cls.screen, cls.gray,
                      (cls.x_scale * 220, cls.y_scale * 690,
                       cls.x_scale * 560, cls.y_scale * 30))
     printText(cls.screen, msg, "fangsong", cls.ft_sz, cls.x_scale * 225,
               cls.y_scale * 693, black)