-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombat.py
More file actions
91 lines (76 loc) · 2.56 KB
/
Copy pathcombat.py
File metadata and controls
91 lines (76 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import time
import random
import os
import player
import enemies
testVariable = True # Can't remember why this is here but I'll get back too it
messageDelay = 0.8 # Delay in seconds between messages. More comfortable and readable than everything appearing as the console calculates it.
playerHealth = 20 # Defines player base health
enemyHealth = 10 # Defines enemy health
# Defining the actions the player can take on his/her turn
def playerTurn():
# Makes player and enemy health into global variables
global enemyHealth
global playerHealth
# Prompts the player for action (i.e. 'attack', 'run')
playerInput = input("What do you do? ")
print(f"\nYou {playerInput} the Goblin.")
if playerInput.lower() == "attack":
time.sleep(messageDelay)
playerAttack = random.randint(0,4)
enemyHealth -= playerAttack
print(f"Goblin takes {playerAttack} damage!")
if enemyHealth <= 0:
time.sleep(messageDelay)
print("You killed the Goblin!")
time.sleep(messageDelay)
exit()
elif playerInput.lower() == "run":
print("You escaped!")
exit()
else:
time.sleep(messageDelay)
print("The Goblin just stares at you...")
time.sleep(2)
playerTurn()
# Defining enemy turn
def enemyTurn():
global enemyHealth
global playerHealth
enemyAttack = random.randint(0,5)
print(f"The goblin attacks you.")
time.sleep(messageDelay)
print(f"You took {enemyAttack} damage!")
playerHealth -= enemyAttack
# Clears screen making for a more readable user experience; is also cross-platform, using a different command depending on the operating system
def newTurn():
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
# Central gameplay loop
def main():
# Step 1: Prompt the player to press ENTER when they are ready to play
input("Press ENTER to Start Combat Simulation...")
#
newTurn()
print("A Goblin blocks your path!")
while playerHealth > 0 and enemyHealth > 0:
print(f"\nYOU: {playerHealth} | ENEMY: {enemyHealth}")
playerTurn()
time.sleep(messageDelay)
enemyTurn()
time.sleep(messageDelay)
newTurn()
main()
'''
TO-DO LIST
- Add different physical attack types depending on weapon a la Persona (Strike, Slash and Pierce)
- Multiple enemies
- make it into an actual dungeon where you proceed instead of it just being a single battle
- spells
- elemental weaknesses
- loot
- weapons
- character and enemy attributes
'''