Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions core/Characters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
class Player():
def __init__(self, col, rows, engine):
self.id=random.randint(10,100)
self.pos=[random.randint(0,5),random.randint(0,4)]
self.pos=[random.randint(0,4),random.randint(0,3)]
self.Engine=engine
self.selected=None
self.img='P'
self.action_range=1 # it means center+1, so 3*3 grid

def move(self, pos):
newx=int(pos.split(',')[0]); x=self.pos[0]
Expand All @@ -41,22 +42,41 @@ def move(self, pos):
if not bot.id==self.id:
print(css.FAIL+'[ERR]'+css.ENDC+' ID:',bot.id,'already in',newx,',',newy,'!')
return
self.pos=[newx, newy]
if newx<=self.pos[0]+self.action_range and newx>=self.pos[0]-self.action_range:
if newy<=self.pos[1]+self.action_range and newy>=self.pos[1]-self.action_range:
self.pos=[newx, newy]
else:
print(errs.ActionRangeError(pos=[newx,newy])); return
else:
print(errs.ActionRangeError(pos=[newx,newy])); return
Comment on lines +45 to +51

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action range check

else:
if skip=='y':
for bot in self.Engine.robots:
if bot.pos==[newx, y]:
if not bot.id==self.id:
print(css.FAIL+'[ERR]'+css.ENDC+' ID:',bot.id,'already in',newx,',',newy,'!')
return
self.pos=[newx, y]
return
# newpos=[newx, y]
if newx<=self.pos[0]+self.action_range and newx>=self.pos[0]-self.action_range:
if y<=self.pos[1]+self.action_range and y>=self.pos[1]-self.action_range:
self.pos=[newx, y]
else:
print(errs.ActionRangeError(pos=[newx, y])); return
else:
print(errs.ActionRangeError(pos=[newx, y])); return
else:
for bot in self.Engine.robots:
if bot.pos==[x, newy]:
if not bot.id==self.id:
print(css.FAIL+'[ERR]'+css.ENDC+' ID:',bot.id,'already in',newx,',',newy,'!')
return
self.pos=[x, newy]
if x<=self.pos[0]+self.action_range and x>=self.pos[0]-self.action_range:
if newy<=self.pos[1]+self.action_range and newy>=self.pos[1]-self.action_range:
self.pos=[x, newy]
else:
print(errs.ActionRangeError(pos=[x,newy])); return
else:
print(errs.ActionRangeError(pos=[x,newy])); return

class Kernel():
def __init__(self):
Expand Down
Binary file modified core/Characters/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
13 changes: 12 additions & 1 deletion core/Errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ def __str__(self):

class HackError(Exception):
def __init__(self, txt='', *args, **kwargs):
print('\033[91m[ERR]\033[0m Unable to hack.'+txt)
print('\033[91m[ERR]\033[0m Unable to hack.'+txt)

class ActionRangeError(Exception):
def __init__(self, b=None, pos=[], *a, **k):
super().__init__(*a, **k)
self.b=b
self.pos=pos
def __str__(self):
if self.b:
return "[ERR] Object w/ id: "+repr(self.b.id)+" is too far."
else:
return "[ERR] "+repr(self.pos)+" is too far."
Binary file modified core/Errors/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
47 changes: 42 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

class Engine():
def __init__(self, col=4, rows=5, enems=3):
def __init__(self, col=4, rows=5, enems=1):
self.gamepoints=0
# map setup
self.columns=col
Expand All @@ -44,6 +44,8 @@ def __init__(self, col=4, rows=5, enems=3):

def run(self):
while True:
if not len(self.robots) or (len(self.robots)==1 and self.robots[0]==self.player):
self.win()
self.update_map()
while self.inbshell:
try:
Expand All @@ -65,7 +67,7 @@ def run(self):
self.player.selected.parser(input(css.OKGREEN+'[BOT]'+css.ENDC+css.OKCYAN+'[SCORE:{}]'.format(self.gamepoints)+css.ENDC+' -state:{}- >> '.format(self.player.selected.state)))
else:
self.show_map()
self.parser(input(css.OKGREEN+'[MAP]'+css.ENDC+css.OKCYAN+'[SCORE:{}]'.format(self.gamepoints)+css.ENDC)) # map parser
self.parser(input(css.OKGREEN+'[MAP]'+css.ENDC+css.OKCYAN+'[SCORE:{}]'.format(self.gamepoints)+css.ENDC+' >> ')) # map parser
except errs.ParamError as e:
print(str(e))
except errs.SameObjError as e:
Expand Down Expand Up @@ -113,19 +115,33 @@ def parser(self, x):
if bot==self.player:
raise errs.SameObjError(bot, self.player)
return
self.player.selected=bot
if int(bot.pos[0])>=(int(self.player.pos[0])-self.player.action_range) and int(bot.pos[0])<=(int(self.player.pos[0])+self.player.action_range):
if int(bot.pos[1])>=(int(self.player.pos[1])-self.player.action_range) and int(bot.pos[1])<=(int(self.player.pos[1])+self.player.action_range):
self.player.selected=bot
else:
raise errs.ActionRangeError(bot)
else:
raise errs.ActionRangeError(bot)
elif '-pos' in params:
v=params[params.index('-pos')+1]
for bot in self.robots:
if bot.pos==[int(i) for i in v.split(',')]:
self.player.selected=bot
if int(bot.pos[0])>=(int(self.player.pos[0])-self.player.action_range) and int(bot.pos[0])<=(int(self.player.pos[0])+self.player.action_range):
if int(bot.pos[1])>=(int(self.player.pos[1])-self.player.action_range) and int(bot.pos[1])<=(int(self.player.pos[1])+self.player.action_range):
self.player.selected=bot
else:
raise errs.ActionRangeError(bot)
else:
raise errs.ActionRangeError(bot)
else:
raise errs.ParamError(params)

# MOVE
elif cmd=='move':
self.player.move(params[0])
elif cmd=='bye':

# EXIT && BYE
elif cmd in ['bye', 'exit']:
print('[?] Are you sure?')
c=getch()
if c in ['y','s']:
Expand All @@ -139,6 +155,27 @@ def parser(self, x):
else:
raise errs.CommandNotFoundError(cmd)

def win(self):
self.gamepoints+=10
cls_()
titles=[
'__ _____ _ _ __ _____ _ _ \n\\ \\ / / _ \\| | | | \\ \\ / /_ _| \\ | |\n \\ V / | | | | | | \\ \\ /\\ / / | || \\| |\n | || |_| | |_| | \\ V V / | || |\\ |\n |_| \\___/ \\___/ \\_/\\_/ |___|_| \\_|\n \n',
' \n# # # # # # # ### ### \n# # # # # # # # # # # \n # # # # # ### # # # \n # # # # # ### # # # \n # # ### # # ### # # \n'
]
# TODO dump data
print(css.OKGREEN+random.choice(titles)+css.ENDC)
while True:
print('Do you want to start a new game? (y\\n)')
r=getch()
if r.lower()=='y':
main()
elif r.lower()=='n':
print('Exiting...')
time.sleep(1); exit(code=0)
else:
print('[ERR] Invalid Key',r,'.')
continue

def update_map(self):
for y in range(len(self.map)):
for x in range(len(self.map[y])):
Expand Down