def print_game_board(): global game_font gameDisplay.fill((0,0,0)) label = game_font.render("Next block:", 1, (255,255,255)) gameDisplay.blit(label, (240, 25)) label = game_font.render("Score:", 1, (255, 255, 255)) gameDisplay.blit(label, (240, 112)) label = game_font.render(str(score), 1, (255,255,255)) gameDisplay.blit(label, (240, 132)) pygame.draw.line(gameDisplay, (0, 0, 255), (20, 20), (20, 420), 1) pygame.draw.line(gameDisplay, (0, 0, 255), (20, 420), (220, 420), 1) pygame.draw.line(gameDisplay, (0, 0, 255), (220, 420), (220, 20), 1) temp_game_board = copy.deepcopy(game_board) temp_block = block.get_block(current_block_type, current_block_rotation) for y in range(4): for x in range(4): if temp_block[x][y] != 0: temp_game_board[current_x_position + x][current_y_position + y] = temp_block[x][y] for y in range(BOARD_Y_SIZE): for x in range(BOARD_X_SIZE): if temp_game_board[x][y] != 0 and y > 1: pygame.draw.rect(gameDisplay, (255, 0, 0), ((22*(x+1))-(x*2), (20*(y+1)-39), 18, 18), 0) temp_block = block.get_block(next_block_type, 0) for y in range(4): for x in range(4): if temp_block[x][y] != 0: pygame.draw.rect(gameDisplay, (255, 0, 0), ((225 + 22*(x+1))-(x*2), (20*(y+1) + 20), 18, 18), 0) if game_over == True: game_font = pygame.font.SysFont("monospace", 25) label = game_font.render("GAME OVER", 1, (255,255,255)) gameDisplay.blit(label, (120, 120)) pygame.display.update()
def search_button(): search_input = "".encode('utf-8') search_result = "" for key, value in request.form.items(): # print("key: {0}, value: {1}".format(key, value)) search_input = value.encode('utf-8') if search_input: blockhash = search_input print('blockhash') block_data = block.get_block(blockhash,None) txes = block.get_block_txes(blockhash,None) if block_data and txes: print('blockhash block.html') return render_template('block.html', block=block_data, txes=txes) else: print('blockheight') blockheight = search_input block_data = block.get_block(None,blockheight) txes = block.get_block_txes(None,blockheight) if block_data and txes: print('blockheight block.html') return render_template('block.html', block=block_data, txes=txes) else: print('transaction') try: txhash = search_input tx = transaction.get_tx(txhash) input_data = transaction.get_input_data(txhash) output_data = transaction.get_output_data(txhash) if tx and input_data and output_data: return render_template('transaction.html', tx=tx, input=input_data, output=output_data) else: try: print('address 1') address_input = search_input address_data = address.get_txes_data(address_input) if address_data: return render_template('address.html', address_data=address_data) except: pass except: try: print('address 2') address_input = search_input address_data = address.get_txes_data(address_input) if address_data: return render_template('address.html', address_data=address_data) except: pass last_blocks = block.get_last_blocks(5) print('new_blocks.html') return render_template('new_blocks.html', blocks=last_blocks)
def linkBlock(self, nettype, blockhash, txids): conn = network_conn(nettype) with database.transaction(conn, isolation='serializable') as conn: block = get_block(conn, blockhash) if not block: raise ttypes.NotFound() link_txes(conn, block, txids)
def get_output_data(tx_id, p_address=None): """ Get output data from transaction tx_id = transaction ID p_address = data for a specific address """ tx = get_tx(tx_id) value = int() data = [] for vout in tx['vout']: addys = [] value = vout['value'] block_height = block.get_block(tx['blockhash'], None)['height'] if 'addresses' in vout['scriptPubKey']: for address in vout['scriptPubKey']['addresses']: # print(address) addys.append(address) if (p_address is None) or (p_address in addys): vout_data = { 'tx': tx_id, 'address': addys, 'value': value, 'time': tx['time'], 'block': block_height } data.append(vout_data) return data
def get_input_data(tx_id, p_address=None): """ Get input data from transaction tx_id = transaction ID p_address = data for a specific address """ tx = get_tx(tx_id) addy = str() value = int() data = [] for vin in tx['vin']: if 'txid' in vin: input_tx = get_tx(vin['txid']) for input_vout in input_tx['vout']: if (input_vout['scriptPubKey']['type'] == 'pubkey' or input_vout['scriptPubKey']['type'] == 'pubkeyhash') and vin['vout'] == input_vout['n']: for address in input_vout['scriptPubKey']['addresses']: if p_address is None or p_address == address: addy = address value = input_vout['value'] block_height = block.get_block( tx['blockhash'], None)['height'] vin_data = { 'tx': tx_id, 'address': addy, 'value': value, 'tx_vin': vin['txid'], 'time': tx['time'], 'block': block_height } data.append(vin_data) return data
def die(self): self.kill() ingame.BLOCKS.add(block.get_block([self.rect.centerx, 0], random.choice(color.LIST), special=True)) UFO.invade.stop() self.velocity[0] = 0 self.position = list(START_POS) self.rect.topleft = START_POS self.state = UFO.STATES.IDLE
def move_obj(state, mv_obj, xsteps=0, ysteps=0): old_x = mv_obj['x'] old_y = mv_obj['y'] tar_x = old_x + xsteps tar_y = old_y + ysteps #Execute any collision interactions between moving object and the objects in target block tar_block = block.get_block(state, tar_x, tar_y) if tar_block is not None: pre_collision_handler(state, mv_obj, tar_block, xsteps, ysteps) #Execute the move if target block is not occupied by a solid object tar_block = block.get_block( state, tar_x, tar_y) #Refresh tar_block as it might have changed during collision if block.check_solidity(tar_block) is False: add_obj(state, mv_obj, tar_x, tar_y) del_obj(state, mv_obj, old_x, old_y) post_collision_handler(state, tar_block)
def vanish(self): global balls balls.add(self) ingame.BLOCKS.add(block.get_block([self.rect.centerx, 0], self.color)) self.remove(ingame.ENEMIES) self.position = [-300, -300] self.rect.topleft = self.position self.state = self.__class__.STATES.IDLE
def getgamestate(): px = getRectAsImage((0, 0, 1920, 1080)) board_state = [] current_active = None for y in range(0, 20): board_line = [] for x in range(0, 10): ypos = startingY + int(deltaY * y) xpos = startingX + int(deltaX * x) #if(y == 2 and x > 2 and x < 7): #in the upper "attackers" zone #ypos -= 2 #elif(y == 3 and x > 2 and x < 7): #in the lower "attackers" zone #ypos += 3 if (y == 19): ypos -= 2 pixelsamples = [] for i in range(ypos - 7, ypos + 7): pixelsamples.append(px.getpixel((xpos, i))) px.load()[xpos, i] = (255, 0, 255) for j in range(xpos - 7, xpos + 7): pixelsamples.append(px.getpixel((j, ypos))) px.load()[j, ypos] = (255, 0, 255) blocktype = get_block(pixelsamples) #if(y < 2 and int(blocktype) < int(Block['ACTIVE_O'])): #blocktype = Block['EMPTY'] if (blocktype >= int(Block['ACTIVE_O'])): current_active = int(blocktype) if (blocktype == Block['GHOST'] or int(blocktype) >= int(Block['ACTIVE_O']) or blocktype == Block['EMPTY']): board_line.append(0) else: board_line.append(1) board_state.append(board_line) numpy_board_state = array(board_state) if (current_active != None): actual_queue = array([tetrominoQueue[current_active]]) move = get_command(actual_queue, numpy_board_state)[0] print("Best move = {}".format(move)) return move else: return [None, None]
def start_new_round(): global game_board global current_x_position global current_y_position global current_block_type global current_block_rotation global next_block_type global new_round temp_block = block.get_block(current_block_type, current_block_rotation) for y in range(4): for x in range(4): if temp_block[x][y] != 0: game_board[current_x_position + x][current_y_position + y] = 8 clear_full_lines() current_block_type = next_block_type next_block_type = random.randint(1, 7) current_block_rotation = 0 current_x_position = 2 current_y_position = 2 new_round = True
def route_block_no(height): print('app.route /blockno/<height>') block_data = block.get_block(None, height) txes = block.get_block_txes(None, height) return render_template('block.html', block=block_data, txes=txes)
def route_block(blockhash): print('app.route /block/<blockhash>') block_data = block.get_block(blockhash,None) txes = block.get_block_txes(blockhash,None) return render_template('block.html', block=block_data, txes=txes)
print('Please provide employee details!') e_id = str(input('Employee id: ')) e_type = str(input('Employee type (such as Doctor, nurse, etc): ')) name = str(input('Employee name: ')) age = input('Age: ') contact_number = input('Contact number: ') add_employee(e_id, e_type, name, age, contact_number) print('Employee list updated!' + '\n') if option == '4': clear() print('Please provide patient details!') p_id = str(input('Patient id: ')) name = str(input('Patient name: ')) age = input('Age: ') contact_number = input('Contact number: ') doctor_name = str(input("Patient's doctor: ")) disease = str(input('Disease of patient: ')) address = str(input("Patient's address: ")) add_patient(p_id, name, age, contact_number, doctor_name, disease, address) print('Patient list updated!' + '\n') if option == '5': clear() get_block() print() if option == 'q': run_app = False
def getBlock(self, nettype, blockhash): conn = network_conn(nettype) block = get_block(conn, blockhash) if not block: raise ttypes.NotFound() return block
def try_to_place_block(action): global game_board global current_block global current_x_position global current_y_position global current_block_type global current_block_rotation global new_round global game_over temp_block_rotation = current_block_rotation + 1 taken_places_count = 0 #Preparing temporary game board to check is move possible. Forbbiten places marked with 9 temp_game_board = [[0 for x in range(BOARD_Y_SIZE + 2)] for x in range(BOARD_X_SIZE + 4)] for y in range(BOARD_Y_SIZE + 2): for x in range(BOARD_X_SIZE + 4): if x < 2 or x > 11 or y > 21: temp_game_board[x][y] = 9 #Copping actual game board and counting taken places for y in range(BOARD_Y_SIZE): for x in range(BOARD_X_SIZE): temp_game_board[x+2][y] = game_board[x][y] if game_board[x][y] == 8: taken_places_count += 1 #Placing block in place according to event if action == 1: temp_block = block.get_block(current_block_type, current_block_rotation) for y in range(4): for x in range(4): if temp_block[x][y] is not 0: temp_game_board[x + current_x_position + 2][y + current_y_position + 1] = temp_block[x][y] elif action == 2: temp_block = block.get_block(current_block_type, current_block_rotation) for y in range(4): for x in range(4): if temp_block[x][y] is not 0: temp_game_board[x + current_x_position + 3][y + current_y_position] = temp_block[x][y] elif action == 3: temp_block = block.get_block(current_block_type, current_block_rotation) for y in range(4): for x in range(4): if temp_block[x][y] is not 0: temp_game_board[x + current_x_position + 1][y + current_y_position] = temp_block[x][y] elif action == 4: if temp_block_rotation > 3: temp_block_rotation = 0 temp_block = block.get_block(current_block_type, temp_block_rotation) for y in range(4): for x in range(4): if temp_block[x][y] is not 0: temp_game_board[x + current_x_position + 2][y + current_y_position] = temp_block[x][y] #Checking if performed move is correct temp_border_count = 0 temp_taken_places_count = 0 for y in range(BOARD_Y_SIZE + 2): for x in range(BOARD_X_SIZE + 4): if temp_game_board[x][y] == 9: temp_border_count += 1 if temp_game_board[x][y] == 8: temp_taken_places_count += 1 if temp_border_count == 116 and temp_taken_places_count == taken_places_count: #Taking apropiate actions if action == 1: new_round = False current_y_position += 1 elif action == 2: current_x_position += 1 elif action == 3: current_x_position -= 1 elif action == 4: current_block_rotation = temp_block_rotation else: if action == 1: if new_round == True: game_over = True else: start_new_round()
def __make_block(self, pos, c): BLOCKS.add(block.get_block([pos, 0], c))