Advertisement
Taximaniac

MonsterKiller Game

Jan 28th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.77 KB | None | 0 0
  1. # import only system from os
  2. from os import system, name
  3.  
  4. from time import sleep
  5.  
  6. from monster import Monster
  7. from player import Player
  8. from random import randint
  9.  
  10. # define our clear function
  11. def clear_screen():
  12.     # for windows
  13.     if name == 'nt':
  14.         _ = system('cls')
  15.  
  16.     # for mac and linux(here, os.name is 'posix')
  17.     else:
  18.         _ = system('clear')
  19.  
  20.  
  21. is_running = True
  22.  
  23. # Get a random heal point for the player when we start game
  24. heal = randint(0, 10)
  25.  
  26. # make the player and monster objects
  27. player = Player('Player', 'Christian', 1, 10, heal)
  28. monster = Monster('Monster', 'Gorgar', 1, 10)
  29.  
  30. # this function is used to display healt within different places in the game
  31. def display_health():
  32.     print(f"The {player.type} -> {player.name}'s healt is: {player.health}'")
  33.     print(f"The {monster.type} -> {monster.name}'s healt is: {monster.health}'")
  34.  
  35.    
  36.    
  37.  
  38. while is_running:
  39.     sleep(0.5)
  40.     clear_screen()
  41.     #Print header
  42.     print('=' * 44)
  43.     print('|  Monster Killer - Version 0.0.0.1 Alpha  |')
  44.     print('=' * 44)
  45.  
  46.     # print menu
  47.     print('-' * 44)
  48.     print('Please select action')
  49.     print('-' * 44)
  50.     print('1) Attack')
  51.     print('2) Heal')
  52.     print('3) Quit')
  53.     print('-' * 44)
  54.    
  55.     # Display Initial Health
  56.     display_health()
  57.    
  58.     # display and get player's choice
  59.     print('-' * 44)
  60.     sleep(0.2)
  61.     player_choice = input('Enter your choice: ')
  62.  
  63.     # Check if the string player_choice is a int
  64.     if player_choice.isdigit():
  65.         # make the selection of choice made by player
  66.         if int(player_choice) == 1:
  67.             clear_screen()
  68.             # Player attacks monster
  69.             player_attack_points = player.attack()
  70.             print(f"Player Attacks The Monster and apply {player_attack_points} points of damage!")
  71.             monster.apply_damage(player_attack_points)
  72.  
  73.             # monster attacks player back
  74.             monster_attack_points = monster.attack()
  75.             print(f"Monster Attacks Player and apply {monster_attack_points} points of damage")
  76.             player.apply_damage(monster_attack_points)
  77.  
  78.             display_health()
  79.             sleep(5)
  80.         elif int(player_choice) == 2:
  81.             clear_screen()
  82.             # if player health is lower than 100 - heal points then allow to heal
  83.             if player.health <= (100 - player.heal):
  84.                 # let player heal with given heal points in the player object
  85.                 old_health = player.health
  86.                 player.apply_healing()
  87.                 new_health = player.health
  88.                 heal_points = new_health - old_health
  89.                 print(f"Player Heal Itself with {heal_points} healpoints\nFrom {old_health} Health Points to {new_health} Health Points")
  90.                 display_health()
  91.                 sleep(3)
  92.             else:
  93.                 clear_screen()
  94.                 print("Player can't heal right now.\nPlease try again when player is more damaged!")
  95.                 sleep(3)
  96.  
  97.             # after player try to heal, monster will attack
  98.             # monster attacks player back
  99.             monster_attack_points = monster.attack()
  100.             print(f"Monster Attacks Player and apply {monster_attack_points} points of damage")
  101.             player.apply_damage(monster_attack_points)
  102.  
  103.             display_health()
  104.             sleep(3)
  105.         elif int(player_choice) == 3:
  106.             clear_screen()
  107.             print('Player want to quit, quitting game...')
  108.             sleep(0.5)
  109.             is_running = False
  110.         else:
  111.             clear_screen()
  112.             print('Invalid Input Entry!')
  113.             sleep(0.5)
  114.     else:
  115.         clear_screen()
  116.         print('Oops, only digits are allowed as entry!')
  117.         sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement