示例#1
0
def main():
    playerName = input("Give your name: ")

    #Luodaan pelaajaoliot
    human = HumanPlayer(playerName)
    cpu = CPUPlayer("CPU")

    isQuitting = False
    while not isQuitting:
        humanResult = human.play()
        cpuResult = cpu.play()

        result = resolve(humanResult, cpuResult)

        print(human.name, humanResult)
        print(cpu.name, cpuResult)

        if result == 0:
            print("It's a tie!")
        elif result == 1:
            print(human.name, "wins!!")
        else:
            print(cpu.name, "wins!!")

        playAgain = input("Play again (y/n").lower().strip()
        isQuitting = playAgain == "n"
示例#2
0
def resolve(p1Choice, p2Choice, winningData):
    ''' Palauttaa 1, jos pelaaja 1 voittaa, 0 tasapelissä ja -1 pelaajan 2 voittaessa '''
    return winningData[p1Choice][p2Choice]


playerName = input("Give your name: ")

player1 = HumanPlayer(playerName)
player2 = CPUPlayer("CPU")

isQuitting = False

while isQuitting == False:
    # Peliä loopataan, kunnes pelaaja päättä lopettaa pelin
    p1Choice = player1.play()
    p2Choice = player2.play()
    result = resolve(p1Choice, p2Choice, winningData)

    print(player1.name, p1Choice.name)
    print(player2.name, p2Choice.name)

    if result == 0:
        print("It's a tie!")
    elif result == 1:
        print(player1.name, "wins!")
    else:
        print(player2.name, "wins!")

    playAgain = input("Play again (y/n)? ").lower().strip()
    isQuitting = playAgain == "n"  # true vain, kun pelaaja syöttää merkin 'n'