Created
November 17, 2015 02:23
-
-
Save ronbeltran/59923a42d3033d213b79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 random | |
ATTACKS = ('Cowboy', 'Ninja', 'Bear') | |
COWBOY = 0 | |
NINJA = 1 | |
BEAR = 2 | |
def title(): | |
header = ', '.join(ATTACKS) | |
print header | |
print '_' * len(header) | |
options() | |
def options(): | |
print ''' | |
You can have the following options available: | |
c for cowboy | |
n for ninja | |
b for bear | |
r for rules | |
q for quit | |
''' | |
def rules(): | |
print ''' | |
Rules: | |
- Ninja beats Cowboy using lightning speed ninja kicks | |
- Cowboy beats Bear with his quick draw and perfect accuracy | |
- Bear beats Ninja with a strong swipe of his clawed paw | |
''' | |
options() | |
def goodbye(): | |
print 'Thanks for playing the game. Bye!' | |
def printPick(attack): | |
print 'Computer picked {}'.format(ATTACKS[attack]) | |
def show_winner(user, computer): | |
winner = None | |
if user == computer: | |
winner = 'We tied!' | |
elif user == NINJA and computer == COWBOY or user == COWBOY and computer == NINJA: | |
winner = 'Ninja beats cowboy.' | |
elif user == COWBOY and computer == BEAR or user == BEAR and computer == COWBOY: | |
winner = 'Cowboy beats bear.' | |
elif user == BEAR and computer == NINJA or user == NINJA and computer == BEAR: | |
winner = 'Bear beats Ninja.' | |
print winner | |
def battle(user_attack): | |
computer_attack = random.randint(0, 2) | |
printPick(computer_attack) | |
show_winner(user_attack, computer_attack) | |
if __name__ == "__main__": | |
title() | |
while True: | |
choice = str(raw_input('Please make your selection: ')).lower() | |
if choice == "q": | |
goodbye() | |
break | |
elif choice in ['c', 'n', 'b']: | |
if choice == 'c': | |
battle(0) | |
elif choice == 'n': | |
battle(1) | |
else: | |
battle(2) | |
else: | |
print 'Invalid choice' | |
rules() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment