mastosnake/mastosnake.py

42 lines
1.4 KiB
Python
Raw Normal View History

2021-05-24 12:03:29 -05:00
class Mastosnake:
2021-05-24 22:51:46 -05:00
def __init__(self, game):
2021-05-24 12:03:29 -05:00
self.game = game
def returnStatus(self):
statusstring = ""
2021-05-24 22:51:46 -05:00
for j in range(self.game.boarddimensions[0] - 1, -1, -1):
2021-05-24 12:03:29 -05:00
for i in range(0, self.game.boarddimensions[1]):
if (i, j) in self.game.snake:
2021-05-24 22:51:46 -05:00
if (i, j) == self.game.snake[0]:
statusstring += ''
2021-05-24 12:03:29 -05:00
else:
2021-05-24 22:51:46 -05:00
statusstring += ''
elif (i, j) == self.game.apple:
statusstring += '🍎'
2021-05-24 12:03:29 -05:00
else:
2021-05-24 22:51:46 -05:00
statusstring += ''
statusstring += '\n'
statusstring += '\n'
statusstring += self.game.gamestate
statusstring += ' | score: '
statusstring += str(len(self.game.snake))
2021-05-24 12:03:29 -05:00
dataskel = {
'status': statusstring,
'poll': {
'options': [],
2021-05-24 22:51:46 -05:00
'expires_in': 100000,
2021-05-24 12:03:29 -05:00
'multiple': False
}
}
for _, _, i in self.game.moveset():
dataskel['poll']['options'].append(i)
return dataskel
2021-05-24 22:51:46 -05:00
def updateState(self, data):
tmp = []
for i in data['options']:
tmp.append((i['title'], i['votes_count']))
tmp2 = (0, -1)
for i in tmp:
if i[1] > tmp2[1]:
tmp2 = i
self.game.move(tmp2[0])