def main(): # importuje plik i zapisuje w lokalnej dla tego modułu liście albums_data = file_handling.import_data("albums_data.txt") working = True check = True text = "" # loopa zeby menu było wyświetlane non stop, nawet jesli ValueError to znaczy jesli input # nie bedzie int. text jest po to zeby wyswietlac okreslony komunikat w dowolnie wybranym miejscu # w przypadku dobrze wybranej opcji zamieniam text na pusty string zeby komunika nie byl wysiwetlany while working and check: try: display.print_program_menu([ "Show table", "Delete album", "Display oldest album", "Get albums by genre", "What is the oldest album by genre", "For arrow keys navigation" ], text) choice = int(input("What is your choice?:")) if choice == 1: display.print_albums_list(albums_data) display.pause() text = "" elif choice == 2: display.print_albums_list(albums_data) artist = input("What is name of artist you want to delete: ") album_name = input( "What is name of album you want to delete: ") delete_album_by_artist_and_album_name(albums_data, artist, album_name) text = "" elif choice == 3: display.print_command_result( music_reports.get_last_oldest(albums_data)) text = "" elif choice == 4: try: genre = input("What is the genre?: ") display.print_albums_list( music_reports.get_albums_by_genre(albums_data, genre)) display.pause() text = "" except (ValueError, IndexError, TypeError): text = "\033[41;33mNo such genre\33[m" elif choice == 5: try: genre = input("What is the genre?: ") display.print_command_result( music_reports.get_last_oldest_of_genre( albums_data, genre)) text = "" except (ValueError, IndexError, TypeError): text = "\033[41;33mNo such genre\33[m" elif choice == 6: arow_nawigation_menu() elif choice == 0: display.clear() working = False except ValueError: text = "\033[41;33mGive proper number\33[m"
def manage_inputs(events): global player global LOOSE # Keys pressed once for e in events: if e.type == pygame.KEYDOWN and e.key == pygame.K_w: # Auto destruction player.explode() LOOSE = True if e.type == pygame.KEYDOWN and e.key == pygame.K_p: # Pause game pause(window) # Player movement while key down keys = pygame.key.get_pressed() # Checking pressed keys if keys[pygame.K_UP]: player.move("forward") if keys[pygame.K_DOWN]: player.move("backward") if keys[pygame.K_LEFT]: player.move("left") if keys[pygame.K_RIGHT]: player.move("right") if keys[pygame.K_SPACE]: player.shoot()
def main(): display.welcome() #welcome note display.intro() #intro about black jack Black_jack.get_players_number() #input number of palyers players = [] #to store list of players print( '\nAll players should open their wallet accounts in casino to play this game' ) for i in range(Black_jack.n): players.append(Black_jack()) #appending n objects to the players list players[i].status = "PLAY" #assigning status as play print('\nPlayer', i + 1, ':') print('-' * 10) Wallet.open_account(players[i]) #to open account for i in range(Black_jack.n): Wallet.display(players[i]) print('\nPlayers should enter your bet amount before playing:\n') for i in range(Black_jack.n): print('\n', players[i].name, ':') print('-' * 10) players[i].get_bet_amount() #get bet amount for all players Wallet.withdraw(players[i], players[i].bet) #withdraw bet amount print("\nPlayers' Wallet Details:") #print wallet details print('-' * 25, end='') for i in range(Black_jack.n): Wallet.display(players[i]) #first two cards Black_jack.assign_dealer_cards() #assign dealer cards for i in range(Black_jack.n): players[i].cards = list() #creating list for players' cards for j in range(2): players[i].hit() #assign cards for players print('Dealer is distributing the cards.....') display.pause() #pause Black_jack.display_cards(players) for i in range(Black_jack.n): players[i].black_jackpot() #check players who has natural if players[i].status == 'NATURAL': Black_jack.natural_indexes.append( i) #store index of players who has natural #check if insurance is possible(i.e,if there is a possibility for a natural for dealer Black_jack.check_for_insurance() if Black_jack.insure == True: #if dealer has possibility for a natural for i in range(Black_jack.n): if i in Black_jack.natural_indexes: #players with natural print( players[i].name, ',Congrajulations!!!You have a natural.Wait for the dealer to turn up his card' ) players[i].status = 'END' #change status to END else: #players with no natural players[i].ask_for_insurance( ) #ask if players wish to insure themselves if players[i].status == 'INSURE': Black_jack.insure_indexes.append( i) #store index of players who insured #check if dealer has natural Black_jack.dealer_black_jackpot() #dealer with natural if Black_jack.natural == True: #if dealer has natural Black_jack.dealer_cards[1] = Black_jack.card_2 #unhiding the card Black_jack.display_cards( players ) #display cards after unhiding dealer's card cuz game end once dealer has a natural for i in range(Black_jack.n): #players with natural if i in Black_jack.natural_indexes: #players with natural ties with dealer since dealer also has natural print( players[i].name, ',since the dealer too has natural, you ties up with dealer' ) print('Bet amount will be refunded') Wallet.deposit(players[i], players[i].bet) #players without natural else: #players without natural if i in Black_jack.insure_indexes: #non natural players with insurance will get insured bet print( players[i].name, ",since the dealer has natural and you don't, you lost your bet amount" ) print( 'But since you have insured yourself, you won your insured bet.The insured bet amount will be refunded soon!' ) Wallet.deposit(players[i], players[i].bet / 2) else: #non natural players without insurance print( players[i].name, ",since the dealer has natural and you don't, you lost your bet amount" ) print('You should have insured yourself!!!') display.pause() return None #game ends #dealer without natural but insure possible elif Black_jack.insure == True and Black_jack.natural == False: #if dealer has no natural for i in range(Black_jack.n): if i in Black_jack.natural_indexes: #natural players win 1.5 of the bet and ends the game print(players[i].name, ",since the dealer don't have natural,you win the bet!") print( 'One and a half of your bet amount will be credited to your wallet account now' ) Wallet.deposit(players[i], players[i].bet * 1.5) else: #non natural players if i in Black_jack.insure_indexes: #non natural insured players lose their insured bet print( players[i].name, ",since the dealer don't have natural,you can continue your game" ) print( "Also since you have insured,you lose your insured bet" ) else: #non natural non insured players continue their game print( players[i].name, ",since the dealer don't have natural,you can continue your game" ) display.pause() if Black_jack.natural == False: #if dealer has no insurance(no natural obviously) for i in range(Black_jack.n): if players[ i].status != 'END' and i in Black_jack.natural_indexes: #natural players win naturally print(players[i].name, ",since the dealer don't have natural,you win the bet!") print( 'One and a half of your bet amount will be credited to your wallet account now' ) Wallet.deposit(players[i], players[i].bet * 1.5) else: #non natural players should choose to double down or split or hit if players[i].check_double_down() == True: players[i].ask_double_down( ) #ask players who satisfy doubling conditions if players[i].status == 'DD': Black_jack.double_indexes.append( i ) #store index in a list of players who doubles their bet players[i].double_down( ) #process to do for double down Black_jack.display_cards(players) elif players[i].check_split() == True: players[i].ask_split( ) #ask players who satisfy splitting conditions if players[i].status == 'SPLIT': Black_jack.split_indexes.append( i) #store index in a list of players who splits players[i].split(players) #process to do for split #rest of the players(non splitted and non doubled players (satisfy condition but chose not to split or double), and regular players) if players[i].status != 'END' and players[i].status != 'STAY': Black_jack.display_cards(players) players[i].hit_till_stay(players) else: continue display.pause() #all players' turns ends #now dealer's turn Black_jack.dealer_cards[1] = Black_jack.card_2 #unhiding print('Dealer Turns up his face-down card') display.pause() Black_jack.dealer_cards[1] = Black_jack.card_2 Black_jack.display_cards(players) #displays cards Black_jack.dealer_sum() #to calc dealer's total while Black_jack.add < 17: #dealer should hit until his total is atleast 17 print("Dealer's total is less than 17...,") input('So now the dealer is forced to Hit,Press Enter to continue\n') Black_jack.dealer_cards.append(Deck.draw_card_random()) #dealer hits Black_jack.dealer_sum() Black_jack.display_cards(players) if Black_jack.add > 21: print('Dealer is busted') for i in range(Black_jack.n): if i in Black_jack.double_indexes and players[i].status == 'STAY': print(players[i].name, 'since you doubled your bet,you win twice of your bet!') print( 'Amount you won and your bet amounts will be credited to your wallet' ) Wallet.deposit(players[i], 4 * players[i].bet) elif i in Black_jack.split_indexes: flag = 0 if players[i].status == 'STAY': flag += 1 if players[i].status_split == 'STAY': flag += 1 if flag != 0: print(players[i].name, ", you won", flag, 'hand(s)') print('Amount you won will be credited to your wallet') Wallet.deposit(players[i], 2 * flag * players[i].bet) elif players[i].status == 'STAY': print(players[i].name, ", you win") print( 'Your bet amounts and the amount you won will be credited to your wallet' ) Wallet.deposit(players[i], players[i].bet * 2) display.pause() return None #now check with dealer Black_jack.dealer_sum() #calc total of dealer Black_jack.check_with_dealer(players)
def main(): display.welcome() #welcome note display.intro() #intro about black jack Black_jack.get_players_number() #input number of palyers players=[] #to store list of players print('\nAll players should open their wallet accounts in casino to play this game') for i in range(Black_jack.n): players.append(Black_jack()) #appending n objects to the players list players[i].status="PLAY" #assigning status as play print('\nPlayer',i+1,':') print('-'*10) Wallet.open_account(players[i]) #to open account print('\nPlayers should enter your bet amount before playing:\n') for i in range(Black_jack.n): print('\nPlayer',i+1,':') print('-'*10) players[i].get_bet_amount() #get bet amount for all players Wallet.withdraw(players[i],players[i].bet) #withdraw bet amount print("\nPlayers' Wallet Details:") #print wallet details print('-'*25,end='') for i in range(Black_jack.n): Wallet.display(players[i]) #first two cards Black_jack.assign_dealer_cards() #assign dealer cards for i in range(Black_jack.n): players[i].cards=list() #creating list for players' cards for j in range(2): players[i].hit() #assign cards for players print('Dealer is distributing the cards.....') Black_jack.display_cards(players) #display cards for players and dealers for i in range(Black_jack.n): players[i].black_jackpot() #assign natural attribute of players as True or False #INSURE AND NATURAL Black_jack.check_for_insurance() #checking if insurance is possible for players if Black_jack.insure=='CAN': #if insure is possible for i in range(Black_jack.n): if players[i].status!='NATURAL': #and if player doesn't have natural players[i].ask_for_insurance() #ask player for insurance(who doesn't have blackjack) Black_jack.dealer_black_jackpot() #assign if natural is present for dealer if Black_jack.natural==True: #if dealer has natural for i in range(Black_jack.n): if players[i].status=='NATURAL': #players having natural print('Conrajulations!!! You have a Natural!!!') print("Now the dealer will check his card.You will win if he doesn't have a natural.If he has a natural,the match is Draw!") display.pause() print('Dealer too has Natural!!!') print('Match is a natural Tie for you') players[i].change_status('END') #change player status to 'END' Wallet.deposit(players[i],players[i].bet) #refund bet amount Wallet.display(players[i]) #print wallet details else: #players who doesn't have natural print('Dealer has a natural but you do not have a natural') print('You lose your bet naturally') for i in range(Black_jack.n): players[i].change_status('END') #change players' status to "END" if players[i].status=='INSURE': #if the players is insured or not print('Since you have insured yourself...you have won the insured bet.') Wallet.deposit(players[i],players[i].bet) #depositing insured bet amount Wallet.display(players[i]) #print wallet details of the players else: #if dealer has no natural for i in range(Black_jack.n): if players[i].status=='NATURAL': #if players have natural print('Conrajulations!!! You have a Natural!!!') print("Now the dealer will check his card.You will win if he doesn't have a natural.If he has a natural,the match is Draw!") display.pause() print('Dealer does not have Natural.So you WIN naturally!!!') players[i].change_status('END') #changing players' status to end Wallet.deposit(players[i],1.5*players[i].bet) #depositing natural bet else: #players don't have natural print('Dealer does not have Natural') if players[i].status=='INSURE': #insured players print('So,you lost your insured bet.But...') print('You can continue your game') #blackjack and insurance over #control flows here only # 1)when insurance is possible but dealer has no natural and player has no natural(may or maynot insured) # 2)when insurance is not possible,players has no natural #SPLIT AND DOUBLE DOWN AND REGULAR PLAY #from now on only players whose status is not 'END' will be playing #split and doube down is similar to playing in regular way except bet amount differs and hiiting frequency alters for i in range(Black_jack.n): if players[i].status=='PLAY': #players who did not end their game players[i].check_double_down() #check double down is possible and get player's wish players[i].check_split() #check if split is possible and get players' wish #condition for split and double down doesn't coincide so calling check_split and check_double_down doesn't cause problem #DOUBLE DOWN if players[i].status=='DD': #players who chosen to double down print('Since you have choosen to Double Down...you can draw only one card') players[i].hit() #player drawing one card Black_jack.display_cards(players) #to display cards players[i].bust() #to check if player is busted if players[i].status=='BUST': #if player is busted display.bust_player() players[i].change_status('END') #change status to "END" print('You lose your Doubled Bet') #SPLIT elif players[i].status=='SPLIT': #players who chosen to split Black_jack.split_indexes.append(i) #storing players' indexes who wishes to split for _ in range(2): #two loops for two hands if 'A' in players[i].cards[0]: #if the two cards are Aces player gets only one card for each players[i].hit() #one hit Black_jack.display_cards(players) #to display cards players[i].black_jackpot() if players[i].status=='NATURAL': #to check if the player has a natural after splitting Wallet.deposit(players[i],players[i].bet*2) #only bet amount players[i].change_status('END') #change status to "END" #condition for bust and natural doesn't coincide so calling both function next to other doesn't cause problem players[i].bust() if players[i].status=='BUST': #to check if th player is busted display.bust_player() players[i].change_status('END') #change status to "END" print('You lost this hand.') else: #if no Ace,hit until stay while players[i].status!='STAY': #if no natural,no bust,ask until stay players[i].hit() Black_jack.display_cards(players) #to display cards if players[i].stop_21()==True: #if tot=21 break #no more hits(and player can't be busted since tot is only 21(not exeeds 21)) players[i].bust() if players[i].status=='BUST': #if player is bust display.bust_player() print('You Lost this hand.') players[i].change_status('END') #change status to "END" self.swap_split() #swap both hands' details(status,card,add) #REGULAR PLAY else: #NDD NOSPLIT players(means REGULAR PLAY) while players[i].status!='STAY': #hit until stay players[i].hit() Black_jack.diplay_cards(players) #to display cards if players[i].stop_21()==True: #if tot=21 break #no more hits players[i].bust() if players[i].status=='BUST': #if player is bust display.bust_player() players[i].change_status('END') #change status to "END" #All players' turns ends #now it is Dealer's turn Black_jack.dealer_cards[1]=Black_jack.card_2 #dealer now turns up his hidden card print('Dealer Turns up his face-down card') Black_jack.display_cards(players) #displays cards if Black_jack.check_status(players)==True: #if game did not end while Black_jack.add<17: #dealer should hit until his total is atleast 17 print("Dealer's total is less than 17...So,") input('now the dealer is forced to Hit,Press Enter to continue\n') Black_jack.dealer_cards.append(Deck.draw_card_random()) #dealer hits Black_jack.dealer_sum() #to calc total of dealer Black_jack.display_cards(players) #to display cards else: #game ends print('\n \t\t\t\t\t\t\t\t\t\tGame Over\n') #control flows here only if game did not end #to check stayed players and splitted players(other hand also) and double downed players Black_jack.dealer_sum() #calc total of dealer for i in range(Black_jack.n): if players[i].status in ['DD','STAY']: #out of DD STAY SPLIT players considering DD and STAY now players[i].calc_sum() #to calc total of player players[i].check_with_dealer() #check player total with dealer elif players[i].status=='SPLIT': #splitted players print('Since you have splitted,You first play the hand to your left') for i in range(2): #two loops for two hands players[i].calc_sum() players[i].check_with_dealer() #check player's total with dealer's players[i].swap_split() #swap splitted hands
def split(self,players): Black_jack.display_cards(players) #to display cards for k in range(2): #two loops for two hands hand=['Left','Right'] #just to display print(self.name,',you are now playing your',hand[k],'hand') if 'A' in self.cards[0]: #if the two cards are Aces player gets only one card for each print('Since you got an ACE ,you can hit only once') display.pause() #pause self.hit() #one hit self.calc_sum() if k==1: self.swap_split() Black_jack.display_cards(players) self.swap_split() else: Black_jack.display_cards(players) self.black_jackpot() if self.status=='NATURAL': #to check if the player has a natural after splitting print('Congrajulations!!!This hand has a natural.') Wallet.deposit(self,self.bet*2) #only bet amount Wallet.display(self) #display wallet details self.change_status('END') #change status to "END" else: self.change_status('STAY') #Note:Player who splitted(A-A) bet can't get busted(check the maximum total he can get(only 21 is possible) else: #if no Ace,hit until stay while True: self.hit_or_stay() if self.status=='STAY': self.change_status('STAY') break self.hit() if k==1: self.swap_split() Black_jack.display_cards(players) self.swap_split() else: Black_jack.display_cards(players) if self.stop_21()==True: input('Press Enter to continue\n') self.change_status('STAY') break self.bust() if self.status=='BUST': print('You are busted') input('Press Enter to continue\n') self.change_status('END') break #to prevent displaying cards -collapsing hand error-logically correcting if k==1: self.swap_split() Black_jack.display_cards(players) self.swap_split() if self.stop_21()==True: #if tot=21 self.change_status('STAY') self.bust() if self.status=='BUST': #if player is bust print('You are busted so you Lost this hand.') self.change_status('END') #change status to "END" self.swap_split() #swap both hands' details(status,card,add)
# define a color for start and stop vertex attr["vertex_color"][start]="green" attr["vertex_color"][stop]="red" print("Starting at {}, ending at {}".format(start, stop)) if len(graph.neighbours_of(G, start)) == 0: raise Exception("Bad luck, {} has no neighbours".format(start)) num_steps = 0 display.write_dot_desc(G, dot_file_name, attr) cur = start while cur != stop and num_steps < max_num_steps: display.pause(0) num_steps += 1 print("Step {} at {}".format(num_steps, cur)) # find a random neighbour of cur prev = cur neighbours = graph.neighbours_of(G, cur) cur = random.choice(list(neighbours)) # do some coloring before next graph render attr["vertex_color"][prev]="white" attr["vertex_color"][start]="green" attr["vertex_color"][cur]="orange" attr["vertex_color"][stop]="red" attr["edge_color"][graph.mk_edge(prev, cur)]="orange" display.write_dot_desc(G, dot_file_name, attr)
def arow_nawigation_menu(): albums_data = file_handling.import_data("albums_data.txt") working = True check = False text = "" menu_index = 0 menu_lenght = 7 # while not check and working:"\33[46;37m","\33[m" while working and not check: arrow_choice = [] menu_index = ((7000 - len(arrow_up) + len(arrow_down)) % menu_lenght ) #7k gdyby ktos chcial naciska up arrow printing_addons = [ ["", ""], ["", ""], ["", ""], ["", ""], ["", ""], ["", ""] ] #lista z brakujacym elementem ktora bedzie dodrukowywana do menu printing_addons.insert( menu_index, ["==>>", "<<=="] ) # brakujacy element o konkretnym indeksie ktory bedzie zmieniał kolor czcionki display.print_program_menu_arrow_nawigation([ " Show table ", " Delete album ", " Display oldest album ", " Get albums by genre ", " What is the oldest album by genre ", " For number keys navigation ", " Exit " ], text, menu_index, printing_addons) arrow_sensing(arrow_choice) if menu_index == 0 and len(arrow_choice) > 0: display.print_albums_list(albums_data) display.pause() text = "" elif menu_index == 1 and len(arrow_choice) > 0: display.print_albums_list(albums_data) artist = input("What is name of artist you want to delete: ") album_name = input("What is name of album you want to delete: ") delete_album_by_artist_and_album_name(albums_data, artist, album_name) text = "" elif menu_index == 2 and len(arrow_choice) > 0: display.print_command_result( music_reports.get_last_oldest(albums_data)) text = "" elif menu_index == 3 and len(arrow_choice) > 0: try: genre = input("What is the genre?: ") display.print_albums_list( music_reports.get_albums_by_genre(albums_data, genre)) display.pause() text = "" except (ValueError, IndexError, TypeError): text = "\033[41;33mNo such genre\33[m" elif menu_index == 4 and len(arrow_choice) > 0: try: genre = input("What is the genre?: ") display.print_command_result( music_reports.get_last_oldest_of_genre(albums_data, genre)) text = "" except (ValueError, IndexError, TypeError): text = "\033[41;33mNo such genre\33[m" elif menu_index == 5 and len(arrow_choice) > 0: check = True elif menu_index == 6 and len(arrow_choice) > 0: display.clear() exit()