Repository navigation
Turn in the Mini Project 4 #6
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
b70ae97
c40af24
086c735
104e084
2cc94cd
d61d10c
b2a41e0
a913dc0
8486919
bbf1fd4
b80dbf4
262f5c1
7fdce31
4273f42
558de66
20379d8
db39c83
d73f897
95155e0
16cbf96
a11db98
741f559
d8be63f
7e115a0
f49c50c
0a42179
6fd3c15
1fae333
4e5d19a
6b59ba4
d5c9fd7
1d851ea
6086d69
ef209e0
a2e05c5
3cb86bd
b2326b7
9a12fb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ded more documentation
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,20 @@ | |
| pygame.init() | ||
| font = pygame.font.SysFont('Consolas', 20) | ||
|
|
||
| class Doctor: | ||
| """ | ||
| Doctor begins to work on a cure after a certain amount of upgrades | ||
| or after time has elapsed for a certain time | ||
| """ | ||
| def __init__(self, timer=120, rate=1, percent=0): | ||
| """ Timer is set for when the cure will be started | ||
| Rate is at what rate the cure is being develop | ||
| If cure.percent is 100 percent the game is over | ||
| """ | ||
| self.timer = timer | ||
| self.rate = rate | ||
| self.percent = percent | ||
|
|
||
| class Country: | ||
| """ | ||
| Each country has its maximum population without any infected people, | ||
|
|
@@ -44,15 +58,15 @@ def infected_ratio(self): | |
|
|
||
| def death(self): | ||
| """ | ||
| A part of the infected population would be passed away. | ||
| A part of the infected population would be killed. | ||
| Then the infected population and maximum population will be reduced as many as the number of people death. | ||
| """ | ||
| death_pop = 0 | ||
| alive_pop = self.max_pop | ||
| if self.infected_ratio() > 0.10: | ||
| if self.infected_pop > 10: | ||
| if self.infected_ratio() > 0.10: #ratios are arbitrarily selected | ||
|
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. It's recommended that you give constants a name and capitalize them. |
||
| if self.infected_pop > 15: | ||
| death_pop = int(self.death_rate*self.infected_pop*(random.random()/15)) | ||
| else: | ||
| else: #once population hits below 15, we no longer use a ratio | ||
| if self.max_pop >= 1: | ||
| death_pop = 1 | ||
| else: | ||
|
|
@@ -66,6 +80,8 @@ def step(self): | |
| """ | ||
| If infection starts (infect_pop changed into unity), | ||
| then the infection starts with the certain rate | ||
|
|
||
| When infected population is at max pop, the infection rate stops. | ||
| """ | ||
| if self.infected_pop < self.max_pop: | ||
| self.infected_pop = self.infected_pop * self.infected_rate | ||
|
|
@@ -102,7 +118,7 @@ def propagation(self, other): | |
| if random.random() <= self.infected_ratio()/10: | ||
| other.infected_pop = 1 | ||
|
|
||
|
|
||
| """Varibles for pygame display""" | ||
| background_color = (255,255,255) | ||
|
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. Usually, global variables are defined before any other code is written - but this doesn't affect the rest of your code in any way.
Contributor
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. By convention, global variables are capitalized e.g. |
||
| width, height = 640, 480 | ||
|
|
||
|
|
@@ -142,23 +158,25 @@ def propagation(self, other): | |
|
|
||
| screen = pygame.display.set_mode((640, 480)) | ||
|
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. All of this setup code could go into a |
||
|
|
||
| """ Herein, three countries are defined """ | ||
| """ Herein, three countries are defined as well as the doctor """ | ||
| country1 = Country(200, 120, 200, radius=60) | ||
| country2 = Country(500, 180, 200, radius=40, color=BLUE) | ||
| country3 = Country(320, 360, 200, radius=50, color=GREEN) | ||
| countries = [country1, country2, country3] | ||
| country_pop_index = country1 | ||
| total_pop = 0 | ||
|
|
||
| doctor1 = Doctor() | ||
|
|
||
| Time = 0 | ||
| time = 0 | ||
| upgrades = 0 | ||
| Upgrade_Point = 0 | ||
|
Contributor
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. By convention, variables whose values change (variables that are not constants) are all lowercase. |
||
| infectionindex = 1 | ||
| """ This is the counter to allow you to | ||
|
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. You don't need multiline comments here - inline comments will suffice. |
||
| click on a country and place a pathogen""" | ||
| clock = pygame.time.Clock() | ||
|
|
||
| upgrades = 0 | ||
|
|
||
| """ Pressing C will officially start the game running our | ||
|
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 main game loop should be inside its own function. |
||
| game function with time""" | ||
|
|
@@ -208,12 +226,23 @@ def propagation(self, other): | |
| """Modify Time + XXXX to modify the speed of the game.""" | ||
| if pygame.time.get_ticks() > (Time + 1000): | ||
| Time = pygame.time.get_ticks() | ||
| """ If population == 0 then game is over""" | ||
|
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. I suggest using inline comments |
||
| if all(country.max_pop == 0 for country in countries) == True: | ||
| running = False | ||
| endscreen = True | ||
| #print ('For each country: (infected ratio, total population)', (country1.infected_ratio(),country1.max_pop), (country2.infected_ratio(),country2.max_pop), (country3.infected_ratio(),country3.max_pop)) | ||
|
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. I suggest removing print statements and logs before submitting pull requests (in the future) |
||
| Total_infected = 0 | ||
| """ | ||
| Doctor starts working if time is above a certain time or if upgrade counts | ||
| are more than 3 | ||
|
|
||
| Once cure is started, the percent increments by the cure rate | ||
| """ | ||
| if (upgrades > 3) or (pygame.time.get_ticks() > (doctor1.timer * 1000)): | ||
| doctor1.percent = doctor1.percent + (doctor1.rate) | ||
| if doctor1.percent == 100: | ||
| running = False | ||
| lose = True #if doctor cure hits 100% lost screen is played | ||
| """ | ||
| Infection types: step, death, propagation | ||
| Upgrade Point is given at every step. | ||
|
|
@@ -224,7 +253,7 @@ def propagation(self, other): | |
| Total_infected += (country.infected_pop + country.dead_pop) | ||
| if infectionindex == 0: | ||
| if country.max_pop !=0: | ||
| if pygame.time.get_ticks() > (time + 2000): | ||
| if pygame.time.get_ticks() > (time + 4000): | ||
| time = pygame.time.get_ticks() | ||
| Upgrade_Point += random.randint(1,3) | ||
| for other in countries: | ||
|
|
@@ -243,9 +272,11 @@ def propagation(self, other): | |
| """ | ||
| screen.blit(font.render('Infected:%.2d'%(country_pop_index.infected_pop) + ' ' +'Dead:%.2d'%(country_pop_index.dead_pop) + ' '+ 'Alive:%.2d'%(country_pop_index.max_pop) +' '+'Upgrade Point:%.2d'%(Upgrade_Point) , True, (0, 255, 255)), (0, 440)) | ||
| screen.blit(font.render('Current Upgrades:%.2d'%(upgrades), True, (0, 255, 255)), (400, 400)) | ||
| screen.blit(font.render('Current Cure Percentage:%.2d'%(doctor1.percent), True, (0, 255, 255)), (0, 400)) | ||
| pygame.display.update() # updates real screen from staged screen | ||
|
|
||
|
|
||
| endscreen = False | ||
| """End screen when everyone is dead """ | ||
| while endscreen: | ||
| screen.fill(background_color) | ||
| for event in pygame.event.get(): | ||
|
|
@@ -267,4 +298,26 @@ def propagation(self, other): | |
|
|
||
| pygame.display.update() | ||
|
|
||
| """Endscreen when the disease is cured""" | ||
| while lose: | ||
| screen.fill(background_color) | ||
| for event in pygame.event.get(): | ||
| if event.type == pygame.QUIT: | ||
| pygame.quit() | ||
| quit() | ||
|
|
||
| if event.type == pygame.KEYDOWN: | ||
| if event.key == pygame.K_q: | ||
| pygame.quit() | ||
| quit() | ||
|
|
||
|
|
||
| text = basicfont.render('The Doctor Has Cured Your Disease! Press Q to end the game.', True, (0, 0, 0), (255, 255, 255)) | ||
| textrect = text.get_rect() | ||
| textrect.centerx = screen.get_rect().centerx | ||
| textrect.centery = screen.get_rect().centery | ||
| screen.blit(text, textrect) | ||
|
|
||
| pygame.display.update() | ||
|
|
||
| pygame.quit() | ||
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.
This class could be put into its own file and imported.