Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tower.py~
diff options
context:
space:
mode:
Diffstat (limited to 'tower.py~')
-rw-r--r--tower.py~44
1 files changed, 35 insertions, 9 deletions
diff --git a/tower.py~ b/tower.py~
index 33bf43c..8186c20 100644
--- a/tower.py~
+++ b/tower.py~
@@ -1,4 +1,4 @@
-import random, os.path
+import random, os.path, time
import util
import pygame
@@ -358,9 +358,13 @@ def run():
shownGap1, shownGap2 = None, None #Variables will represent gaps that will be displayed (if they get hit or stepped on)
fallWait, topHoleWait = 0, 0 #Variables representing timers for if the hero is falling or a gap is being displayed because it was stepped on
+ gapFails = 0
+
run = 1 #Variable representing if the game is running
runCounter = 0 #The number of run loops the game has gone through
+ startTime = time.clock()
+
#The main game loop of the program
while run:
runCounter = runCounter+1
@@ -444,6 +448,8 @@ def run():
if hero.collidelist(impassableGaps) != -1:
fallWait = 60 #Sets the variable representing the fact that the hero is falling, because they went the wrong way
shownGap1 = impassableGaps[hero.collidelist(impassableGaps)]
+ gapFails = gapFails + 1
+ print "Falling! (#%d)"%(gapFails)
#checks if the hero is standing on top of a gap they cannot pass through
tempHero = hero.inflate(-70,0)
@@ -476,8 +482,8 @@ def run():
updateRects.append(shownGap2)
#Code which spawns a drop which contains a number, only called every 100 loops
- if runCounter%75 == 0:
- newDrop = generateDropNumber(heroNumber,levelNum)
+ if runCounter%100 == 0:
+ newDrop = generateDropNumber(heroNumber,levelNum,dropValues)
dropRects.append(pygame.Rect(random.randint(150,850),0,50,50))
dropValues.append(newDrop[0:2])
dropStrings.append(newDrop[2])
@@ -547,7 +553,12 @@ def run():
if hero.topleft[1] <= -80:
levelNum = levelNum+1
if levelNum == 8: #Made it to the top of the tower!
- victoryCinematic(screen)
+ #victoryCinematic(screen)
+ timeTaken = int(time.clock() - startTime)
+ minutesTaken = timeTaken/60
+ secondsTaken = timeTaken%60
+ topString = "You have reached the top!\nTime Taken: %dm %ds\nFails: %d"%(minutesTaken,secondsTaken,gapFails)
+ util.ok_box(topString, (450,400), 300, 50, screen)
break
#Copy copies the second floor displayed on the screen so it can be shown as the very bottom on the next level
@@ -581,9 +592,10 @@ def run():
background.blit(copy, (100,850))
print "Now on level %d."%(levelNum)
- print clock
- clock.tick(40) #limits to 40 FPS
-
+ #print clock
+ clock.tick(35) #limits to 40 FPS
+
+ pygame.quit()
def main():
print "Running Tower"
@@ -626,9 +638,23 @@ def victoryCinematic(screen):
util.ok_box("You have reached the top of the tower!", (450,400), 300, 50, screen)
-def generateDropNumber(heroNumber,level):
+def generateDropNumber(heroNumber,level,currentValues):
#Randomly selects if the drop will have addition, subtraction, multiplication, or division, addition and subtraction being more likely
- type = random.sample([0,0,0,0,0,0,1,1,1,1,1,1],1)[0]
+
+ #Only need to check the last 2 that dropped
+ currentValues = currentValues[len(currentValues)-2:]
+
+ type = random.sample([0,1],1)[0]
+
+ #Checks the previous entries to make sure we don't have the same type of operation more then twice
+ #As it is randomly generated, having +, +, +, +... etc over and over would not work well
+ if len(currentValues) == 2:
+ if currentValues[0][0] == currentValues[1][0]:
+ if currentValues[0][0] == 1:
+ type = 0
+ else:
+ type = 1
+
levelAverage = (levelRanges[level][0]+levelRanges[level][1])/2
returnString = ""
if type == 0: #Addition drop