diff options
Diffstat (limited to 'explore.py')
-rw-r--r-- | explore.py | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/explore.py b/explore.py new file mode 100644 index 0000000..fa8239c --- /dev/null +++ b/explore.py @@ -0,0 +1,97 @@ +import isrock +import isportal +from math import floor +from curses import KEY_LEFT as left, KEY_RIGHT as right, KEY_DOWN as down, KEY_UP as up +import inv + +def splitlist(liststr, strsplit): + newlist = [] + sublist = [] + for item in liststr: + if item == strsplit: + newlist.append(sublist) + sublist = [] + else: + sublist.append(item) + newlist.append(sublist) + return newlist + +class Explore: + def __init__(self, density, x=0, y=0): + self.density = density + self.x = x + self.y = y + + def get_area(self, dim): + out = '' + for y in range(dim[0]): + y += self.y + for x in range(floor(dim[1]/2)): + x += self.x + pos = isrock.isrock(self.density, (x,y), typereq=True) + if not pos[0]: + out += ' ' + elif pos[1] == 'n': + out += '*' + else: + out += '\\' + out += ' ' + out = out[:-1] + out += '\n' + return out[:-1] + + def displace(self, dim, dis): + self.move((self.x + dim[0], self.y + dim[1]), dis) + + def move(self, dim, dis): + self.x, self.y = dim[0], dim[1] + dim = (dim[0]+dis[1], dim[1]+dis[0]) + if isportal.isportal(dim): + dim = isportal.link(dim) + self.x, self.y = dim[0]-dis[1], dim[1]-dis[0] + + def interpretkey(self, key): + return {up:(0,-1), left:(-1,0), down:(0,1), right:(1,0)}[key] + + def rockmod(self, dim, state): + dim = (self.x + dim[1], self.y + dim[0]) + if state != isrock.isrock(self.density, dim): + if state and inv.quantity <= 0: + return + isrock.modrock(dim, state) + inv.quantity += -1 if state else 1 + + def getinv(self): + return inv.quantity + + def load(self, file): + try: + f = open('./worlds/'+str(file)[2:-1],'r') + data = [line[:-1] for line in f.readlines()] #removes newlines + f.close() + except: + return "File Doesn't Exist" + loc = [int(num) for num in data[0].split(' ')] + self.x, self.y, inv.quantity = loc[0], loc[1], loc[2] + data = splitlist(data[1:], '______') + isrock.load(data[0]) + isportal.load(data[1]) + + def save(self, file): + f = open('./worlds/'+str(file)[2:-1],'w') + data = str(self.x) + ' ' + str(self.y) + ' ' + str(inv.quantity) + '\n' + data += isrock.save() + data += '______\n' + isportal.save() + f.write(data) + f.close() + + def setportal(self, dim): + dim = (dim[1]+self.x, dim[0]+self.y) + if not isrock.isrock(self.density, dim) and inv.quantity >= 10: + inv.quantity -= 10 + isrock.modrock(dim, True, 'p') + isportal.modportal(dim) + elif isrock.isrock(self.density, dim, typereq=True)[1] == 'p': + inv.quantity += 10 + isrock.modrock(dim, False) + isportal.modportal(dim) |