Skip to content
Open
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b70ae97
location. py is the function indicating the site of pathogen, and imp…
Subeen-Kim Oct 19, 2017
c40af24
Version 1 Skeleton UI
jwen2 Oct 22, 2017
086c735
Added Click Interaction
jwen2 Oct 23, 2017
104e084
Virus Draft - RAW
victorbianchi Oct 23, 2017
2cc94cd
Merge branch 'master' of https://github.com/jwen2/InteractiveProgramming
victorbianchi Oct 23, 2017
d61d10c
Merge branch 'master' of https://github.com/jwen2/InteractiveProgramming
Subeen-Kim Oct 23, 2017
b2a41e0
1st trial about time and input handling
Subeen-Kim Oct 23, 2017
a913dc0
Added Time and Pause Botton on Bottom Right
jwen2 Oct 23, 2017
8486919
Merge branch 'master' of https://github.com/jwen2/InteractiveProgramming
jwen2 Oct 23, 2017
bbf1fd4
Country Population Database
victorbianchi Oct 25, 2017
b80dbf4
Merge branch 'master' of https://github.com/jwen2/InteractiveProgramming
victorbianchi Oct 25, 2017
262f5c1
Attempting to Add Circle Interaction
jwen2 Oct 26, 2017
7fdce31
Merge branch 'master' of https://github.com/jwen2/InteractiveProgramming
jwen2 Oct 26, 2017
4273f42
UI Screen Change Test - Press C to Change Screens/Run Functions
jwen2 Oct 26, 2017
558de66
Useful File
jwen2 Oct 27, 2017
20379d8
new virus format with gorgeous time stuff
Subeen-Kim Oct 27, 2017
db39c83
propagation and death types are added
Subeen-Kim Oct 27, 2017
d73f897
Added display for total infected/total pop. Fixed Initial Infection
jwen2 Oct 29, 2017
95155e0
Added title screen and instructions
jwen2 Oct 29, 2017
16cbf96
modification about death stops at 5
Subeen-Kim Oct 29, 2017
a11db98
Added rounds function
vtbianchi Oct 29, 2017
741f559
Merge branch 'master' of https://github.com/jwen2/InteractiveProgramming
vtbianchi Oct 29, 2017
d8be63f
now it stops at zero
Subeen-Kim Oct 29, 2017
7e115a0
Upgrade points is updated
Subeen-Kim Oct 29, 2017
f49c50c
Merge branch 'master' of https://github.com/jwen2/InteractiveProgramming
Subeen-Kim Oct 29, 2017
0a42179
Added End Game Screen
jwen2 Oct 29, 2017
6fd3c15
Added upgrade possibility
vtbianchi Oct 29, 2017
1fae333
I modified Upgrade_Point into linear function
Subeen-Kim Oct 30, 2017
4e5d19a
death rate modified
Subeen-Kim Oct 30, 2017
6b59ba4
ReadMe File
vtbianchi Oct 30, 2017
d5c9fd7
Read Me File
vtbianchi Oct 30, 2017
1d851ea
Added upgrades
vtbianchi Oct 30, 2017
6086d69
Added Upgrade Points Box, Slow'd down points gain, Fixed upgrade cost
jwen2 Oct 30, 2017
ef209e0
documentation is improved
Subeen-Kim Oct 30, 2017
a2e05c5
Wirte-up and Reflection file
Subeen-Kim Oct 30, 2017
3cb86bd
Reflection
vtbianchi Oct 30, 2017
b2326b7
Added doctor and cure funtionality, Fixed death bug (stuck at 15), ad…
jwen2 Dec 9, 2017
9a12fb2
Merge branch 'master' of https://github.com/jwen2/InteractiveProgramming
jwen2 Dec 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added doctor and cure funtionality, Fixed death bug (stuck at 15), ad…
…ded more documentation
  • Loading branch information
jwen2 committed Dec 9, 2017
commit b2326b7ff08b166577fecf0fb3ca7d521cee55d4
71 changes: 62 additions & 9 deletions Country.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Copy link
Copy Markdown

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.

"""
Each country has its maximum population without any infected people,
Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's recommended that you give constants a name and capitalize them. self.infected_ratio() > THRESHOLD.
Also, it's common practice to make a config class that contains all these arbitrary values

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:
Expand All @@ -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
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, global variables are capitalized e.g. BACKGROUND_COLOR.

width, height = 640, 480

Expand Down Expand Up @@ -142,23 +158,25 @@ def propagation(self, other):

screen = pygame.display.set_mode((640, 480))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this setup code could go into a setup() function.


""" 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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"""
Expand Down Expand Up @@ -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"""

@SeunginLyu SeunginLyu Dec 11, 2017 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using inline comments # if the population is zero, then game is over if the comments can be kept brief.

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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.
Expand All @@ -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:
Expand All @@ -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():
Expand All @@ -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()