forked from TinkerYpsi/WS_IntroPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot0.py
67 lines (58 loc) · 2.55 KB
/
plot0.py
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
import matplotlib.pyplot as plt
import random
class Player:
def __init__(self, name, health, attacks, move_strengths):
self.name = name
self.health = health
self.attacks = attacks
self.attack_strengths = move_strengths
self.alive = True
def lose_battle(self, health_penalty):
if self.health - health_penalty <= 0 and self.alive:
self.alive = False
self.health = 0
else:
self.health -= health_penalty
attacks = ['lightsaber throw']
attack_strengths = [15]
luke = Player("Luke Skywalker", 100, attacks, attack_strengths)
evil_attacks = ['electrocute']
evil_attack_strengths = [20]
vader = Player("Darth Vader", 100, evil_attacks, evil_attack_strengths)
while luke.alive and vader.alive:
row = ""
attack = random.randint(0, 1) # random number that is 0 or 1
if attack == 0: # Luke plays Vader
current_attack = luke.attacks[0]
current_strength = luke.attack_strengths[0]
bonus = 20
die_roll = random.randint(1, 20)
# Luke wins if he rolls greater than a 5
if die_roll > 5:
# make's winner's successful move more powerful next turn
luke.attack_strengths[0] += bonus
vader.lose_battle(current_strength)
print(luke.name + " attacked " + vader.name + " using " + current_attack + "!")
print(vader.name + " lost " + str(current_strength) + " health!")
print(luke.name + "'s " + current_attack + " just gained " + str(bonus) + " power!")
else:
print(vader.name + " dodged " + luke.name + "'s " + current_attack + " attack!")
health_bonus = 7
if vader.health + health_bonus > 100:
vader.health = 100
print(vader.name + " has healed to 100 health!")
else:
vader.health += (health_bonus * 2)
print(vader.name + " has gained " + str(health_bonus * 2) + " health!")
if luke.health + health_bonus > 100:
luke.health = 100
print(luke.name + " has healed to 100 health!")
else:
luke.health += health_bonus
print(luke.name + " has gained " + str(health_bonus) + " health!")
else:
print("Darth Vader has dodged!")
if luke.alive and not vader.alive:
print("Luke Skywalker has defeated Lord Vader!")
elif vader.alive and not luke.alive:
print("Darth Vader has defeated Luke Skywalker!")