-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
52 lines (44 loc) · 1.36 KB
/
player.py
File metadata and controls
52 lines (44 loc) · 1.36 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
#!/usr/bin/env python3
import graphics
class Player:
def __init__(self, x, y):
self.x = x
self.y = y
self.health = 100
self.max_health = 100
self.attack = 10
self.defense = 5
self.gold = 0
self.level = 1
self.exp = 0
self.exp_to_level = 100
def move(self, dx, dy, dungeon):
new_x = self.x + dx
new_y = self.y + dy
# Check if the move is valid
if 0 <= new_x < graphics.MAP_WIDTH and 0 <= new_y < graphics.MAP_HEIGHT:
if dungeon[new_y][new_x] != 1: # 1 represents walls
self.x = new_x
self.y = new_y
return True
return False
def take_damage(self, damage):
actual_damage = max(1, damage - self.defense)
self.health -= actual_damage
return actual_damage
def heal(self, amount):
old_health = self.health
self.health = min(self.max_health, self.health + amount)
return self.health - old_health
def gain_exp(self, amount):
self.exp += amount
if self.exp >= self.exp_to_level:
self.level_up()
def level_up(self):
self.level += 1
self.exp = 0
self.exp_to_level += 50
self.max_health += 20
self.health = self.max_health
self.attack += 3
self.defense += 2