Exemplo n.º 1
0
 def rect(self, z):
     screen.drawline(self.x, 100, self.x, 130, 1, 0x000000)
     self.x += 1
     if self.x == 180:
         self.timer.deinit()
         text.draw("加载完成", 88, 160, 0xff0000)
         self.quit_flag = True
Exemplo n.º 2
0
 def isDead(self):
     for j in range(0, len(self.back[0])):
         if self.back[0][j] != 0:
             print("GAME OVER")
             text.draw("GAME OVER", 34, 150, 0xFF0000, 0x000000)
             self.start = False
             break
Exemplo n.º 3
0
    def sub_cb(self, topic, message):
        message = message.decode()
        print("mark is :", self.mark)
        #赋值给choose
        self.choose = int(message)

        if (self.choose < 20):  #来自1号自己的信息,不判断
            print("对方尚未选择")
            return
        elif (self.choose > 20):
            self.mark = self.mark + 1  #修改标志,代表一方已完成选择
            print("player1 get choose is :", self.choose)
            #处理所得信息
            self.computerStatus = self.choose - 20
            #显示对方结果
            text.draw(str(self.computerStatus), 172, 152, 0x000000, 0xffffff)
        #判断胜负并显示结果
        if self.mark % 2 == 0:  #如果双方都完成选择
            resultMessage = " 平局 "
            if self.computerStatus == 0:
                return
            elif (self.playerStatus == self.computerStatus):
                self.equalNum += 1
            elif (self.playerStatus > self.computerStatus):
                self.playerScore += 1
                resultMessage = "%s胜出" % self.playerName
            elif (self.playerStatus < self.computerStatus):
                self.computerScore += 1
                resultMessage = "%s胜出" % self.computerName
            text.draw(resultMessage, 90, 210, 0x000000, 0xffffff)
            self.updateTotolArea()
Exemplo n.º 4
0
 def showKeyboard(self):
     for i in range(4):
         for j in range(4):
             num = self.keyboard[j][i]
             x = i * (self.button_width + self.margin) + 28
             y = (j + 1) * (self.button_height + self.margin) + 30
             text.draw(self.keydict[num], int(x), int(y), 0x000000,
                       0xffffff)
Exemplo n.º 5
0
def draw():
    win.fill(BGCOLOUR)
    win.blit(backgroundPic, (0, 0))

    for t in texts.values():
        t.draw()

    pygame.display.update()
Exemplo n.º 6
0
 def draw(self, surf, **kwargs):
     if DEBUG:
         fps = kwargs['fps']
         surf_size = surf.get_size()
         text.draw(surf, 'FPS: %s' % fps,
                   font__press_start_normal,
                   (10, surf_size[1] - 5),
                   color.WHITE,
                   halign='left', valign='bottom')
Exemplo n.º 7
0
    def on_draw(self):
        self.ima_background.blit(0, 0)

        for s in self.sprites:
            s.draw()

        if self.show_layer:
            self.layer.blit(0, 0)

        for text in self.texts:
            text.draw()
Exemplo n.º 8
0
    def draw_banner(self):
        rect = pg.Rect(0, 0, 500, 100)
        rect.center = (self.bbox.centerx, self.bbox.centery - 20)
        pg.draw.rect(self.screen, colors.FUCHSIA, rect)
        if self.winner:
            message = "{} wins!".format(
                self.player_name[logic.get_active_player(self.turn)])
        else:
            message = "It was a draw!"

        text.draw(self.screen, self.bbox.center, 50, colors.AQUA, "cb",
                  message)
Exemplo n.º 9
0
 def updateTotolArea(self):
     #汇总区域用于显示电脑和玩家的胜平负次数
     print("-------更新汇总区域-------")
     playerTotal = "%s赢了%d局" % (self.playerName, self.playerScore)
     computerTotal = "%s赢了%d局" % (self.computerName, self.computerScore)
     equalTotal = "平局%d次" % self.equalNum
     text.draw("-------------", 20, 240, 0x000000, 0xffffff)
     text.draw(playerTotal, 20, 256, 0x000000, 0xffffff)
     text.draw(computerTotal, 20, 272, 0x000000, 0xffffff)
     text.draw(equalTotal, 20, 288, 0x000000, 0xffffff)
Exemplo n.º 10
0
    def tick(self):
        self.clock.tick(60)
        moved = False
        for event in pygame.event.get():
            if event.type == QUIT:
                raise GameException
            elif event.type == KEYDOWN:
                if event.key == 273:
                    moved = self.snakeParts[0].moveTo(1)
                if event.key == 274:
                    moved = self.snakeParts[0].moveTo(2)
                if event.key == 276:
                    moved = self.snakeParts[0].moveTo(3)
                if event.key == 275:
                    moved = self.snakeParts[0].moveTo(4)
        if not moved:
            self.move_timer = self.move_timer + 1
            if self.move_timer == 10:
                self.move_timer = 0
                self.moveAllSnakeParts()
                self.snakeParts[0].moveTo(self.snakeParts[0].lastDirection)

        else:
            self.move_timer = 0
            self.moveAllSnakeParts()

        self.food_timer = self.food_timer - 1

        if self.food_timer == 0:
            self.addObject(
                food.Food(
                    random.randint(0, 100) * 8,
                    random.randint(0, 75) * 8, self.background))
            self.food_timer = random.randint(100, 200)

        for obj in self.gameObjects:
            for obj2 in self.gameObjects:
                if obj != obj2 and obj.rect.colliderect(obj2):
                    obj.collide(self, obj2)
                # obj2.collide(self, obj)

        toRemove = []
        for obj in self.gameObjects:
            if hasattr(obj, "dead"):
                if obj.dead:
                    toRemove.append(obj)
        for obj in toRemove:
            self.removeObject(obj)

        self.drawThing = text.draw(20, 20, self.background, self.score)
        self.rdrawThing = pygame.sprite.RenderPlain(self.drawThing)

        self.sprites.update()
        self.screen.blit(self.background, (0, 0))
        self.rdrawThing.draw(self.screen)
        self.sprites.draw(self.screen)
        pygame.display.flip()
Exemplo n.º 11
0
 def displayInit(self, x=10, y=10, w=222, h=303):
     #显示游戏规则信息
     mentionStr1 = "游戏规则:"
     mentionStr2 = "双方随机生成1-6的数"
     mentionStr3 = "按键1-3选择 按键4停止"
     text.draw(mentionStr1, 20, 20, 0x000000, 0xffffff)
     text.draw(mentionStr2, 20, 36, 0x000000, 0xffffff)
     text.draw(mentionStr3, 20, 52, 0x000000, 0xffffff)
     text.draw("-------------", 20, 68, 0x000000, 0xffffff)
     self.updateTotolArea()
     #设置游戏运行状态
     self.gameStart = True
Exemplo n.º 12
0
 def displayInit(self, x=10, y=10, w=222, h=303):
     #显示游戏规则信息
     mentionStr1 = "游戏规则:"
     mentionStr2 = "按键1.剪刀 按键2.石头"
     mentionStr3 = "按键3.布  按键4.结束"
     text.draw(mentionStr1, 20, 20, 0x000000, 0xffffff)
     text.draw(mentionStr2, 20, 36, 0x000000, 0xffffff)
     text.draw(mentionStr3, 20, 52, 0x000000, 0xffffff)
     text.draw("-------------", 20, 68, 0x000000, 0xffffff)
     self.updateTotolArea()
     #设置游戏运行状态
     self.gameStart = True
Exemplo n.º 13
0
    def tick(self):
        self.clock.tick(60)
        moved = False
        for event in pygame.event.get():
            if event.type == QUIT:
                raise GameException
            elif event.type == KEYDOWN:
                if event.key == 273:
                    moved = self.snakeParts[0].moveTo(1)
                if event.key == 274:
                    moved = self.snakeParts[0].moveTo(2)
                if event.key == 276:
                    moved = self.snakeParts[0].moveTo(3)
                if event.key == 275:
                    moved = self.snakeParts[0].moveTo(4)
        if not moved:
            self.move_timer = self.move_timer+1
            if self.move_timer == 10:
                self.move_timer = 0
                self.moveAllSnakeParts()
                self.snakeParts[0].moveTo(self.snakeParts[0].lastDirection)
                
                      
        else:
            self.move_timer = 0
            self.moveAllSnakeParts()

        self.food_timer = self.food_timer - 1

        if self.food_timer == 0:
            self.addObject(food.Food(random.randint(0,100)*8,random.randint(0,75)*8, self.background)) 
            self.food_timer = random.randint(100,200)
       
        for obj in self.gameObjects:
            for obj2 in self.gameObjects:
                if obj != obj2 and obj.rect.colliderect(obj2):
                    obj.collide(self, obj2)
                   # obj2.collide(self, obj)
        
        toRemove = []
        for obj in self.gameObjects:
                if hasattr(obj, "dead"):
                    if obj.dead:
                        toRemove.append(obj)
        for obj in toRemove:
            self.removeObject(obj)   
         
        self.drawThing = text.draw(20,20, self.background, self.score)
        self.rdrawThing = pygame.sprite.RenderPlain(self.drawThing) 
                            
        self.sprites.update()
        self.screen.blit(self.background,(0,0))
        self.rdrawThing.draw(self.screen)
        self.sprites.draw(self.screen)
        pygame.display.flip()
Exemplo n.º 14
0
    def draw_board(self):
        # Clear screen
        self.screen.fill(colors.WHITE)

        # Draw title across the top
        text.draw(self.screen, (self.bbox.centerx, self.bbox.y - 3), 30,
                  colors.BLACK, "cb", "Tic Tac Toe")

        # Current turn status
        text.draw(self.screen, (self.bbox.right, self.bbox.bottom + 3), 20,
                  colors.BLACK, "rt", "Current turn: {}".format(self.turn + 1))

        # Current move status
        text.draw(
            self.screen, (self.bbox.left, self.bbox.bottom + 3), 20,
            colors.BLACK, "lt", "Current move: {}".format(
                self.player_name[logic.get_active_player(self.turn)]))

        # Grid
        for x in [self.bbox.left + i * self.bbox.width // 3 for i in (1, 2)]:
            pg.draw.line(self.screen, colors.BLACK, (x, self.bbox.top),
                         (x, self.bbox.bottom), 5)
        for y in [self.bbox.top + i * self.bbox.height // 3 for i in (1, 2)]:
            pg.draw.line(self.screen, colors.BLACK, (self.bbox.left, y),
                         (self.bbox.right, y), 5)
Exemplo n.º 15
0
    def selectInit(self):
        # 变量初始化
        self.selectXi = 0
        self.selectYi = 0

        self.l_operand = 0
        self.r_operand = 0
        self.operator = 123
        self.result = 0
        self.dotFlag = 0
        self.dotLoc = 0

        # 显示初始化
        x = self.margin * 3
        y = self.button_height - self.margin * 3
        text.draw('            0', int(x), int(y), 0x000000, 0xffffff)

        # 选择初始化
        x = self.startX
        y = self.startY
        self.drawRect(x, y, x + self.button_width, y + self.button_height, 2,
                      0xff0000)
Exemplo n.º 16
0
def typing(ctx):
    """ Scene that shows a text that the player must type"""
    event = game.event.wait()
    if event.type == QUIT:
        game.quit()
        sys.exit(0)
    if event.type == KEYDOWN:
        key = game.key.name(event.key)

        if not "shift" in key and not ctx["handler"].finished():
            if KMOD_SHIFT & event.mod:
                key = ctx["handler"].shift_key(key)
            ctx["handler"].handle(key)
        if key == "escape":
            ctx["scene"], ctx["kind"] = Scene.MENU, None

    ctx["surface"].fill(BGCOLOR.value)
    font = ctx["font"]
    text.draw(ctx["surface"], *ctx["handler"].draw_text(), TEXTRECT, font)
    text.draw(ctx["surface"], *ctx["handler"].draw_score(), SCORERECT, font)

    game.display.update()

    return Scene.TYPING
Exemplo n.º 17
0
    def sub_cb(self, topic, message):
        message = message.decode()

        print("choose is :", self.choose)
        self.choose = int(message)
        print("mark is :", self.mark)
        if self.choose > 20:  #来自2号自己的信息,不判断
            print("对方尚未选择出拳")
            return
        else:
            self.mark = self.mark + 1
            print("player1 choose is :", self.choose)
            self.computerStatus = self.choose - 10
            if (self.computerStatus == 1):
                self.computerMessage = "%s出拳为:剪刀" % self.computerName
                bmp_jiandao.draw(150, 140)
            if (self.computerStatus == 2):
                self.computerMessage = "%s出拳为:石头" % self.computerName
                bmp_shitou.draw(150, 140)
            if (self.computerStatus == 3):
                self.computerMessage = "%s出拳为:布 " % self.computerName
                bmp_bu.draw(150, 140)

        #显示电脑和玩家的出拳信息
        text.draw(self.playerMessage, 20, 84, 0x000000, 0xffffff)
        text.draw(self.computerMessage, 20, 100, 0x000000, 0xffffff)

        #判断胜负并显示结果
        if self.mark % 2 == 0:  #如果双方都完成选择
            resultMessage = " 平局 "
            if self.computerStatus == 0:
                return
            elif (self.playerStatus == self.computerStatus):
                self.equalNum += 1
            elif (self.playerStatus == 1 and self.computerStatus == 3):
                resultMessage = "%s胜出" % self.playerName
                self.playerScore += 1
            elif (self.playerStatus == 2 and self.computerStatus == 1):
                resultMessage = "%s胜出" % self.playerName
                self.playerScore += 1
            elif (self.playerStatus == 3 and self.computerStatus == 2):
                resultMessage = "%s胜出" % self.playerName
                self.playerScore += 1
            elif (self.computerStatus == 1 and self.playerStatus == 3):
                resultMessage = "%s胜出" % self.computerName
                self.computerScore += 1
            elif (self.computerStatus == 2 and self.playerStatus == 1):
                resultMessage = "%s胜出" % self.computerName
                self.computerScore += 1
            elif (self.computerStatus == 3 and self.playerStatus == 2):
                resultMessage = "%s胜出" % self.computerName
                self.computerScore += 1

            text.draw(resultMessage, 90, 210, 0x000000, 0xffffff)
            self.updateTotolArea()
Exemplo n.º 18
0
def text_with_shadow(msg,
                     x=False,
                     y=False,
                     fgColor=0x000000,
                     bgColor=0xEEEEEE,
                     shadowBgColor=0xCCCCCC,
                     shadowOffsetX=0,
                     shadowOffsetY=2):
    msg_len = len(msg)

    if x is False:
        x = (SW - CW * msg_len) // 2
    if y is False:
        y = (SH - CH) // 2

    if shadowBgColor is not False:
        text.draw(" " * msg_len, x + shadowOffsetX, y + shadowOffsetY, fgColor,
                  shadowBgColor)

    if bgColor is False:
        text.draw(msg, x, y, fgColor)
    else:
        text.draw(msg, x, y, fgColor, bgColor)
Exemplo n.º 19
0
 def printscore(self, msg, score):
     print(msg + str(score))
     text.draw(msg + str(score), 20, 250, 0xFF0000, 0x000000)
Exemplo n.º 20
0
    def is_win(self, i, j, k):  #判断胜负

        start_y = 0
        end_y = 10
        if j - 4 >= 0:
            start_y = j - 4
        if j + 4 <= 10:
            end_y = j + 4
        count = 0
        for pos_y in range(start_y, end_y + 1):  #判断纵向胜负
            if self.board[pos_y][i][2] == k and k == 1:
                count += 1

                if count >= 5:
                    text.draw("绿色方胜", 88, 160, 0xff0000)
            else:
                count = 0
        for pos_y in range(start_y, end_y + 1):
            if self.board[pos_y][i][2] == k and k == 2:
                count += 1

                if count >= 5:
                    text.draw("黑色方胜", 88, 160, 0xff0000)
            else:
                count = 0

        start_x = 0
        end_x = 10
        if i - 4 >= 0:
            start_x = i - 4
        if i + 4 <= 10:
            end_x = i + 4
        count = 0
        for pos_x in range(start_x, end_x + 1):  #判断横向胜负
            if self.board[j][pos_x][2] == k and k == 1:
                count += 1

                if count >= 5:
                    text.draw("绿色方胜", 88, 160, 0xff0000)
            else:
                count = 0
        for pos_x in range(start_x, end_x + 1):
            if self.board[j][pos_x][2] == k and k == 2:
                count += 1

                if count >= 5:
                    text.draw("黑色方胜", 88, 160, 0xff0000)
            else:
                count = 0

        count = 0
        s = j - i
        start = start_y
        end = end_x + s
        if j > i:
            start = start_x + s
            end = end_y
        for index in range(start, end + 1):  #判断斜方向胜负(左上右下)
            if self.board[index][index - s][2] == k and k == 1:
                count += 1

                if count >= 5:
                    text.draw("绿色方胜", 88, 160, 0xff0000)
            else:
                count = 0
        for index in range(start, end + 1):
            if self.board[index][index - s][2] == k and k == 2:
                count += 1

                if count >= 5:
                    text.draw("黑色方胜", 88, 160, 0xff0000)
            else:
                count = 0

        count = 0
        s = j + i

        if j + i <= 10:
            start = start_y
            end = s - start_x
        if j + i > 10:
            start = s - 10
            end = 10
        if s >= 4 and s <= 16:

            for index in range(start, end + 1):  #判断斜方向胜负(左下右上)
                if self.board[index][s - index][2] == k and k == 1:
                    count += 1

                    if count >= 5:
                        text.draw("绿色方胜", 88, 160, 0xff0000)
                else:
                    count = 0
            for index in range(start, end + 1):
                if self.board[index][s - index][2] == k and k == 2:
                    count += 1

                    if count >= 5:
                        text.draw("黑色方胜", 88, 160, 0xff0000)
                else:
                    count = 0
Exemplo n.º 21
0
    def draw(self, pos, color, num):
        x = pos[0] * 55 + self.x
        y = pos[1] * 55 + self.y

        text.draw("   ", x + 3, y + 19, color, 0x000000)

        if num < 16:
            text.draw(str(num), x + 19, y + 19, color, 0x000000)
        elif num < 128:
            text.draw(str(num), x + 11, y + 19, color, 0x000000)
        elif num < 1024:
            text.draw(str(num), x + 3, y + 19, color, 0x000000)
        elif num == 1024:
            text.draw("1K", x + 11, y + 19, color, 0x000000)
        else:
            text.draw("2K", x + 11, y + 19, color, 0x000000)
Exemplo n.º 22
0
    def keyboardEvent(self, key):
        # 右移选择键
        if self.keymatch[key] == "Key1":
            # 取消前一个选择
            num = self.keyboard[self.selectYi][self.selectXi]
            x = self.selectXi * (self.button_width + self.margin) + self.startX
            y = self.selectYi * (self.button_height +
                                 self.margin) + self.startY
            self.drawRect(x, y, x + self.button_width, y + self.button_height,
                          2, 0x00ff00)
            # 选择右边一个
            self.selectXi = (self.selectXi + 1) % 4
            num = self.keyboard[self.selectYi][self.selectXi]
            x = self.selectXi * (self.button_width + self.margin) + self.startX
            self.drawRect(x, y, x + self.button_width, y + self.button_height,
                          2, 0xff0000)

        # 纵向移动键
        elif self.keymatch[key] == "Key2":
            # 取消前一个选择
            num = self.keyboard[self.selectYi][self.selectXi]
            x = self.selectXi * (self.button_width + self.margin) + self.startX
            y = self.selectYi * (self.button_height +
                                 self.margin) + self.startY
            self.drawRect(x, y, x + self.button_width, y + self.button_height,
                          2, 0x00ff00)
            # 选择右边一个
            self.selectYi = (self.selectYi + 1) % 4
            num = self.keyboard[self.selectYi][self.selectXi]
            y = self.selectYi * (self.button_height +
                                 self.margin) + self.startY
            self.drawRect(x, y, x + self.button_width, y + self.button_height,
                          2, 0xff0000)

        # 确认键
        elif self.keymatch[key] == "Key3":
            num = self.keyboard[self.selectYi][self.selectXi]
            self.sendData(num)
            # 清空显示区
            x = self.margin * 3
            y = self.button_height - self.margin * 3
            text.draw('            ', int(x), int(y), 0x000000, 0xffffff)
            # 显示结果
            results = str(self.result)
            length = len(results)
            if length >= 13:
                length = 13
            x = self.screen_width - self.margin * 3 - 16 * length
            y = self.button_height - self.margin * 3
            text.draw(results[0:13], int(x), int(y), 0x000000, 0xffffff)

        # 清空键
        else:
            # 取消前一个选择
            num = self.keyboard[self.selectYi][self.selectXi]
            x = self.selectXi * (self.button_width + self.margin) + self.startX
            y = self.selectYi * (self.button_height +
                                 self.margin) + self.startY
            self.drawRect(x, y, x + self.button_width, y + self.button_height,
                          2, 0x00ff00)
            # 按键选择初始化
            self.selectInit()
Exemplo n.º 23
0
def on_draw():
    render.draw()
    text.draw()
Exemplo n.º 24
0
    def draw_layout(self):
        #draws two side banners
        pygame.draw.rect(self.screen, const.LIGHT_YELLOW,
                         (0, 0, const.OFFSET, const.HEIGHT))
        pygame.draw.rect(
            self.screen, const.LIGHT_YELLOW,
            (const.WIDTH - const.OFFSET, 0, const.OFFSET, const.HEIGHT))

        #draws main play field (empty)
        for i in range(const.HEIGHT // const.SQUARE):
            for j in range(10):
                self.draw_block(j, i, const.GRAY, const.BLACK)

        #draws texts on side banners
        for text in self.texts:
            text.draw()

        #draws all ocouppied squares
        for key in self.ocuppied:
            color = self.ocuppied[key]
            if (color != const.BLACK):
                self.draw_block(key[0], key[1], const.WHITE, color)

        #draws logo + buttons on starting screen (START)
        if (self.state == const.START):
            pygame.draw.rect(self.screen, const.LIGHT_BLUE,
                             (self.center_x, self.center_y, const.ER_WIDTH,
                              const.ER_HEIGHT))
            self.logo.draw()

            self.play_button.draw(self.screen)
            self.help_button.draw(self.screen)
        #draws layout for "How to play" state(HELP)
        elif (self.state == const.HELP):
            pygame.draw.rect(
                self.screen, const.LIGHT_BLUE,
                (const.OFFSET,
                 (const.HEIGHT // const.SQUARE) // 2 * const.SQUARE,
                 const.WIDTH - 2 * const.OFFSET, const.HEIGHT))

            self.keys.draw()

            self.active.draw(self.draw_block)

            if (self.study_phase > 0):
                self.prev_button.draw(self.screen)

            if (self.study_phase < 2):
                self.next_button.draw(self.screen)

            if (self.study_phase == 2):
                self.help_end_button.draw(self.screen)

            self.help_text.draw()
            self.help_info.draw()

        #draws 3 next game objects + active game object (GAME)
        elif (self.state == const.GAME):
            self.next1.draw(self.draw_block)
            self.next2.draw(self.draw_block)
            self.next3.draw(self.draw_block)
            self.active.draw(self.draw_block)
            self.pause_button.draw(self.screen)

        #draws layout for pause state state(PAUSE)
        elif (self.state == const.PAUSE):
            self.next1.draw(self.draw_block)
            self.next2.draw(self.draw_block)
            self.next3.draw(self.draw_block)
            self.active.draw(self.draw_block)
            self.pause_button.draw(self.screen)

            pygame.draw.rect(self.screen, const.LIGHT_BLUE,
                             (self.center_x, self.center_y, const.ER_WIDTH,
                              const.ER_HEIGHT))
            self.pause_text.draw()
            self.retry_button.draw(self.screen)
            self.resume_button.draw(self.screen)
            self.menu_button.draw(self.screen)

        #draws texts + button on ending screen (GAME_OVER)
        else:
            pygame.draw.rect(self.screen, const.LIGHT_BLUE,
                             (self.center_x, self.center_y, const.ER_WIDTH,
                              const.ER_HEIGHT))
            for text in self.end_report:
                text.draw()

            self.retry_button.draw(self.screen)
Exemplo n.º 25
0
y_step = 0
step_count = 0
lcd_refresh()
while True:
    utime.sleep_ms(30)
    key_scan()
    i = 0
    x_step = 0
    y_step = 0
    for state in key_state:
        if state == 1:
            key_state[i] = 0
            if i == 0:
                x_step = 1
            elif i == 1:
                y_step = 1
            elif i == 2:
                x_step = -1
            elif i == 3:
                y_step = -1
        i += 1
    if x_step != 0 or y_step != 0:
        if boy_move_xy(boy_x, boy_y, x_step, y_step) == 0:
            boy_x += x_step
            boy_y += y_step
            step_count += 1
            text.draw(str(step_count), 0, 250, 0xff0000, 0xffffff)
            if state_check() == 0:
                print('胜利!')
                text.draw('胜利!', 0, 280, 0xff0000)
Exemplo n.º 26
0
t1 = a[0]
t2 = a[1]
t3 = a[2]
t4 = a[3]
t5 = a[4]
t6 = a[5]
t7 = a[6]
#绘制界面
week0 = " 一 二 三 四 五 六 日"
week1 = " 01020304050607 "
week2 = " 08091011121314"
week3 = " 15161718192021"
week4 = " 22232425262728"
week5 = " 293031"
#显示日期
text.draw(week0, 8, 0, BLACK, 0xffffff)
text.draw(week1, 0, 30, BLACK, 0xffffff)
text.draw(week2, 0, 60, BLACK, 0xffffff)
text.draw(week3, 0, 90, BLACK, 0xffffff)
text.draw(week4, 0, 120, BLACK, 0xffffff)
text.draw(week5, 0, 150, BLACK, 0xffffff)
#划线分隔日期
#竖线
screen.drawline(50, 30, 50, 170, 1, 0x000000)
screen.drawline(82, 30, 82, 170, 1, 0x000000)
screen.drawline(114, 30, 114, 170, 1, 0x000000)
screen.drawline(146, 30, 146, 170, 1, 0x000000)
screen.drawline(178, 30, 178, 170, 1, 0x000000)
screen.drawline(210, 30, 210, 170, 1, 0x000000)
#横线
screen.drawline(10, 50, 240, 50, 1, 0x000000)
Exemplo n.º 27
0
    def pressKeyboardEvent(self, key):
        keymatch = ["Key1", "Key2", "Key3", "Key4"]
        #游戏还未开始,不必处理键盘输入
        if (self.gameStart == False):
            return
        print(keymatch[key])
        self.mark = self.mark + 1
        if (keymatch[key] == "Key1"):
            self.playerStatus = 1
            self.playerMessage = "%s出拳为:剪刀" % self.playerName
            self.client.publish(self.TOPIC2,
                                "2" + self.d[self.playerStatus - 1])
            bmp_jiandao.draw(40, 140)
        elif (keymatch[key] == "Key2"):
            self.playerStatus = 2
            self.playerMessage = "%s出拳为:石头" % self.playerName
            self.client.publish(self.TOPIC2,
                                "2" + self.d[self.playerStatus - 1])
            bmp_shitou.draw(40, 140)
        elif (keymatch[key] == "Key3"):
            self.playerStatus = 3
            self.playerMessage = "%s出拳为:布 " % self.playerName
            self.client.publish(self.TOPIC2,
                                "2" + self.d[self.playerStatus - 1])
            bmp_bu.draw(40, 140)
        else:
            text.draw("游戏结束", 90, 210, 0x000000, 0xffffff)
            #设置游戏运行状态
            self.gameStart = False
            return

        #电脑的出拳为一个随机值

        #二号玩家收到11-13

        print("choose is :", self.choose)
        if (self.choose > 20 or self.mark % 2 == 1):
            print("对方尚未选择出拳")
            return
        else:
            self.computerStatus = self.choose - 10
            if (self.computerStatus == 1):
                self.computerMessage = "%s出拳为:剪刀" % self.computerName
                bmp_jiandao.draw(150, 140)
            if (self.computerStatus == 2):
                self.computerMessage = "%s出拳为:石头" % self.computerName
                bmp_shitou.draw(150, 140)
            if (self.computerStatus == 3):
                self.computerMessage = "%s出拳为:布 " % self.computerName
                bmp_bu.draw(150, 140)

        #显示电脑和玩家的出拳信息
        text.draw(self.playerMessage, 20, 84, 0x000000, 0xffffff)
        text.draw(self.computerMessage, 20, 100, 0x000000, 0xffffff)

        #判断胜负并显示结果
        resultMessage = " 平局 "
        if self.computerStatus == 0:
            return
        elif (self.playerStatus == self.computerStatus):
            self.equalNum += 1
        elif (self.playerStatus == 1 and self.computerStatus == 3):
            resultMessage = "%s胜出" % self.playerName
            self.playerScore += 1
        elif (self.playerStatus == 2 and self.computerStatus == 1):
            resultMessage = "%s胜出" % self.playerName
            self.playerScore += 1
        elif (self.playerStatus == 3 and self.computerStatus == 2):
            resultMessage = "%s胜出" % self.playerName
            self.playerScore += 1
        elif (self.computerStatus == 1 and self.playerStatus == 3):
            resultMessage = "%s胜出" % self.computerName
            self.computerScore += 1
        elif (self.computerStatus == 2 and self.playerStatus == 1):
            resultMessage = "%s胜出" % self.computerName
            self.computerScore += 1
        elif (self.computerStatus == 3 and self.playerStatus == 2):
            resultMessage = "%s胜出" % self.computerName
            self.computerScore += 1

        text.draw(resultMessage, 90, 210, 0x000000, 0xffffff)
        self.updateTotolArea()
Exemplo n.º 28
0
    def pressKeyboardEvent(self, key):
        keymatch = ["Key1", "Key2", "Key3", "Key4"]
        #游戏还未开始,不必处理键盘输入
        if (self.gameStart == False):
            return
        #处理按键
        print(keymatch[key])
        self.mark = self.mark + 1
        if (keymatch[key] == "Key1"):
            self.roll()
            self.client.publish(self.TOPIC2, "1" + str(self.playerStatus))
            text.draw(str(self.playerStatus), 52, 168, 0x000000, 0xffffff)
        elif (keymatch[key] == "Key2"):
            self.roll()
            self.client.publish(self.TOPIC2, "1" + str(self.playerStatus))
            text.draw(str(self.playerStatus), 52, 168, 0x000000, 0xffffff)
        elif (keymatch[key] == "Key3"):
            self.roll()
            self.client.publish(self.TOPIC2, "1" + str(self.playerStatus))
            text.draw(str(self.playerStatus), 52, 168, 0x000000, 0xffffff)
        else:
            text.draw("游戏结束", 90, 210, 0x000000, 0xffffff)
            #设置游戏运行状态
            self.gameStart = False
            return

        #对方玩家选择

        #一号玩家收到21-26

        print("choose is :", self.choose)
        if (self.choose < 20):  #来自1号自己的信息,不判断
            print("对方尚未选择")
            return
        elif (self.choose > 20):
            print("player1 get choose is :", self.choose)
            #处理所得信息
            self.computerStatus = self.choose - 20
            #显示对方结果
            text.draw(str(self.computerStatus), 172, 152, 0x000000, 0xffffff)

        #判断胜负并显示结果
        if self.mark % 2 == 0:  #如果双方都完成选择
            resultMessage = " 平局 "
            if self.computerStatus == 0:
                return
            elif (self.playerStatus == self.computerStatus):
                self.equalNum += 1
            elif (self.playerStatus > self.computerStatus):
                self.playerScore += 1
                resultMessage = "%s胜出" % self.playerName
            elif (self.playerStatus < self.computerStatus):
                self.computerScore += 1
                resultMessage = "%s胜出" % self.computerName
            text.draw(resultMessage, 90, 210, 0x000000, 0xffffff)
            self.updateTotolArea()
Exemplo n.º 29
0
 def roll(self):
     #获得随机数并更新显示
     result1 = randint(1, 6)
     text.draw(str(result1), 52, 152, 0x000000, 0xffffff)
     self.playerStatus = result1
Exemplo n.º 30
0
    def pressKeyboardEvent(self, key):
        keymatch = ["Key1", "Key2", "Key3", "Key4"]
        #游戏还未开始,不必处理键盘输入
        if (self.gameStart == False):
            return

        print(keymatch[key])
        if (keymatch[key] == "Key1"):
            self.playerStatus = 1
            self.playerMessage = "%s出拳为:剪刀" % self.playerName
            bmp_jiandao.draw(40, 140)
        elif (keymatch[key] == "Key2"):
            self.playerStatus = 2
            self.playerMessage = "%s出拳为:石头" % self.playerName
            bmp_shitou.draw(40, 140)
        elif (keymatch[key] == "Key3"):
            self.playerStatus = 3
            self.playerMessage = "%s出拳为:布 " % self.playerName
            bmp_bu.draw(40, 140)
        else:
            text.draw("游戏结束", 90, 210, 0x000000, 0xffffff)
            #设置游戏运行状态
            self.gameStart = False
            return

        #电脑的出拳为一个随机值
        self.computerStatus = random.randint(1, 3)
        print(self.computerStatus)
        if (self.computerStatus == 1):
            self.computerMessage = "%s出拳为:剪刀" % self.computerName
            bmp_jiandao.draw(150, 140)
        if (self.computerStatus == 2):
            self.computerMessage = "%s出拳为:石头" % self.computerName
            bmp_shitou.draw(150, 140)
        if (self.computerStatus == 3):
            self.computerMessage = "%s出拳为:布 " % self.computerName
            bmp_bu.draw(150, 140)

        #显示电脑和玩家的出拳信息
        text.draw(self.playerMessage, 20, 84, 0x000000, 0xffffff)
        text.draw(self.computerMessage, 20, 100, 0x000000, 0xffffff)

        #判断胜负并显示结果
        resultMessage = " 平局 "
        if (self.playerStatus == self.computerStatus):
            self.equalNum += 1
        elif (self.playerStatus == 1 and self.computerStatus == 3):
            resultMessage = "%s胜出" % self.playerName
            self.playerScore += 1
        elif (self.playerStatus == 2 and self.computerStatus == 1):
            resultMessage = "%s胜出" % self.playerName
            self.playerScore += 1
        elif (self.playerStatus == 3 and self.computerStatus == 2):
            resultMessage = "%s胜出" % self.playerName
            self.playerScore += 1
        else:
            resultMessage = "%s胜出" % self.computerName
            self.computerScore += 1

        text.draw(resultMessage, 90, 210, 0x000000, 0xffffff)
        self.updateTotolArea()
Exemplo n.º 31
0
 def show(self):
     _text.draw(self.text, self.x, self.y, self.fg, self.bg)
Exemplo n.º 32
0
def menu(ctx):
    """ Main menu scene"""
    event = game.event.wait()
    if event.type == QUIT:
        game.quit()
        sys.exit(0)
    if event.type == KEYDOWN:
        if event.key == K_LEFT:
            ctx["current_mode"] = (ctx["current_mode"] + 3) % 4
        elif event.key == K_RIGHT:
            ctx["current_mode"] = (ctx["current_mode"] + 1) % 4
        elif event.key == K_DOWN:
            ctx["current_mode"] = (ctx["current_mode"] + 2) % 4
        elif event.key == K_UP:
            ctx["current_mode"] = (ctx["current_mode"] + 2) % 4
        elif event.key == K_RETURN:
            ctx["scene"], ctx["kind"] = Scene.TYPING, list(
                text.Kind)[ctx["current_mode"]]
            return
        elif event.key == K_BACKQUOTE:
            ctx["scene"] = Scene.SCORE
            return

    font = ctx["font"]
    padding = 30
    ctx["surface"].fill(BGCOLOR.value)

    MENU1 = (WIDTH / 2 - font.size("Uniform")[0] - padding,
             HEIGHT / 2 - font.size("Uniform")[1] - padding, 100, 100)
    MENU2 = (WIDTH / 2 + padding,
             HEIGHT / 2 - font.size("Weighted")[1] - padding, 100, 100)
    MENU3 = (WIDTH / 2 -
             (font.size("Uniform")[0] + font.size("Digits")[0]) / 2 - padding,
             HEIGHT / 2 + padding, 100, 100)
    MENU4 = (WIDTH / 2 +
             (font.size("Reduced")[0] - font.size("Digits")[0]) / 2 + padding,
             HEIGHT / 2 + padding, 100, 100)

    text1 = font.render(
        "Normal", FONTANTIALIAS,
        Color.YELLOW.value if ctx["current_mode"] != 0 else Color.RED.value)
    text2 = font.render(
        "Weighted", FONTANTIALIAS,
        Color.YELLOW.value if ctx["current_mode"] != 1 else Color.RED.value)
    text3 = font.render(
        "Code", FONTANTIALIAS,
        Color.YELLOW.value if ctx["current_mode"] != 2 else Color.RED.value)
    text4 = font.render(
        "Reduced", FONTANTIALIAS,
        Color.YELLOW.value if ctx["current_mode"] != 3 else Color.RED.value)

    descriptions = [
        "Type words selected uniformally at random",
        "Type words favoring those whose letters you are slower at typing",
        "Type expressions that resemble code",
        f"Type words that contain the letters in the  set '{REDUCEDALPHABET}'"
    ]
    description = descriptions[ctx["current_mode"]]

    DESCRITION = (max(
        2 * padding,
        (WIDTH - font.size(descriptions[ctx["current_mode"]])[0]) /
        2), HEIGHT - 2 * font.size(descriptions[ctx["current_mode"]])[1] -
                  padding, WIDTH - 3 * padding, 200)
    text.draw(ctx["surface"], description,
              [Color.GREY.value for i in range(len(description))], DESCRITION,
              font)
    ctx["surface"].blit(text1, MENU1)
    ctx["surface"].blit(text2, MENU2)
    ctx["surface"].blit(text3, MENU3)
    ctx["surface"].blit(text4, MENU4)
    game.display.update()

    ctx["scene"] = Scene.MENU