def main(): # Initialise colorama init() # Show title screen title() # Main game loop while True: # Check if the player's health is below zero and end the game if player["health"] <= 0: nice_print("You have died! Game over!", Fore.RED) quit() # Check if the player has met the victory condition and end the game if item_fire in player["inventory"]: nice_print_line("Your fire now burns brightly on the top of the cliffs") nice_print_line("Any passing planes or ships are sure to see you on the island") nice_print_line("But will anyone arrive in time, or is it already too late for you?") nice_print_line("Only time will decide") credits(1) quit() # Display game status (location description, inventory etc.) print_location(player["current_location"]) if player["current_location"]["enemy"]: combat(player["current_location"]["enemy"]) print_location(player["current_location"]) print_player(player) print_inventory_items(player["inventory"]) # Show the menu with possible actions and ask the player command = menu(player["current_location"]["exits"], player["current_location"]["items"], player["inventory"]) # Execute the player's command - repeat the options if the command cannot be performed while not execute_command(command): command = menu(player["current_location"]["exits"], player["current_location"]["items"], player["inventory"])
def main(): global energy gameStart = getCurrentTime() #time the game started energyLossTime = getCurrentTime() #time since energy was last lost initiateRooms() #Allocate items to containers in the objectAllocation.py file schedule = sched.scheduler(time.time, time.sleep) #A scheduler to set up timed events xrayCount = 0 #The amount of turns spent in the xray room command = [""] #Set command to a blank list so that NoneType errors don't occur difficulty = player.difficulty #Get the difficulty from the player.py if difficulty == "easy": #Set energy loss time depending on difficulty energyLoss = 200 elif difficulty == "normal": energyLoss = 150 else: energyLoss = 100 # Main game loop while True: play_music() # Display game status (room description, inventory etc.) if checkEndings(current_room, command): #Check if any end conditions have been met break print_room(current_room) print_inventory_items(inventory) if current_room["name"] == "Xray Room": #Check if in the xray room since the xray room is dangerous if xrayCount >= 5: #If more than 5 turns in the xray room type_print("You have died") type_print(""" Your skin starts to ripple with waves of pain, you fall to the floor with a overwhelming sense of nausea. The pain overtakes and your eyes slowly start to close to the sickening sound of the broken X-Ray machines. Your eyes never open again...""") print_game_over() #Kill the player break else: xrayCount += 1 #Another turn spend in the xray room schedule.enter(randint(5, 15), 1, type_print(xrayRoomMessage())) #Display a message in 5-15 seconds # Show the menu with possible actions and ask the player command = menu(current_room["exits"], current_room["items"], inventory) # Execute the player's command execute_command(command) if(player.morgue_open == True): #Check if the morgue has been opened, if so randomly spawn zombies in rooms if(command[0] == "go"): if(random.randint(1, 10) > 4): combat(difficulty, random.randint(2, 10)) if checkEndings(current_room, command): #Once again check if any win (or loss) conditions have been met break if timeSince(energyLossTime, getCurrentTime()) > energyLoss: #Check if it has been long enough to deduct energy energy -= 1
def interaction(self): if abs(self.target.rect.centerx - self.rect.centerx) < 100 and abs( self.target.rect.centery - self.rect.centery) < 100: self.draw_text(self.text, FONT, 10, WHITE, self.rect.centerx + self.camera.x, self.rect.y + self.camera.y, align="s") # Limite le son a 1 par pnj while (self.count <= 1): self.count += 1 if self.sex == 0: pygame.mixer.Sound(EFFECTS_SOUNDS['voicef']).play() if self.sex == 1: pygame.mixer.Sound(EFFECTS_SOUNDS['voicem']).play() # Interaction if abs(self.target.rect.centerx - self.rect.centerx) < 60 and abs( self.target.rect.centery - self.rect.centery) < 60: # If Win dialogue keystate = pygame.key.get_pressed() if keystate[INTERACT]: J1 = Joueur() J1.classe = 'humain' J1.nom = "Viktor" J2 = IA() i = randint(1, 3) print(i) if i == 1: J2.nom = 'Bron' J2.sprite = ennemi1 elif i == 2: J2.nom = "Oleg" J2.sprite = ennemi2 else: J2.nom = "Judy" J2.sprite = ennemi3 redraw(J1, J2, 1) combat(J1, J2) #If Win self.kill()
def make_batch_matrix(self, batch_list, name=None, matrix=None): if name and matrix is None: try: self.batch_dict[name] = combat(self.norm_dict[name], batch=list(batch_list)) except KeyError: try: self.norm_counts_matrix(name=name) self.batch_matrix = combat(self.norm_matrix, batch=list(batch_list)) except KeyError as e: raise KeyError( 'need a norm_matrix before it can be batch' + 'corrected, also couldnt create norm matrix' ).with_traceback(e.__traceback__) else: corrected_matrix = combat(matrix, batch=list(batch_list)) return corrected_matrix
def wrapper(n): ship1Won = 0 t1 = time() for i in range(n): ship1, ship2 = mafonction() if combat(ship1, ship2) == 'Ship 1 won': ship1Won += 1 t2 = time() print('Ship 1 won '+str(ship1Won)+' times on '+str(n)) print('Round time : '+str((t2-t1)/n)+' seconds per fight')
def combatAtLocation(tkRoot, friendlyShips, enemyShips): print("combatAtLocationMenu") combatResult = None if (friendlyShips and enemyShips): combatResult = combat(tkRoot, friendlyShips, enemyShips) if (combatResult is not None): print(combatResult.combatOrders) tkRoot.battleOrders.update(combatResult.combatOrders)
def correct_combat(df, embeds_cols, verbose=False): if verbose: print('Do COMBAT') # Expression exp = df[embeds_cols].T # Covariants mod = patsy.dmatrix("~ compound + compound_uM", df, return_type="dataframe") ebat = combat(exp, df['plate'], mod, "compound_uM") df.loc[:, embeds_cols] = ebat.T return df
def ap_combat(df_rna, meta): """ ... """ dat, pheno, _, _ = py_df_to_R_df(data=df_rna, meta=meta, filename=None, to_save=False, to_scale=False, var_thres=None) # dat.columns.name = None # pheno.index.name = pheno.columns.name # pheno.columns.name = None mod = patsy.dmatrix("~1", data=pheno, return_type="dataframe") ebat = combat( data=dat, batch=pheno['source'], # pheno['batch'] model=mod) df_rna_be = R_df_to_py_df(ebat) return df_rna_be
def combat_norm(rna, meta, sample_col_name: str, batch_col_name: str): """ This function is adjusted to accept a python dataframe (rna) and transpose it before applying the combat algorithm. Args: sample_col_name: column name that contains the rna samples batch_col_name: column name that contains the batch values """ rna_fea, pheno, _, _ = py_df_to_R_df(data=rna, meta=meta, sample_col_name=sample_col_name) # dat.columns.name = None # pheno.index.name = pheno.columns.name # pheno.columns.name = None mod = patsy.dmatrix("~1", data=pheno, return_type="dataframe") ebat = combat( data=rna_fea, batch=pheno[batch_col_name], # pheno['batch'] model=mod) df_rna_be = R_df_to_py_df(ebat, sample_col_name=sample_col_name) return df_rna_be
enemy2 = Goblin() enemy2.locx, enemy2.locy = enemy2loc enemy2.rect = pygame.Rect(enemy2.locx, enemy2.locy, 60, 96) enemy3 = Goblin() enemy3.locx, enemy3.locy = enemy3loc enemy3.rect = pygame.Rect(enemy3.locx, enemy3.locy, 60, 96) characters = [player, char1, char2, enemy1, enemy2, enemy3] #list of all the characters active in the game win.loadimages(characters) #preload all of the images needed for characters running = 1 while running == 1: #game loop start for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: for m in characters: if m.rect.collidepoint(pygame.mouse.get_pos()): for u in characters: u.selected = False #unselect all other characters m.selected = True #select the mob so the stat block is updated with their information if event.type == pygame.KEYDOWN: key = pygame.key.get_pressed() if key[pygame.K_c]: combat(characters, win) elif key[pygame.K_q]: running = 0 if event.type == pygame.QUIT: running = 0 else: pygame.event.clear() win.refresh(characters) pygame.quit() #game loop is over, close the window
running=False if event.type == pygame.MOUSEBUTTONDOWN: if (event.button == 1 and a_block.get_ammo() > 0): missiles.add(Missile("images/missile_2.png",a_block.rect.center,(event.pos[0],event.pos[1]),window,walls,monster_group,number_of_particles,my_particles,a_block.get_spldmg(),a_block.get_pie()) ) a_block.increment_ammo(-1) if event.button == 3: for monster in monster_group: if monster.rect.collidepoint(mousepos) and monster.get_shield() > 0 and a_block.get_powercharge() > 0: monster.increment_shield(-1) a_block.increment_powercharge(-1) key = pygame.key.get_pressed() for monster in monster_group: monster.ai(monster,a_block,walls,walk_counter,walk_counter_max,monster_group,collidables) text2 = basicfont.render(monster.hptext, True, (255, 0, 0)) window.blit(text2,(monster.rect.center[0]-10,monster.rect.center[1]-30)) combat(a_block,monster_group,player_group,my_particles,combat_counter) s.fill((0,0,0)) mask.fill((0,0,0)) s.blit(window,(200-offset[0]/2,200-offset[1]/2)) # dia 2 gia na min kanei scroll oso grigora oso kounieme.(dinei mia aisthish xorou anti apla na kouniete to map oso kouniete o pexths me apotelesma na fenete statheros o pexths) if walk_counter_player == walk_counter_max_player-1: handle_event(event,key,a_block,block_group,player_group,walls,animation_counter,animation_interval,camera,monster_group,items_group,collidables,s,window) clock.tick(fps) floor_group.draw(window) items_group.draw(window) block_group.draw(window) player_group.draw(window) monster_group.draw(window) missiles.draw(window) particle_life+=1 animation_counter+=1 walk_counter += 1
newweapon = sword_short() #create a short sword and equip it player.equip_weapon(newweapon) char1 = dummy() char1.name = "Character one"; char1.team = 1 char2 = dummy() #^ players group members char2.name = "Character two"; char2.team = 1 enemy1 = dummy() enemy1.team = 2 enemy2 = dummy() enemy2.name = "Goblin"; enemy2.team = 2 enemy3 = dummy() #enemy mobs enemy3.name = "Goblin"; enemy3.team = 2 while True: print "1: start combat. l: level up. anything else: quit" event = raw_input("select an option:") if event == "1": combat(player,char1,char2,enemy1,enemy2,enemy3) elif event == "l": player.on_levelup() print "Health:"+str(player.health)+" Stamina:"+str(player.stamina) print "attack:"+str(player.attack)+" defense:"+str(player.defense) print "accuracy:"+str(player.accuracy)+" evasion:"+str(player.evasion) else: break
def oneFightProcess(i, ship1, ship2): s = randrange(999999999) seed(s) c = combat(ship1, ship2) # print('Fight #'+str(i)+'\nSeed #'+str(s)) return c
enemy2.locx, enemy2.locy = enemy2loc enemy2.rect = pygame.Rect(enemy2.locx, enemy2.locy, 60, 96) enemy3 = Goblin() enemy3.locx, enemy3.locy = enemy3loc enemy3.rect = pygame.Rect(enemy3.locx, enemy3.locy, 60, 96) characters = [player, char1, char2, enemy1, enemy2, enemy3] #list of all the characters active in the game win.loadimages(characters) #preload all of the images needed for characters running = 1 while running == 1: #game loop start for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: for m in characters: if m.rect.collidepoint(pygame.mouse.get_pos()): for u in characters: u.selected = False #unselect all other characters m.selected = True #select the mob so the stat block is updated with their information if event.type == pygame.KEYDOWN: key = pygame.key.get_pressed() if key[pygame.K_c]: combat(characters, win) elif key[pygame.K_q]: running = 0 if event.type == pygame.QUIT: running = 0 else: pygame.event.clear() win.refresh(characters) pygame.quit() #game loop is over, close the window
break else: print("Đánh lại đê!") while True: print("Bạn sẽ:\n" "1. Bỏ chạy\n" "2. Đứng yên chờ đợi\n" "3. Lao về phía con sói") choice = input(">>>") if choice == "1": print("Bạn định bỏ chạy nhưng cánh cửa đóng lại") elif choice == "2": print("Bạn và sói gườm gườm nhìn nhau, không bên nào động thủ\n" "Bạn và sói cứ nhìn nhau như vậy tầm 10 phút, sói do bỏ đói " "lâu ngày không chịu được đã lao vào tấn công bạn") break elif choice == "3": break else: print("Đánh lại đê!") print("----------") for k, v in player.items(): print(k, v) print("----------") print("Đấu với") print("----------") for k, v in wolf.items(): print(k, v) print("----------") combat(player, wolf)