Last active
February 26, 2016 07:03
-
-
Save dumpmycode/9dfdc07ba479676ff56c to your computer and use it in GitHub Desktop.
practicepython.org - Rock Paper Scissor single player game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# Author: OscarP | |
# A single player jankenpon game using randint to generate computer's hand. | |
# Please feel free to revise. | |
from random import randint | |
def convert(choice): | |
if choice == '1': | |
return 'rock' | |
elif choice == '2': | |
return 'scissor' | |
elif choice == '3': | |
return 'paper' | |
else: | |
print('Enter 1, 2 or 3 only please.\nfuck this shit im out!') | |
exit(0) | |
def win(): | |
print('You win!') | |
print('\033[1;31m{}\033[1;m vs {}'.format(player,computer)) | |
def lose(): | |
print('You lost.') | |
print('\033[1;31m{}\033[1;m vs {} '.format(player, computer)) | |
def jankenpon(player, computer): | |
if player == computer: | |
print ('Its a tie!') | |
print('\033[1;31m{}\033[1;m vs {} '.format(player, computer)) | |
elif player == 'rock': | |
if computer == 'scissor': | |
win() | |
else: | |
lose() | |
elif player == 'scissor': | |
if computer == 'paper': | |
win() | |
else: | |
lose() | |
else: | |
if computer == 'rock': | |
win() | |
else: | |
lose() | |
newgame = raw_input('Do you want to play JanKenPon? (y/n)') | |
while newgame == 'y': | |
computer = str(randint(1,3)) | |
player = raw_input('Player 1 enter your hand (1: rock, 2: scissor, 3: paper) = ') | |
computer = convert(computer) | |
player = convert(player) | |
jankenpon(player, computer) | |
newgame = raw_input('Do you want to keep playing JanKenPon? (y/n)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment