Advertisement
brostoevski

Master Hunter

Jan 24th, 2013
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.33 KB | None | 0 0
  1. import sys
  2. from random import randint
  3. import math
  4. import time
  5.  
  6. class Engine(object):
  7.  
  8.     def __init__(self, scene_map):
  9.         self.scene_map = scene_map
  10.  
  11.     def play(self):
  12.         current_scene = self.scene_map.opening_scene()
  13.  
  14.         while True:
  15.             print "\n----------"
  16.             next_scene_name = current_scene.enter()
  17.             current_scene = self.scene_map.next_scene(next_scene_name)
  18.             self.setter = current_scene
  19.  
  20. class BattleSystem(object):
  21.  
  22.     def __init__(self, room):
  23.         self.room = room
  24.         print "\nYou entered a room and there are %i monsters!" % len(self.room)
  25.         time.sleep(2)
  26.         print "\nThey spotted you!"
  27.         time.sleep(2)
  28.         print "\nHere they come!"
  29.         time.sleep(1)
  30.            
  31.     def kill_monster(self):
  32.         self.room.pop(0)
  33.    
  34.     def first_attack_hint(self):
  35.         if self.mark in range(1, 16):
  36.             self.first_aim = "running really low to the ground!"
  37.         elif self.mark in range(86, 101):
  38.             self.first_aim = "suddenly jumped!"
  39.         elif self.mark in range(16, 33):
  40.             self.first_aim = "running hunched a bit!"
  41.         elif self.mark in range(33, 66):
  42.             self.first_aim = "running right at you!"
  43.         elif self.mark in range(66, 85):
  44.             self.first_aim = "running very upright!"
  45.  
  46.     def combat(self):
  47.         # Keeps track of turns - user attacks on odd numbers, Monster on even
  48.         turn = 1
  49.         # Not done/might scrap aim function
  50.         aim = 0
  51.         # Shows if guess was high or low relative to position of Monster
  52.         self.space = ""
  53.         # Gives clue on Monster's new position for the next turn
  54.         self.closeness = ""
  55.         # When shooting new monster, tells if Monster position is in lower, middle, or upper third
  56.         self.first_aim = ""
  57.         # Stores Max HP of each monster in order to print current HP v. starting HP
  58.         max_hp = self.room[0][0]
  59.         # This is the position of Monster, randomly given
  60.         self.mark = randint(1, 101)
  61.         # Shows how many steps Monster is away before they can begin attacking
  62.         self.steps = self.room[0][4]
  63.  
  64.         # Makes indication of first monster attacking since there's only 3 monsters per room
  65.         if len(self.room) == 3:
  66.             self.first_attack_hint()
  67.             print "\nThe first one is charging! It has a health of %i and %s" % (self.room[0][0], self.first_aim)
  68.         else:
  69.             self.first_attack_hint()
  70.             print "\nHere comes another! It has health of %i and %s" % (self.room[0][0], self.first_aim)
  71.        
  72.         #While the room has any Monster in it or if player has not been killed
  73.         while self.room and Player.health > 0:
  74.             # If you're not aiming, either aim or attack without aiming
  75.             if turn % 2 == 1 and aim == 0:
  76.                 self.guess = int(raw_input("\nEnter value 1 - 100 or value 0 to take aim: "))
  77.                 if self.guess == 0:
  78.                     print "\nYou've steadied your shot and the enemy is in your sights!"               
  79.                     aim = 1
  80.                 else:
  81.                     #attack with no aim
  82.                     self.no_aim()
  83.             # If you're aiming
  84.             elif turn % 2 == 1 and aim == 1:
  85.                 mark = randint(1, 20)
  86.                 self.guess = int(raw_input("\nEnter value 1 - 20: "))
  87.                 #Placeholder no_aim function, but might get rid of aim altogether
  88.                 self.no_aim(self.guess, self.room[0][0], self.mark)
  89.                 aim = 0
  90.                 print """
  91.                | Your HP: %s/100 |                      | Monster HP: %s/%s |
  92.                     """ % (Player.health, self.room[0][0], max_hp)
  93.             #If monster is killed
  94.             if self.room[0][0] <= 0:
  95.                 self.room[0][0] = 0
  96.                 print """
  97.                | Your HP: %s/100 |                      | Monster HP: %s/%s |
  98.                     """ % (Player.health, self.room[0][0], max_hp)
  99.                 print "\nYou killed the monster!"
  100.                 self.kill_monster()
  101.                 if self.room:
  102.                     self.combat()
  103.                 else:
  104.                     return
  105.             # Monster attacks on all even turns
  106.             if turn % 2 == 0:
  107.                 # Monster inflicts damage or kills player - see below
  108.                 self.steps_away()
  109.                 # Monster attacks
  110.                 self.defense()
  111.                 print """
  112.                | Your HP: %s/100 |                      | Monster HP: %s/%s |
  113.                     """ % (Player.health, self.room[0][0], max_hp)
  114.             #print self.mark
  115.             turn += 1
  116.    
  117.     # If a valid number is entered, proceed to attack
  118.     def no_aim(self):
  119.         if math.isnan(self.guess) or self.guess < 1 or self.guess > 100:
  120.             print "\nYou're a Master Hunter, not a dumbass."
  121.         else:
  122.             self.attack_wo_aim()
  123.    
  124.     # Assigns damage based on how close your guess is
  125.     def attack_wo_aim(self):
  126.         self.fatal_hit = randint(200, 250)
  127.         self.critical_hit = randint(75, 80)
  128.         self.hit = randint(30, 35)
  129.         self.damage = 0
  130.         self.distance()
  131.  
  132.         if self.guess == self.mark:
  133.             self.damage = self.fatal_hit
  134.             print """
  135.                 |-----------------|
  136.                 |                 |
  137.                 |                 |
  138.                 |  BOOM HEADSHOT! |
  139.                 |                 |
  140.                 |                 |
  141.                 |-----------------|
  142.                
  143.                 """
  144.             print "\nYou dealt a fatal blow of %s and killed the monster!" % self.fatal_hit
  145.  
  146.         elif self.guess in range(self.mark - 5, self.mark + 5):
  147.             self.damage = self.critical_hit
  148.             print """
  149.                 |-----------------------|
  150.                 |                       |
  151.                 |                       |
  152.                 |  CRITICAL HIT OF %s!  |
  153.                 |                       |
  154.                 |                       |
  155.                 |-----------------------|
  156.                
  157.                 """ % self.damage
  158.             print "\nYou dealt a critical blow of %s!" % self.critical_hit
  159.  
  160.         elif self.guess in range(self.mark - 10, self.mark + 10):
  161.             self.damage = self.hit
  162.             print """
  163.                 |-----------------------|
  164.                 |                       |
  165.                 |                       |
  166.                 |      HIT OF %s!       |
  167.                 |                       |
  168.                 |                       |
  169.                 |-----------------------|
  170.                
  171.                 """ % self.damage
  172.             print "\nYou dealt a blow of %s!" % self.hit
  173.  
  174.         else:
  175.             print """
  176.                 |-----------------|
  177.                 |                 |
  178.                 |                 |
  179.                 |   You missed!   |
  180.                 |                 |
  181.                 |                 |
  182.                 |-----------------|
  183.                
  184.                 """
  185.             print "\nYou missed! Your guess of %i was %s!" % (self.guess, self.space)
  186.        
  187.         self.room[0][0] -= self.damage
  188.    
  189.     #Tells how close guess is relative to Monster's previous location
  190.     def distance(self):
  191.         if self.guess > self.mark + 20:
  192.             self.space = "too high!"
  193.         elif self.guess > self.mark:
  194.             self.space = "a bit high!"
  195.         elif self.guess < self.mark - 20:
  196.             self.space = "too low!"
  197.         elif self.guess < self.mark:
  198.             self.space = "a bit low!"
  199.         else:
  200.             return
  201.  
  202.     #Tells where you should aim next
  203.     def relative(self):
  204.         if self.guess > self.mark + 15:
  205.             self.einstein = "Aim lower!"
  206.         elif self.guess > self.mark:
  207.             self.einstein = "Aim a bit lower!"
  208.         elif self.guess < self.mark - 15:
  209.             self.einstein = "Aim higher!"
  210.         elif self.guess < self.mark:
  211.             self.einstein = "Aim a bit higher!"
  212.         else:
  213.             return
  214.  
  215.     # Generates Monster'sn ext position
  216.     def defense(self):
  217.        
  218.         chance = randint(1, 10)
  219.  
  220.         if self.mark in range(1, 15):
  221.             chance = randint(6, 10)
  222.         elif self.mark in range(86, 100):
  223.             chance = randint(1, 5)
  224.  
  225.         if chance == 2 or chance == 3 and self.mark > 11:
  226.             self.mark -= randint(3, 10)
  227.             self.relative()
  228.             if self.mark in range(1, 15):
  229.                 self.closeness = "\nThe monster is running really low to the ground!"
  230.             else:
  231.                 self.closeness = "\nThe monster ducked a little! %s" % self.einstein
  232.         elif chance == 4 or chance == 5 and self.mark > 25:
  233.             self.mark -= randint(11, 25)
  234.             self.relative()
  235.             if self.mark in range(1,15):
  236.                 self.closeness = "\nThe monster is running really low to the ground!"
  237.             else:
  238.                 self.closeness = "\nThe monster ducked! %s" % self.einstein
  239.         elif chance == 6 or chance == 7 and self.mark < 89:
  240.             self.mark += randint(3, 10)
  241.             self.relative()
  242.             if self.mark in range(86, 101):
  243.                 self.closeness = "\nThe monster jumped!"
  244.             else:
  245.                 self.closeness = "\nThe monster raised its head a little! %s" % self.einstein
  246.         elif chance == 8 or chance == 9 and self.mark < 75:
  247.             self.mark += randint(11, 25)
  248.             self.relative()
  249.             if self.mark in range(86, 101):
  250.                 self.closeness = "\nThe monster jumped!"
  251.             else:
  252.                 self.closeness = "\nThe monster raised its head! %s" % self.einstein
  253.         elif chance == 1:
  254.             self.mark = randint(1, 15)
  255.             self.relative()
  256.             self.closeness = "\nThe monster is running really low to the ground!"
  257.         elif chance == 10:
  258.             self.mark = randint(86, 101)
  259.             self.relative()
  260.             self.closeness = "\nThe monster jumped!"
  261.        
  262.         if self.mark > 100 or self.mark < 0:
  263.             self.mark = 50
  264.             print "\nThe monster is dead center!"
  265.             return
  266.        
  267.         print self.closeness
  268.         if self.steps > 0:
  269.             print "\nThe monster is %i steps away" % self.steps
  270.             self.steps -= 1
  271.         else:
  272.             return
  273.  
  274.         #print chance
  275.  
  276.     def steps_away(self):
  277.  
  278.         if self.steps == 0:
  279.             self.monster_inflict = randint(self.room[0][2], self.room[0][3])
  280.             Player.health -= self.monster_inflict
  281.             print "\nThe monster attacked you and did %i damage!" % self.monster_inflict
  282.             if Player.health <= 0:
  283.                 Player.health = 0
  284.                 print "\nYou lose the game!\n"
  285.                 return
  286.  
  287.  
  288. #Player's health stored here
  289. class Player(object):
  290.  
  291.     health = 100
  292.  
  293. #All monsters stored here [HEALTH, (not relevant anymore), MINIMUM DAMAGE, MAXIMUM DAMAGE, STEPS AWAY,]
  294. class Monsters(object):
  295.    
  296.     room1 = [[100, 100, 7, 10, 4], [140, 100, 12, 15, 4], [200, 100, 15, 20, 4]]
  297.     room2 = [[100, 100, 7, 10, 3], [140, 100, 12, 15, 3], [200, 100, 15, 20, 3]]
  298.     room3 = [[100, 100, 7, 10, 3], [140, 100, 12, 15, 3], [200, 100, 25, 30, 2]]
  299.  
  300. #"credits"
  301. class Prologue(object):
  302.  
  303.     def enter(self):
  304.         time.sleep(0.5)
  305.         print "You are the greatest assassin never known."
  306.         time.sleep(2.5)
  307.         print "You arm yourself with just one weapon: an innocuous looking single-shot rifle"
  308.         time.sleep(3.0)
  309.         print "\n\nYou are Haven, the Master Hunter, and it's time to shoot some monsters down."
  310.  
  311.         time.sleep(2.5)
  312.         print """
  313.                 |--------------------------------------|
  314.                 |                                      |
  315.                 |                                      |
  316.                 |        MASTER HUNTER                 |
  317.                 |          a game by Brostoevski       |
  318.                 |                                      |
  319.                 |--------------------------------------|
  320.                
  321.                 """
  322.        
  323.         time.sleep(2)
  324.         game_decision = raw_input("Press ANY KEY to continue.")
  325.  
  326.         try:
  327.             input = raw_input
  328.         except NameError:
  329.             pass
  330.        
  331.         return 'opening_scene'
  332.  
  333. class OpeningScene(object):
  334.  
  335.     def enter(self):
  336.         print "You're standing outside of a large castle."
  337.         time.sleep(1.5)
  338.         print "You know the horror that exists within the walls"
  339.         time.sleep(1.5)
  340.         print "...and the likelihood that you won't come out alive..."
  341.         time.sleep(2)
  342.         print "...and the possibility for riches if you do."
  343.         time.sleep(2)
  344.         print "\n\nHAVEN: It has come."
  345.         time.sleep(2.5)
  346.  
  347.         return 'first_scene'
  348.  
  349. class FirstScene(object):
  350.  
  351.     def enter(self):
  352.         print "THE FIRST ROOM"
  353.         time.sleep(2)
  354.         print "Haven spots a group of other-worldly creatures."
  355.         time.sleep(1.5)
  356.         print "\n\nHAVEN: It's back to where you came from, demons!"
  357.         time.sleep(2.0)
  358.         first = BattleSystem(Monsters.room1)
  359.         first.combat()
  360.        
  361.         if Player.health <= 0:
  362.             return 'death'
  363.         else:
  364.             return 'second_scene'
  365.    
  366.    
  367. class SecondScene(object):
  368.    
  369.     def enter(self):
  370.         print "THE SECOND ROOM"
  371.         time.sleep(2)
  372.         second = BattleSystem(Monsters.room2)
  373.         second.combat()
  374.  
  375.         if Player.health <= 0:
  376.             return 'death'
  377.         else:
  378.             return 'third_scene'
  379.  
  380. class ThirdScene(object):
  381.  
  382.     def enter(self):
  383.         print "THE THIRD ROOM"
  384.         time.sleep(2)
  385.         third = BattleSystem(Monsters.room3)
  386.         third.combat()
  387.        
  388.         if Player.health <= 0:
  389.             return 'death'
  390.         else:
  391.             print "Quitting!"
  392.             exit()
  393.  
  394. class DeathScene(object):
  395.  
  396.     def enter(self):
  397.         print "Haven was devoured alive by the monsters."
  398.         self.death = raw_input("Type T to try again or Q to quit: ")
  399.  
  400.         if self.death == 'T' or self.death == 't':
  401.             Player.health += 100
  402.             return 'first_scene'
  403.         elif self.death == 'Q' or self.death == 'q':
  404.             exit()
  405.         else:
  406.             print "\nI'm not sure what that means"
  407.             self.enter()
  408.  
  409.  
  410. class Map(object):
  411.  
  412.     scenes = {
  413.         'prologue': Prologue(),
  414.         'opening_scene': OpeningScene(),
  415.         'first_scene': FirstScene(),
  416.         'second_scene': SecondScene(),
  417.         'third_scene': ThirdScene(),
  418.         'death': DeathScene()
  419.     }
  420.  
  421.     def __init__(self, start_scene):
  422.         self.start_scene = start_scene
  423.  
  424.     def next_scene(self, scene_name):
  425.         return Map.scenes.get(scene_name)
  426.  
  427.     def opening_scene(self):
  428.         return self.next_scene(self.start_scene)
  429.  
  430. #if you open with 2nd arg skip, skips long opening sequence
  431. if len(sys.argv) == 2 and sys.argv[1] == "skip":
  432.     a_map2 = Map('first_scene')
  433.     a_game2 = Engine(a_map2)
  434.     a_game2.play()
  435. else:
  436.     a_map = Map('prologue')
  437.     a_game = Engine(a_map)
  438.     a_game.play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement