def enter_Name(): global name global user_points offline_update(name) name = "" enter_name = True name_entered = False name = "" login_image = pygame.image.load("images/login.jpg").convert() while enter_name: for event in pygame.event.get(): if event.type == pygame.QUIT: offline_update(name) pygame.quit() if name != "": name_entered = True gameDisplay.fill(white) gameDisplay.blit(login_image, (0, 0)) #message_to_screen("Waiting For Username", red, [200, 100], 35) #message_to_screen("Enter The Username You Previously Used", black, [120, 200], 30) #message_to_screen("OR", black, [380, 250], 35) #message_to_screen("Choose any username to create a new account", black, [90, 300], 30) pygame.display.update() clock.tick(10) if name_entered: name = name.lower() name = name.replace(' ', '') if name == "global" or name == "blank": name_entered = False name = "" try: user_details = User.Get_Details(name) user_ex = user_details.get_points() if user_ex == "false": user_details.register_user() print( "Account Created! Always use this name to access your score" ) user_points = user_details.get_points() except: user_points = "Can't Connect To Server" print(user_points) print("Continue to game...") if name_entered: enter_name = False game_Menu() box = DialogBox() box.box()
def enter_Name(): global name global user_points offline_update(name) name = "" enter_name = True name_entered = False name = "" login_image = pygame.image.load("images/login.jpg").convert() while enter_name: for event in pygame.event.get(): if event.type == pygame.QUIT: offline_update(name) pygame.quit() if name != "": name_entered = True gameDisplay.fill(white) gameDisplay.blit(login_image, (0, 0)) pygame.display.update() clock.tick(10) if name_entered: name = name.lower() name = name.replace(' ', '') if name == "global" or name == "blank": name_entered = False name = "" try: user_details = User.Get_Details(name) user_ex = user_details.get_points() if user_ex == "false": user_details.register_user() print( "Account Created! Always use this name to access your score" ) user_points = user_details.get_points() except: user_points = "Can't Connect To Server" print(user_points) print("Continue to game...") if name_entered: enter_name = False game_Menu() box = DialogBox() box.box()
def Game_Over(): gameover = True global points global user_points global name gameover_image = pygame.image.load("images/gameover.jpg").convert() points_display = 0 try: user_update = User.Get_Details(name) user_points = user_update.get_points() user_update.upload_score(points) coins = get_coin_value(name) coins = int(coins) coin_new = points * 5 coin_n = coin_new + coins update_coins(name, coin_n) if int(user_points) < points: user_update.update_score(points) user_high_score = user_update.get_points() except: global_high_score = "Can't Connect To Internet" user_high_score = "Can't Connect To Server" try: global_high_score = int(server.get_num_score()) server.run(points) except: print("cannot connect") while gameover == True: mouse_pos = pygame.mouse.get_pos() if mouse_pos[0] >= 175 and mouse_pos[0] < 550 and mouse_pos[ 1] >= 275 and mouse_pos[1] < 345: mouse_click = pygame.mouse.get_pressed() if mouse_click[0] == 1: gameLoop() if mouse_pos[0] >= 175 and mouse_pos[0] < 550 and mouse_pos[ 1] >= 360 and mouse_pos[1] < 427: mouse_click = pygame.mouse.get_pressed() if mouse_click[0] == 1: gameover = False game_Menu() if mouse_pos[0] >= 175 and mouse_pos[0] < 550 and mouse_pos[ 1] >= 445 and mouse_pos[1] < 510: mouse_click = pygame.mouse.get_pressed() if mouse_click[0] == 1: offline_update(name) quit() if points_display < points: points_display += 1 gameDisplay.fill(white) gameDisplay.blit(gameover_image, (0, 0)) #message_to_screen("GAME OVER!", red, [195, 180], 60) message_to_screen(str(points_display), white, [440, 31], 60) message_to_screen(str(user_high_score), white, [370, 566], 30) #message_to_screen("Press R to play again", black, [200, 290], 25) #message_to_screen("Press M for main menu", black, [200, 320], 25) #message_to_screen("Press Q to Quit", black, [200, 350], 25) try: if server.compare_scores(int(global_high_score), points): #message_to_screen(str(global_high_score), light_blue, [235, 170], 30) print("Not Connected") if not server.compare_scores(int(global_high_score), points): #message_to_screen("Global High Score: " + str(global_high_score), red, [200, 240], 20) message_to_screen(str(global_high_score), light_blue, [555, 200], 30) except: message_to_screen("Can't Connect To Server", red, [200, 240], 20) pygame.display.update() pygame.mouse.set_cursor(*pygame.cursors.arrow) clock.tick(10) for event in pygame.event.get(): if event.type == pygame.QUIT: offline_update(name) pygame.quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: quit() if event.key == pygame.K_r: gameLoop() if event.key == pygame.K_m: gameover = False game_Menu()
def game_Menu(): global name global user_points online_update(name) menu_image = "images/menu.jpg" image_menu = pygame.image.load(menu_image).convert() try: global_high_score = server.get_num_score() if global_high_score == "": global_high_score = "Scores Not Found" except: print("cannot connect") global_high_score = "Cannot Connect" try: user_update = User.Get_Details(name) user_points = user_update.get_points() except: user_points = "Can't Connect To Server" game_menu = True while game_menu == True: for event in pygame.event.get(): if event.type == pygame.QUIT: offline_update(name) pygame.quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_c: game_menu = False gameLoop() if event.key == pygame.K_q: offline_update(name) quit() if event.key == pygame.K_l: name = "" game_menu = False enter_Name() if event.key == pygame.K_o: game_menu = False leader_board() mouse_pos = pygame.mouse.get_pos() if mouse_pos[0] >= 185 and mouse_pos[0] < 585 and mouse_pos[ 1] >= 240 and mouse_pos[1] < 302: mouse_click = pygame.mouse.get_pressed() if mouse_click[0] == 1: game_menu = False gameLoop() if mouse_pos[0] >= 185 and mouse_pos[0] < 585 and mouse_pos[ 1] >= 316 and mouse_pos[1] < 375: mouse_click = pygame.mouse.get_pressed() if mouse_click[0] == 1: game_menu = False leader_board() if mouse_pos[0] >= 185 and mouse_pos[0] < 585 and mouse_pos[ 1] >= 400 and mouse_pos[1] < 458: mouse_click = pygame.mouse.get_pressed() if mouse_click[0] == 1: game_menu = False enter_Name() if mouse_pos[0] >= 185 and mouse_pos[0] < 585 and mouse_pos[ 1] >= 486 and mouse_pos[1] < 545: mouse_click = pygame.mouse.get_pressed() if mouse_click[0] == 1: offline_update(name) quit() coins = get_coin_value(name) gameDisplay.fill(white) gameDisplay.blit(image_menu, (0, 0)) message_to_screen(str(global_high_score), white, [520, 170], 27) message_to_screen(str(name), white, [150, 12], 27) message_to_screen(str(user_points), white, [725, 15], 25) pygame.mouse.set_cursor(*pygame.cursors.arrow) pygame.display.update() clock.tick(1000)