Hướng dẫn how do you add a score to rock paper scissors in python? - Làm thế nào để bạn có thêm một số điểm cho trò oẳn tù tì trong trò chơi trăn?

Tôi đang làm việc trong một trò chơi kéo giấy đá. Mọi thứ dường như đang hoạt động tốt ngoại trừ bộ đếm chiến thắng/thua cuộc/cà vạt. Tôi đã xem xét một số trò chơi khác mà mọi người đã đăng ở đây và tôi vẫn không thể làm việc của tôi. Tôi cảm thấy như tôi rất gần nhưng tôi không thể có được nó! Thanks cho bất kỳ kẻ giúp đỡ. Đây là lần đầu tiên tôi đăng bài ở đây vì vậy tôi xin lỗi nếu tôi làm hỏng định dạng.

Tôi đã chỉnh sửa mã nhưng vẫn không thể khiến chương trình nhận ra bộ đếm mà không cần sử dụng các biến toàn cầu. Tại một thời điểm chỉnh sửa của tôi, tôi đã xoay sở để đếm mọi thứ như một chiếc cà vạt ... Tôi không biết làm thế nào và tôi đã mất nó ở đâu đó dọc theo chỉnh sửa của mình. cười lớn. -Có một lần nữa mọi người!

Đây là những gì tôi nhận được khi tôi chạy chương trình:

Prepare to battle in a game of paper, rock, scissors!
Please input the correct number according
to the object you want to choose.
Select rock[1], paper[2], or scissors[3]: 1
Computer chose PAPER .
You chose ROCK .
You lose!
Play again? Enter 'y' for yes or 'n' for no. y
Prepare to battle in a game of paper, rock, scissors!
Please input the correct number according
to the object you want to choose.
Select rock[1], paper[2], or scissors[3]: 2
Computer chose PAPER .
You chose PAPER .
It's a tie!
Play again? Enter 'y' for yes or 'n' for no. y
Prepare to battle in a game of paper, rock, scissors!
Please input the correct number according
to the object you want to choose.
Select rock[1], paper[2], or scissors[3]: 3
Computer chose SCISSORS .
You chose SCISSORS .
It's a tie!
Play again? Enter 'y' for yes or 'n' for no. n
Your total wins are 0 .
Your total losses are 0 .
Your total ties are 0 .
#import the library function "random" so that you can use it for computer 
#choice 
import random 

#define main 
def main[]: 
    #assign win, lose, and tie to zero for tallying
    win = 0 
    lose = 0 
    tie = 0 

    #control loop with 'y' variable 
    play_again = 'y' 

    #start the game 
    while play_again == 'y': 
        #make a welcome message and give directions 
        print['Prepare to battle in a game of paper, rock, scissors!'] 
        print['Please input the correct number according'] 
        print['to the object you want to choose.'] 

        #Get the player and computers choices and 
        #assign them to variables 
        computer_choice = get_computer_choice[] 
        player_choice = get_player_choice[] 

        #print choices 
        print['Computer chose', computer_choice, '.'] 
        print['You chose', player_choice, '.'] 

        #determine who won 
        winner_result[computer_choice, player_choice] 

        #ask the user if they want to play again 
        play_again = input["Play again? Enter 'y' for yes or 'n' for no. "] 

    #print results 
    print['Your total wins are', win, '.'] 
    print['Your total losses are', lose, '.'] 
    print['Your total ties are', tie, '.'] 

#define computer choice 
def get_computer_choice[]: 
    #use imported random function from library 
    choice = random.randint[1,3] 

    #assign what the computer chose to rock, paper, or scissors 
    if choice == 1: 
        choice = 'ROCK' 
    elif choice == 2: 
        choice = 'PAPER' 
    else: 
        choice = 'SCISSORS' 

    #return value 
    return choice 

#define player choice 
def get_player_choice[]: 
    #assign input to variable by prompting user 
    choice = int[input["Select rock[1], paper[2], or scissors[3]: "]] 

    #Detect invalid entry
    while choice != 1 and choice != 2 and choice != 3: 
        print['The valid numbers are rock[type in 1], paper[type in 2],'] 
        print['or scissors[type in 3].'] 
        choice = int[input['Enter a valid number please: ']] 

    #assign what the player chose based on entry 
    if choice == 1: 
        choice = 'ROCK' 
    elif choice == 2: 
        choice = 'PAPER' 
    else: 
        choice = 'SCISSORS' 

    #return value 
    return choice 

#determine the winner from the variables 
def winner_result[computer_choice, player_choice]: 
    #if its a tie, add 1 to tie variable and display message 
    if computer_choice == player_choice:
        result = 'tie'
        print["It's a tie!"]

    #if its a win, add to win tally and display message 
    elif computer_choice == 'SCISSORS' and player_choice == 'ROCK':
        result = 'win'
        print['ROCK crushes SCISSORS! You win!']
    elif computer_choice == 'PAPER' and player_choice == 'SCISSORS': 
        result = 'win'
        print['SCISSORS cut PAPER! You win!']
    elif computer_choice == 'ROCK' and player_choice == 'PAPER': 
        result = 'win'
        print['PAPER covers ROCK! You win!']

    #if it does not match any of the win criteria then add 1 to lose and 
    #display lose message 
    else: 
        result = 'lose'
        print['You lose!']

def result[winner_result,player_choice, computer_choice]:

    # accumulate the appropriate winner of game total
    if result == 'win':
        win += 1
    elif result == 'lose':
        lose += 1
    else:
        tie += 1
    return result

main[] 

Làm thế nào để bạn tạo ra một trò chơi kéo giấy đá với số điểm trong Python?

Thuật toán cho trò chơi cắt tỉa giấy đá..
Lập danh sách 3 tùy chọn- đá, giấy, cắt kéo ..
Hỏi tên của người chơi để chúng tôi có thể hiển thị nó trên bảng điểm ..
Khởi tạo điểm số của người chơi và máy tính thành 0 và số vòng đến 0 ..
Đặt cờ Gameon thành True ..
Trong khi cờ Gameon là đúng các bước 6 đến 12 ..

Có bao nhiêu kết quả có thể có trong kéo giấy đá?

Bằng cách thay thế lựa chọn của người chơi 1 bằng kéo, sau đó Rock, danh sách 9 kết quả trở thành danh sách đầy đủ 9 x 3 = 27 kết quả.Sơ đồ cây là sự thay thế tốt nhất cho danh sách các kết quả [Câu 2B].27 outcomes. A tree diagram is the best alternative to a list of outcomes [question 2b].

Làm thế nào để bạn khởi động lại kéo giấy đá trong Python?

var so sánh = function [lựa chọn1, lựa chọn2] {if [lựa chọn1 === lựa chọn2] {Prompt// Làm thế nào để bạn làm cho nó khởi động lại chức năng trong chức năng?} other if [lựa chọn1! = Hồi Rock |

Làm cách nào để tạo một trò chơi trong Python?

Python cung cấp một thư viện tích hợp có tên Pygame, được sử dụng để phát triển trò chơi.Khi chúng tôi hiểu các khái niệm cơ bản của lập trình Python, chúng tôi có thể sử dụng thư viện pygame để tạo ra các trò chơi với đồ họa hấp dẫn, hoạt hình phù hợp và âm thanh.Pygame là một thư viện đa nền tảng được sử dụng để thiết kế các trò chơi video.. Once we understand the basic concepts of Python programming, we can use the pygame library to make games with attractive graphics, suitable animation, and sound. Pygame is a cross-platform library that is used to design video games.

Bài Viết Liên Quan

Chủ Đề