-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_obj.py
More file actions
103 lines (80 loc) · 3.41 KB
/
map_obj.py
File metadata and controls
103 lines (80 loc) · 3.41 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
92
93
94
95
96
97
98
99
100
101
102
103
import curses as c
from random import random, choice as rand_choice
from cg_battle import CGBattle
from funcs import print_text
from trainer_sprites import player_battle_sprite
class Map:
def __init__(self, height, width, obj):
self.height = height
self.width = width
self.obj = obj
self.pd = c.newpad(height, width)
class MapObject:
def __init__(self, start_y, start_x, string_shown, block=True, **door):
self.start_y, self.start_x = start_y, start_x
self.string_shown = string_shown
self.block = block
self.door = door
class Interactive(MapObject):
overworld_text = []
actions = {} # {after_text_id: func}
def __init__(self, start_y, start_x, string_shown, block=True, detect=None):
super().__init__(start_y, start_x, string_shown, block)
self.detect = detect
def on_interacted_with(self, player, graphics, text, choice):
for i, txt in enumerate(self.overworld_text):
print_text(text, txt, -1)
if i in self.actions.keys():
self.actions[i](player, graphics, text, choice)
text.erase()
choice.erase()
class GrassPatch(Interactive):
"""
A patch of "grass" that spawns wild CGs.
The `spawn` list holds the spawning info:
- Each item is a tuple with 2 elements.
- The first element is the spawn rate of a given CG
*plus the element before itself*; this is for more elegant code.
- The second element is the name of this CG.
"""
def __init__(self, start_y, start_x, height, width, spawn: list, levels: list):
super().__init__(start_y, start_x, ('/' * width + '\n') * height, False)
self.spawn = spawn
self.levels = levels
def on_interacted_with(self, player, graphics, text, choice):
rand = random()
for chance, species in self.spawn:
if rand < chance:
import creagrams as cg # noqa (used in eval(), PyCharm doesn't know that)
CGBattle(player, eval("cg.%s(text, %d)"
% (species, rand_choice(self.levels))),
graphics, text, choice).start_battle()
break
class Trainer(MapObject):
def __init__(self, pos, name, team: list, sprite, repr_char=None):
super().__init__(pos[0], pos[1], repr_char if repr_char else name[0])
self.name = name
self.team = team
self.sprite = sprite
class Player(Trainer):
def __init__(self, name, team, items: dict):
super().__init__((10, 10), name, team, player_battle_sprite)
self.items = items
class Opponent(Trainer, Interactive):
def __init__(self, pos, name, start_text, lose_text, team: list, sprite, repr_char=None, detect=None):
super().__init__(pos, name, team, sprite, repr_char)
self.detect = detect
self.start_text = start_text
self.lose_text = lose_text
self.overworld_text = [start_text]
self.actions = {0: self.start_battle_with_self}
self.battled = False
def start_battle_with_self(self, player, graphics, text, choice):
if not self.battled:
CGBattle(player, self, graphics, text, choice, False).start_battle()
self.battled = True
self.overworld_text = [self.lose_text]
self.detect = None
class PlayerOnMap(MapObject):
def __init__(self):
super().__init__(10, 10, 'p')