Repository navigation
Project Submission #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
2c87b85
24678e7
a168e80
42abeb2
8730859
d959455
f4556da
dba8016
8976520
5118db2
2d2ea2d
c15d2ea
4933c21
e4c2e94
afea157
a786ea4
d0b42b6
96e4cd4
b133a20
03ad23a
459d704
f273cc2
31a7cdb
163590c
5b05cd1
30641b9
2c3120d
07ab946
bd1937a
e183459
47cb257
d216f76
cf87127
df10443
a870d23
3dac77b
2435bc3
e82a305
8155d51
231df00
90fad98
2efaecc
231e65f
a7ed21a
453689c
bc190ca
a8d39f8
59af4e5
7d216f1
6894572
4130462
5863d32
f63593d
8f2efc1
646e64c
8bfb444
6f88e50
62e75c2
4b50ce2
9dcf674
245d255
340cbe8
b96b29e
4549dc2
e773ac0
e6a9e17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,11 @@ | ||
| # Author: Isa Blancett | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job with the unit testing! |
||
| # Project: Interactive Programming | ||
| # Date: 10.30.2017 | ||
| # Description: Class for current gameplay status, including course levels and | ||
| # round number | ||
| # Acknowledgements: Script structure is modeled after Transcriptase's Game | ||
| # repository on Git | ||
|
|
||
| from sys import exit | ||
| import courses | ||
| import doctest | ||
|
|
@@ -7,10 +15,10 @@ class Gameplay(object): | |
| #Parses player commands and manipulates a map object | ||
|
|
||
| def __init__ (self, courses): | ||
| self.courses = courses | ||
| self.labels = list(courses) | ||
| self.order = [] | ||
| self.round = 0 | ||
| self.courses = courses # dictionary of course instances | ||
| self.labels = list(courses) # list of four letter labels for each course | ||
| self.order = [] # list of labels in order of the player's choosing | ||
| self.round = 0 # round number of the current game | ||
|
|
||
| def add_order(self, selection): | ||
| """ adds the order to a course's class instance if picked | ||
|
|
@@ -23,20 +31,23 @@ def add_order(self, selection): | |
| >>> print(test_game.courses['mech'].order) | ||
| 1 | ||
| """ | ||
| # increase round | ||
| self.round = self.round + 1 | ||
| for label in self.labels: | ||
| if label == selection.pressed: | ||
| self.courses[label].order = self.round | ||
| self.courses[label].lvl = 1 | ||
| self.order.append(label) | ||
|
|
||
| # add order and level up newest choice | ||
| label = selection.pressed | ||
| self.courses[label].order = self.round | ||
| self.courses[label].lvl = 1 | ||
| self.order.append(label) | ||
|
|
||
| # return whether all courses have been picked | ||
| return len(self.order) == len(list(self.courses)) | ||
|
|
||
| def level_up(self): | ||
| """ level up any courses that meet all requirements starting with the | ||
| user's previous choice | ||
|
|
||
| returns: dictionary of courses | ||
| returns: None | ||
|
|
||
| Examples: | ||
| >>> test_game = Gameplay(courses.populate(), 0) | ||
|
|
@@ -46,11 +57,14 @@ def level_up(self): | |
| >>> print(test_game.courses['mech'].lvl) | ||
| 2 | ||
| """ | ||
|
|
||
| # No leveling up until 2 courses have been picked | ||
| if len(self.order) > 1: | ||
| # Start leveling with second most recent course selection | ||
| for label in reversed(self.order[:-1]): | ||
| if 0 < int(self.courses[label].lvl) < int(self.courses[label].max) and self.check_reqs(label): | ||
| # Check for maxed out and for dependencies | ||
| if int(self.courses[label].lvl) < int(self.courses[label].max) and self.check_reqs(label): | ||
| self.courses[label].lvl = self.courses[label].lvl + 1 | ||
| return | ||
|
|
||
| def check_reqs(self, label): | ||
| """ given a course label, checks whether all dependencies are met | ||
|
|
@@ -72,12 +86,17 @@ def check_reqs(self, label): | |
| """ | ||
| reqs_met = [] | ||
| lvl = self.courses[label].lvl | ||
|
|
||
| # Loop through reqs of given class | ||
| for req in self.courses[label].reqs: | ||
| # Parse req string for dependent level, needed course, and needed course level | ||
| deplvl = int(req[0]) | ||
| neededcourse = req[1:5] | ||
| neededlevel = int(req[-1]) | ||
| if deplvl == lvl: | ||
| neededcourse = req[1:5] | ||
| neededlevel = int(req[-1]) | ||
| # Append list with True if req has been met | ||
| reqs_met.append(neededlevel <= self.courses[neededcourse].lvl) | ||
| # Return true if all reqs are met or no reqs are needed | ||
| return all(reqs_met) or not len(reqs_met) | ||
|
|
||
| def evaluate_portfolio(self): | ||
|
|
@@ -90,13 +109,16 @@ def evaluate_portfolio(self): | |
| >>> test_game.evaluate_portfolio() | ||
| "Your portfolio could use a little more work. Try again?" | ||
| """ | ||
| # Get list of current levels and max levels | ||
| lvls = [int(self.courses[label].lvl) for label in list(self.courses)] | ||
| maxlvls = [int(self.courses[label].max) for label in list(self.courses)] | ||
| # 1 = perfect game, 2 = acceptable game, 0 = bad game (no job 4 u!!) | ||
| if lvls == maxlvls: | ||
| return 1 | ||
| elif (sum(lvls)) >= (sum(maxlvls)*3/4): | ||
| return 2 | ||
| else: | ||
| return 0 | ||
|
|
||
| # Example docstring test | ||
| # doctest.run_docstring_examples(Gameplay.evaluate_portfolio, globals(), verbose=True) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,24 @@ | ||
| # import all scripts here | ||
| # Author: Leo Liu, Siena Okuno, & Isa Blancett | ||
| # Project: Interactive Programming | ||
| # Date: 10.30.2017 | ||
| # Description: Game setup, loop through game graphics and control, & ending call | ||
|
|
||
| import courses | ||
| from gameplay import Gameplay | ||
| import environment | ||
| import sys | ||
| import pygame | ||
| import ending | ||
| from environment import * | ||
|
|
||
| # INITIALIZE GAME | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code below should be in a function or a class. It's always good practice to wrap things up and not have them free floating in a file. |
||
| BUTTON = pygame.USEREVENT + 1 | ||
| init_courses = courses.populate() | ||
| text_screen = environment.initialize() | ||
| screen = text_screen[0] | ||
| text = text_screen[1] | ||
| control = Gameplay(init_courses) | ||
|
|
||
| # LOOP THROUGH GRAPHICS AND CONTROLS, CHECKING FOR PASSING OF EVENTS | ||
| done = False | ||
| while not done: | ||
| for event in pygame.event.get(): | ||
|
|
@@ -27,7 +32,7 @@ | |
| pygame.display.flip() | ||
| pygame.event.pump() | ||
|
|
||
|
|
||
| # EVALUATE ENDING AND SEND TO VICTORY SCREEN | ||
| victory = control.evaluate_portfolio() | ||
| if victory == 1: | ||
| ending.determine(victory, ["%s: %s" % (control.courses[course].name, 'MAX') for course in control.courses]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job with the header comments on the files!