Skip to content

Commit

Permalink
feat(UI-UX): removed kick button for local and ai player
Browse files Browse the repository at this point in the history
  • Loading branch information
HOOK-Hawkins committed Mar 17, 2024
1 parent 4acb72f commit e42fe0b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions AI/ai_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def run_strategy(self):
thread = Thread(target=self._strategy.thread_entry, daemon=True)
thread.start()
return thread

def get_uuid(self):
return self._strategy.get_uuid()

if __name__ == "__main__":
weak_ai = ai_strategy.WeakAIStrategy()
Expand Down
4 changes: 4 additions & 0 deletions AI/ai_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import random
import logging
import copy
from uuid import UUID

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
Expand All @@ -29,6 +30,9 @@ def post_init(self):
#needs to be called by inheriting classes at the end of their __init__ function
super().__init__(self._ip, self._port, self._player)

def get_uuid(self):
return UUID(self._current_uuid)

def thread_entry(self):
asyncio.run(self.run())

Expand Down
14 changes: 10 additions & 4 deletions UI/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, master, *args, opponent=player_type.unknown, local_players, *
self._display_widgets()
self.playerlist = []
self.local_players = local_players
self.ai_players = []
#self.bind('<<lobby/status>>', self._update_lobby)
#self.bind('<<game/start>>', self._start_game)
self.master.network_events['lobby/status'] = self._update_lobby
Expand All @@ -32,6 +33,7 @@ def __init__(self, master, *args, opponent=player_type.unknown, local_players, *
server_thread(self.master.players[self.master.player])
if opponent in [player_type.ai_strong, player_type.ai_weak]:
ai_context = AIContext(AdvancedAIStrategy() if opponent == player_type.ai_strong else WeakAIStrategy())
self.ai_players.append(ai_context.get_uuid())
self.master.ai = ai_context.run_strategy()

def _create_widgets(self, opponent):
Expand Down Expand Up @@ -65,17 +67,21 @@ def _update_lobby(self, queue):
self.playerlist = []
for player in queue['player']:
rdy = '\u2611' if player.ready else ''
self.playerlist.append([tk.Label(self, text=rdy + ' ' + player.display_name),
tk.Button(self, text='Kick', command=lambda uuid=player.uuid, *args: list(self.master.out_queue.values())[0].put({'message_type': 'lobby/kick', 'args' : {'player_to_kick': uuid}}))])
buffer = []
buffer.append(tk.Label(self, text=rdy + ' ' + player.display_name))
print(player.uuid, self.local_players + self.ai_players)
if(player.uuid not in (self.local_players + self.ai_players)):
buffer.append(tk.Button(self, text='Kick', command=lambda uuid=player.uuid, *args: list(self.master.out_queue.values())[0].put({'message_type': 'lobby/kick', 'args' : {'player_to_kick': uuid}})))
self.playerlist.append(buffer)
if(str(player.uuid) == str(self.master.players[self.master.player].uuid)):
self.ready = player.ready
if(player.ready):
self.btnRdy.config(text="not Ready")
else:
self.btnRdy.config(text="Ready")
for i, player in enumerate(self.playerlist):
player[0].grid(sticky=tk.E+tk.W+tk.N+tk.S, column=2, row=4+i)
player[1].grid(sticky=tk.E+tk.W+tk.N+tk.S, column=3, row=4+i)
for j, object in enumerate(player):
object.grid(sticky=tk.E+tk.W+tk.N+tk.S, column=2+j, row=4+i)


def _start_game(self, queue):
Expand Down

0 comments on commit e42fe0b

Please sign in to comment.