Created
October 27, 2012 03:05
-
-
Save RyanBreaker/3962791 to your computer and use it in GitHub Desktop.
Rock, Paper, Scissors game written in Python 2.
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
import os | |
from random import randint | |
from text import text | |
def printInfo(case): | |
os.system("cls" if os.name=='nt' else "clear") | |
if case == "start": | |
print "Rock, Paper, Scissors!" | |
print text % (wins, losses, ties) | |
else: | |
print case | |
print text % (wins, losses, ties) | |
def getAI(num): | |
if num == 1: | |
return 'r' | |
elif num == 2: | |
return 'p' | |
elif num == 3: | |
return 's' | |
wins = 0 | |
losses = 0 | |
ties = 0 | |
cont = True # cont = Continue | |
case = "start" | |
while cont == True: | |
printInfo(case) | |
plyr = raw_input('> ').lower() | |
ai = getAI(randint(1, 3)) | |
if plyr == ai: | |
ties += 1 | |
case = "Tie!" | |
if plyr == 'r': | |
if ai == 'p': | |
losses += 1 | |
case = "Loss! AI pulled Paper!" | |
elif ai == 's': | |
wins += 1 | |
case = "Win! AI used a Scissors!" | |
elif plyr == 'p': | |
if ai == 'r': | |
wins += 1 | |
case = "Win! AI threw a Rock!" | |
elif ai == 's': | |
losses += 1 | |
case = "Loss! AI used a Scissors!" | |
elif plyr == 's': | |
if ai == 'r': | |
losses += 1 | |
case = "Loss! AI Threw a Rock!" | |
elif ai == 'p': | |
wins += 1 | |
case = "Win! AI pulled Paper!" | |
elif plyr == 'q': | |
cont = False | |
else: | |
case = "Incorrect Input!" | |
os.system("cls" if os.name=='nt' else "clear") | |
print "Press Enter to exit." | |
raw_input() |
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
text = """-------------------- | |
Enter R for Rock | |
Enter P for Paper | |
Enter S for Scissors | |
Enter Q to Quit | |
-------------------- | |
Wins: %d | |
Losses: %d | |
Ties: %d""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment