-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
782 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Car(object): | ||
num_wheels = 4 | ||
gas = 30 | ||
headlights = 2 | ||
size = 'Tiny' | ||
|
||
def __init__(self, make, model): | ||
self.make = make | ||
self.model = model | ||
self.color = 'No color yet. You need to paint me.' | ||
self.wheels = Car.num_wheels | ||
self.gas = Car.gas | ||
|
||
def paint(self, color): | ||
self.color = color | ||
return self.make + ' ' + self.model + ' is now ' + color | ||
|
||
def drive(self): | ||
if self.wheels < Car.num_wheels or self.gas <= 0: | ||
return 'Cannot drive!' | ||
self.gas -= 10 | ||
return self.make + ' ' + self.model + ' goes vroom!' | ||
|
||
def pop_tire(self): | ||
if self.wheels > 0: | ||
self.wheels -= 1 | ||
|
||
def fill_gas(self): | ||
self.gas += 20 | ||
return 'Gas level: ' + str(self.gas) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
from classes import * | ||
from cards import * | ||
|
||
try: | ||
import readline | ||
except ImportError: | ||
pass | ||
|
||
########### | ||
# Parsing # | ||
########### | ||
|
||
def card_parse(line, handsize): | ||
tokens = line.split() | ||
if not tokens: | ||
raise SyntaxError('No command given') | ||
elif len(tokens) > 1: | ||
raise SyntaxError('Too many inputs') | ||
card_index = tokens.pop(0) | ||
if not card_index.isdigit(): | ||
raise SyntaxError('Wrong type of input') | ||
card_index = int(card_index) | ||
if card_index >= handsize or card_index < 0: | ||
raise SyntaxError('Invalid card number') | ||
return card_index | ||
|
||
def name_parse(line): | ||
if not line: | ||
raise SyntaxError('No command given') | ||
return line | ||
|
||
######## | ||
# REPL # | ||
######## | ||
|
||
def read_eval_print_loop(): | ||
while True: | ||
try: | ||
line = input('What is your name?> ') | ||
name = name_parse(line) | ||
break | ||
except (KeyboardInterrupt, EOFError, SystemExit): # If you ctrl-c or ctrl-d | ||
print('\nSee you next game!') | ||
return | ||
except SyntaxError as e: | ||
print('ERROR:', e) | ||
p1 = Player(player_deck, name) | ||
p2 = Player(opponent_deck, 'Opponent') | ||
print(WELCOME_MESSAGE) | ||
duel = Game(p1, p2) | ||
draw = True | ||
while True: | ||
if duel.game_won() == 1: | ||
print(WIN_MESSAGE) | ||
return | ||
elif duel.game_won() == 2: | ||
print(LOSE_MESSAGE) | ||
return | ||
print() | ||
try: | ||
if draw: | ||
p1.draw() | ||
p2.draw() | ||
else: | ||
draw = True | ||
p1.display_hand() | ||
print('Please enter the number next to the card you would like to play this round.') | ||
line = input('card> ') | ||
card_index = card_parse(line, len(p1.hand)) | ||
duel.play_round(p1.play(card_index), p2.play_random()) | ||
duel.display_scores() | ||
except (KeyboardInterrupt, EOFError, SystemExit): # If you ctrl-c or ctrl-d | ||
print('\nGood game. Bye!') | ||
return | ||
except AssertionError: # Deck out | ||
if p1.deck.is_empty() and p2.deck.is_empty(): | ||
print(TIE_MESSAGE) | ||
return | ||
elif p1.deck.is_empty(): | ||
print(PLAYER_DECKOUT_MESSAGE) | ||
return | ||
else: | ||
print(OPPONENT_DECKOUT_MESSAGE) | ||
return | ||
except SyntaxError as e: | ||
print('ERROR:', e) | ||
draw = False | ||
|
||
################# | ||
# Configuration # | ||
################# | ||
|
||
WELCOME_MESSAGE = """ | ||
Welcome to Magic: The Lambda-ing! | ||
Your code has taken on a mind of its own and has | ||
challenged you to a game of cards! If you need a refresher | ||
on the rules, check out the section on the lab page. | ||
Let's get this duel started, shall we? | ||
""" | ||
|
||
WIN_MESSAGE = """ | ||
You have vanquished your foe in a duel! | ||
Congratulations! You won this game of Magic: The Lambda-ing! | ||
""" | ||
|
||
LOSE_MESSAGE = """ | ||
You have been defeated by your foe in a duel! | ||
I'm sorry, you lost this game of Magic: The Lambda-ing. | ||
""" | ||
|
||
TIE_MESSAGE = """ | ||
You and your opponent have no cards left in your decks! | ||
You tied this game of Magic: The Lambda-ing. Who will win if you play again? | ||
""" | ||
|
||
PLAYER_DECKOUT_MESSAGE = """ | ||
You have no cards left in your deck! | ||
I'm sorry, you lost this game of Magic: The Lambda-ing. | ||
""" | ||
|
||
OPPONENT_DECKOUT_MESSAGE = """ | ||
Your opponent has no cards left in their deck! | ||
Congratulations! You won this game of Magic: The Lambda-ing! | ||
""" | ||
|
||
if __name__ == '__main__': | ||
read_eval_print_loop() | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# All cards available in a standard deck. | ||
from classes import * | ||
|
||
#TAs | ||
aaron = TACard('Baron Aaron', 2100, 1300) | ||
addison = TACard('Addison, from operator import add', 1000, 2000) | ||
albert = TACard('Albert, Lethargy Incarnate', 1000, 2000) | ||
alex_k = TACard('Alex, Skipper of Labs and Preparer for Exams', 2293.141593, 1111.11111) | ||
alex_s = TACard('President Lieutenant Stennet for Senate', 1400, 2000) | ||
aman = TACard('Aman', 1000, 2100) | ||
amrita = TACard('Amrita, the Pun-stoppable', 1800, 1450) | ||
annie = TACard('Annie, the Annihilator of Water', 1700, 1500) | ||
audrey = TACard('Audrey, Excitable Engineer', 1777, 1777) | ||
brandon = TACard('Brandon, Not Brendan ', 1234, 1234) | ||
catherine = TACard('Catherine, Referencer of Self', 2500, 900) | ||
cesar = TACard('Cesar, Surveyor of Steaz', 1337, 2222) | ||
chae = TACard('Chae', 1500, 1900) | ||
charles = TACard('Charles, Protector of UwU', 1000, 2000) | ||
dalton = TACard('Dalton, Unit of Atomic Mass', 2144, 1998) | ||
danelle = TACard('Danelle Nachos', 2200, 1100) | ||
derek = TACard('Derek, The Wan and Only', 2000, 1000) | ||
derrick = TACard('EZ4ENCE', 1100, 2000) | ||
griffin = TACard('Griffin, He Who is Hydrated', 1000, 2000) | ||
jack = TACard('Jack, The Master of Dice', 1650, 2100) | ||
jade = TACard('Jade, Singher of Songs', 1700, 1500) | ||
kavi = TACard('Kavi Gupta', 2100, 1000) | ||
lillian = TACard('Lillian, Linda', 1100, 2100) | ||
nancy = TACard('Nancy, The Sheep in the Jeep', 1100, 2100) | ||
patricia = TACard('Patricia, Pokémon Master', 1800, 1600) | ||
paul = TACard('Better Call Paul', 2100, 1200) | ||
regina = TACard('Regina, Wrangler of Skipped Readings', 1200, 2250) | ||
richard = TACard('Richard, Admirer of Baby Yoda ', 1800, 2000) | ||
sean = TACard('Sean, the Over-Caffeinated', 1000, 2300) | ||
shayna = TACard('Shayna, Procrastinator Supreme', 1916, 1459) | ||
yannan = TACard('Yannan, the Yammeister', 1500, 1900) | ||
yichen = TACard('Yichen, Drinker of Boba', 1800, 1500) | ||
|
||
#Tutors | ||
christine = TutorCard('Christine', 1500, 1700) | ||
ethan = TutorCard('Ethan, Pillar of the Demon Slayer Corps', 1800 , 1100) | ||
grant = TutorCard('Grant', 1100, 2100) | ||
ivan = TutorCard('Ivan, the ender of dreaming the starter of scheming', 1900, 2300) | ||
jason = TutorCard('Jason, Counter of Chang-e', 1500, 1900) | ||
jemmy = TutorCard('Jemmy, the Joker', 1200, 1700) | ||
jessica = TutorCard('Jessica, Lover of Shin Ramen', 1528, 2154) | ||
lauren = TutorCard('Lauren, Queen of First Floor Moffitt', 1200, 1800) | ||
matthew = TutorCard('Matty Lee', 2000, 1500) | ||
nicholas = TutorCard('Nicholas, Keeper of Shared Secrets', 1009, 2297) | ||
nikhita = TutorCard('Nikhita, Always Schemin', 1700, 1700) | ||
uma = TutorCard('Uma, Hoarder of Hydroflasks', 1200, 1700) | ||
|
||
|
||
|
||
|
||
# Professors | ||
denero = ProfessorCard('John DeNero, Protector of Abstraction Barriers', 5000, 5000) | ||
|
||
# A standard deck contains all standard cards. | ||
standard_cards = [denero, aaron, addison ,albert ,alex_k ,alex_s ,aman ,amrita ,annie ,audrey ,brandon ,catherine ,cesar ,chae ,charles ,dalton ,danelle ,derek ,derrick ,griffin ,jack ,jade ,kavi ,lillian ,nancy ,patricia ,paul ,regina ,richard ,sean ,shayna ,yannan ,yichen ,ethan ,grant ,ivan ,jason ,jemmy ,jessica ,lauren ,matthew ,nicholas ,nikhita ,uma] | ||
standard_deck = Deck(standard_cards) | ||
|
||
# The player and opponent's decks are the standard deck by default. | ||
player_deck = standard_deck.copy() | ||
opponent_deck = standard_deck.copy() | ||
|
Oops, something went wrong.