def slot_btn_clicked(self, flag): if flag == '生成密码': if self.cipher_type == 'PIN': # PIN码 print(self.code_type) bits = self.code_type & 0x0F mold = (self.code_type & 0xF0) >> 4 self.ciphers.clear() for i in range(self.ciphers_count): code = [ self.numerals_arabic[Utils.rand_int(0, 9)] for _ in range(bits) ] pin = Utils.get_pin(code, mold) print('sgsd', bits, mold, code, pin) self.ciphers.append(pin) self.shell.textEdit.clear() for each in self.ciphers: self.shell.textEdit.append(str(each)) self.shell.label_tip.setText("PIN 码是字符串,拷贝时根据类型自动转为数字或字符。") else: # 随机码、易记密码 if not self.char_set: return # print('生成密码') num = len(self.char_set) - 1 char_list = list(self.char_set) # print(char_list) self.ciphers.clear() for i in range(self.ciphers_count): pwd = [ char_list[Utils.rand_int(0, num)] for _ in range(self.cipher_length) ] s = "".join(pwd) # list 转成字符串 level = self.checker.check_password(s) - 1 # print('level', level) self.ciphers.append(s) tip = ' '.join(self.msg[level]) self.shell.label_tip.setText(f"密码:{tip}") # print(self.ciphers) # pe = QtWidgets.QTextEdit() pe = self.shell.textEdit pe.clear() for each in self.ciphers: pe.append(each) elif flag == '复制密码': # pe = QtWidgets.QTextEdit() pe = self.shell.textEdit text_cursor = pe.textCursor() text_cursor.select(QtGui.QTextCursor.LineUnderCursor) curText = text_cursor.selectedText() pyperclip.copy(curText)
def deal(self): """ 抓牌顺时针抓,打牌逆时针打 :return: """ if self.tiles_count < 54: # 不够起牌的 return self.dealer %= 4 # 轮流坐庄 4人麻将 # 庄家掷骰子找到二次掷骰人,并确定开门方向 # die1 = random.randint(1, 12) die_1 = Utils.rand_int(1, 12) door = (self.dealer + die_1 - 1) % 4 # 开门方向 # 二次掷骰子 # die2 = random.randint(1, 12) die_2 = Utils.rand_int(1, 12) dice = (door + 1) * 34 - die_2 * 2 # zero = dice % self.tiles_count # 开始摸牌的位置 new_round = self.round[dice:] new_round.extend(self.round[:dice]) self.round = new_round # 重新起算 # print(dice, len(self.round)) # print(self.data.cards2names(sorted(self.round))) # 返回新的排序队列,原队列不排序 self.lots = 0 # 给玩家发牌,顺时针抓牌 for k in range(3): # 发三次牌,每人每次拿连续的4张 for i in range(4): player_id = (i + self.dealer) % 4 # 循环坐庄 for j in range(4): # # 牌号、牌卡控件、翻牌等标志 # ID = self.round[self.lots] # 牌号,兼做排序用 index = j + 4 * k # 槽位 # player_id 也代表卡牌类型 # self.card_players[player_id][index] = Tile(self, ID, player_id, index) # self.card_players[player_id][index][0] = self.round.pop(0) # 牌号,兼做排序用 self.card_players[player_id][index] = [self.round.pop(0), 0] # 牌号,兼做排序用 # print(player_id, index, self.card_players[player_id][index]) self.lots += 1 # 每人再模一张,叫牌空置 for i in range(4): player_id = (i + self.dealer) % 4 # 从庄家开始 self.card_players[player_id][12] = [self.round.pop(0), 0] # 返回弹出值 # self.card_players[player_id][12] = Tile(self, self.round[self.lots], player_id, 12) # self.card_players[player_id][13] = Tile(self, 999, 4 + player_id, 13) # 叫牌,确保排在最后,每台不用清零 # self.tile_shadow = Tile(self, 999, 1, 13) # 把影子牌实例化 self.lots += 1 # for j in range(13, 18): # self.card_players[player_id][j] |= 0xff # 叫牌,确保排在最后,每台不用清零 self.card_players[player_id].sort() # 排序 # self.data.sortArray(self.card_players[player_id]) # 庄家不多摸,现在从庄家开始摸牌再发牌 self.speaker = self.dealer # 目前的摸/出牌者
def max_lib(self): row = Utils.rand_int(0, self.board_lines - 1) col = Utils.rand_int(0, self.board_lines - 1) # self.lot_cur += 1 state = 1 # 2 - self.lot_cur % 2 self.board_map[row][col] = [state, self.lot_cur] self._find(row, col, state) print(self.get_liberty(row, col))
def deal(self): """ 抓牌顺时针抓,打牌逆时针打 :return: """ if self.tiles_count < 54: # 不够起牌的 return self.dealer %= 4 # 轮流坐庄 4人麻将 # 庄家掷骰子找到二次掷骰人,并确定开门方向 # die1 = random.randint(1, 12) die_1 = Utils.rand_int(1, 12) door = (self.dealer + die_1 - 1) % 4 # 开门方向 # 二次掷骰子 # die2 = random.randint(1, 12) die_2 = Utils.rand_int(1, 12) dice = (door + 1) * 34 - die_2 * 2 # zero = dice % self.tiles_count # 开始摸牌的位置 new_round = self.round[dice:] new_round.extend(self.round[:dice]) self.round = new_round # 重新起算 # print(len(self.round)) self.lots = 0 # 给玩家发牌,顺时针抓牌 for k in range(3): # 发三次牌,每人每次拿连续的4张 for i in range(4): player_id = (i + self.dealer) % 4 # 循环坐庄 for j in range(4): index = j + 4 * k # 槽位 # player_id 也代表卡牌类型 self.card_players[player_id][index] = self.round.pop( 0) # 牌号,兼做排序用 self.lots += 1 # 每人再模一张,叫牌空置 for i in range(4): player_id = (i + self.dealer) % 4 # 从庄家开始 self.card_players[player_id][12] = self.round.pop(0) # 返回弹出值 self.lots += 1 # for j in range(13, 18): # self.card_players[player_id][j] |= 0xff # 叫牌,确保排在最后,每台不用清零 self.card_players[player_id].sort() # 排序 # 庄家不多摸,现在从庄家开始摸牌再发牌 self.speaker = self.dealer # 目前的摸/出牌者
def shuffling(self): tmp = [] for i in range(4): tmp.extend(DataMj.g_tile_ids[0:27]) if self.tiles_count > 108: tmp.extend(DataMj.g_tile_ids[27:34]) if self.tiles_count > 136: tmp.extend(DataMj.g_tile_ids[34:42]) self.dark_cards = sorted(tmp) # 都算暗牌 self.round.clear() # 随机洗牌 for i in range(self.tiles_count): index = Utils.rand_int(0, self.tiles_count - i - 1) self.round.append(tmp[index]) tmp.pop(index)
def shuffling(self): self.round.clear() for i in range(self.tiles_count): index = Utils.rand_int(0, self.tiles_count - 1) self.round.append(DataMj.g_tiles_ID[index])