[PyGame] How to select only one image from three? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: [PyGame] How to select only one image from three? (/thread-23273.html) |
How to select only one image from three? - maks_mkv - Dec-19-2019 Hi all. I write a game. In game used three image. How to select only one image from three? import pygame, sys import os, random os.chdir('C:\\Users\\maksim\\Desktop\\GAME_PY\\') pygame.init() BLACK = (0, 0, 0) size = [800, 800] screen = pygame.display.set_mode(size) pygame.display.set_caption("Камень, ножницы, бумага") screen.fill([255, 255, 255]) paper = pygame.image.load('paper.png') rock = pygame.image.load('rock.png') scissors = pygame.image.load('scissors.png') paper_select = pygame.image.load('paper_select.png') rock_select = pygame.image.load('rock_select.png') scissors_select = pygame.image.load('scissors_select.png') pc = pygame.image.load('pc.png') scale_paper = pygame.transform.scale(paper,(181,175)) scale_rock = pygame.transform.scale(rock,(181,175)) scale_scissors = pygame.transform.scale(scissors,(181,175)) scale_paper_select = pygame.transform.scale(paper_select,(181,175)) scale_rock_select = pygame.transform.scale(rock_select,(181,175)) scale_scissors_select = pygame.transform.scale(scissors_select,(181,175)) scale_pc = pygame.transform.scale(pc,(181,175)) screen.blit(scale_paper, [550,100]) screen.blit(scale_rock, [550,300]) screen.blit(scale_scissors, [550,500]) screen.blit(scale_pc, [100,300]) rect1 = pygame.Rect(550, 100, 178, 173) rect2 = pygame.Rect(550, 300, 178, 173) rect3 = pygame.Rect(550, 500, 178, 173) pygame.draw.line(screen, BLACK, [400,0],[400,800], 5) pygame.display.flip() # pygame.draw.rect(screen, (211,211,211), (550, 100, 178, 173)) # pygame.draw.rect(screen, (211,211,211), (550, 300, 178, 173)) # pygame.draw.rect(screen, (211,211,211), (550, 500, 178, 173)) pc_choice=random.randint(1,3) pygame.time.wait(500) if pc_choice == 1: gg = "Rock" screen.blit(scale_rock, [100,300]) pygame.display.flip() elif pc_choice == 2: gg = "Scissors" screen.blit(scale_scissors, [100,300]) pygame.display.flip() else: gg = "Paper" pc_choice == 3 screen.blit(scale_paper, [100,300]) pygame.display.flip() human_choice = 10 running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN and human_choice != 0: #print(pygame.mouse.get_pos()) if rect1.collidepoint(event.pos): human_choice = 1 screen.blit(scale_paper_select, [550,100]) #pygame.display.flip() print("Ваш выбор - бумага") if rect2.collidepoint(event.pos): human_choice = 2 screen.blit(scale_rock_select, [550,300]) #pygame.display.flip() print("Ваш выбор - камень") if rect3.collidepoint(event.pos): human_choice = 3 screen.blit(scale_scissors_select, [550,500]) # pygame.display.flip() print("Ваш выбор - ножницы") pygame.display.flip() if human_choice == 1: print("Ваш выбор - бумага") if pc_choice == 1: print("Вы выйграли") elif pc_choice == 2: print("Компьютер выйграл") else: pc_choice == 3 print("Ничья") if human_choice == 2: print("Ваш выбор - камень") if pc_choice == 1: print("Ничья") elif pc_choice == 2: print("Вы выйграли") else: pc_choice == 3 print("Компьютер выйграл") if human_choice == 3: print("Ваш выбор - ножницы") if pc_choice == 1: print("Компьютер выйграл") elif pc_choice == 2: print("Ничья") else: pc_choice == 3 print("Вы выйграли") print(pc_choice, human_choice) pygame.quit() RE: How to select only one image from three? - michael1789 - Dec-19-2019 options = (rock, paper, scissors) selection = random.choice(options) |