Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import only system from os
- from os import system, name
- from time import sleep
- from monster import Monster
- from player import Player
- from random import randint
- # define our clear function
- def clear_screen():
- # for windows
- if name == 'nt':
- _ = system('cls')
- # for mac and linux(here, os.name is 'posix')
- else:
- _ = system('clear')
- is_running = True
- # Get a random heal point for the player when we start game
- heal = randint(0, 10)
- # make the player and monster objects
- player = Player('Player', 'Christian', 1, 10, heal)
- monster = Monster('Monster', 'Gorgar', 1, 10)
- # this function is used to display healt within different places in the game
- def display_health():
- print(f"The {player.type} -> {player.name}'s healt is: {player.health}'")
- print(f"The {monster.type} -> {monster.name}'s healt is: {monster.health}'")
- while is_running:
- sleep(0.5)
- clear_screen()
- #Print header
- print('=' * 44)
- print('| Monster Killer - Version 0.0.0.1 Alpha |')
- print('=' * 44)
- # print menu
- print('-' * 44)
- print('Please select action')
- print('-' * 44)
- print('1) Attack')
- print('2) Heal')
- print('3) Quit')
- print('-' * 44)
- # Display Initial Health
- display_health()
- # display and get player's choice
- print('-' * 44)
- sleep(0.2)
- player_choice = input('Enter your choice: ')
- # Check if the string player_choice is a int
- if player_choice.isdigit():
- # make the selection of choice made by player
- if int(player_choice) == 1:
- clear_screen()
- # Player attacks monster
- player_attack_points = player.attack()
- print(f"Player Attacks The Monster and apply {player_attack_points} points of damage!")
- monster.apply_damage(player_attack_points)
- # monster attacks player back
- monster_attack_points = monster.attack()
- print(f"Monster Attacks Player and apply {monster_attack_points} points of damage")
- player.apply_damage(monster_attack_points)
- display_health()
- sleep(5)
- elif int(player_choice) == 2:
- clear_screen()
- # if player health is lower than 100 - heal points then allow to heal
- if player.health <= (100 - player.heal):
- # let player heal with given heal points in the player object
- old_health = player.health
- player.apply_healing()
- new_health = player.health
- heal_points = new_health - old_health
- print(f"Player Heal Itself with {heal_points} healpoints\nFrom {old_health} Health Points to {new_health} Health Points")
- display_health()
- sleep(3)
- else:
- clear_screen()
- print("Player can't heal right now.\nPlease try again when player is more damaged!")
- sleep(3)
- # after player try to heal, monster will attack
- # monster attacks player back
- monster_attack_points = monster.attack()
- print(f"Monster Attacks Player and apply {monster_attack_points} points of damage")
- player.apply_damage(monster_attack_points)
- display_health()
- sleep(3)
- elif int(player_choice) == 3:
- clear_screen()
- print('Player want to quit, quitting game...')
- sleep(0.5)
- is_running = False
- else:
- clear_screen()
- print('Invalid Input Entry!')
- sleep(0.5)
- else:
- clear_screen()
- print('Oops, only digits are allowed as entry!')
- sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement