Started work on turn based systems
This commit is contained in:
@ -5,3 +5,5 @@ from .anim import AnimatedObject
|
|||||||
from .events import AnimStart
|
from .events import AnimStart
|
||||||
from .events import AnimFinish
|
from .events import AnimFinish
|
||||||
from .events import Timeout
|
from .events import Timeout
|
||||||
|
from .turns import BaseTurnHandler
|
||||||
|
from .turns import RoundTable
|
||||||
|
|||||||
54
src/gameUtils/turns.py
Normal file
54
src/gameUtils/turns.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
class BaseTurnHandler:
|
||||||
|
def __init__(self, playersManager):
|
||||||
|
"""
|
||||||
|
The base turn handler metaclass, used to create round
|
||||||
|
handlers such as round table.
|
||||||
|
"""
|
||||||
|
self._pm = playersManager
|
||||||
|
# The current turn number (0 based)
|
||||||
|
self.turn = 0
|
||||||
|
# The maximum number of turns
|
||||||
|
self.turns = len(self._pm)
|
||||||
|
# The current round number (0 based)
|
||||||
|
self.round = 0
|
||||||
|
# Which players are playing in this turn
|
||||||
|
self.playing = []
|
||||||
|
|
||||||
|
def next(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
class RoundTable(BaseTurnHandler):
|
||||||
|
"""
|
||||||
|
A simple "round table" round system.
|
||||||
|
"""
|
||||||
|
# TODO: Add some kind of implementation with NoPE
|
||||||
|
# to determain if we actually need to re-assign PDOs.
|
||||||
|
def __init__(self, teamSize: int, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
if teamSize > len(self._pm):
|
||||||
|
raise Exception('Too little players for specified team size.') # TODO: Custom exception
|
||||||
|
|
||||||
|
self.temaSize = teamSize
|
||||||
|
self.turns //= self.temaSize
|
||||||
|
|
||||||
|
def next(self):
|
||||||
|
"""
|
||||||
|
Oh god I hate it.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.turn += 1
|
||||||
|
if self.turn >= self.turns:
|
||||||
|
self.turn -= self.turns
|
||||||
|
self.round += 1
|
||||||
|
|
||||||
|
self.playing = []
|
||||||
|
playerNames = self._pm.keys()
|
||||||
|
|
||||||
|
for i in range(self.temaSize):
|
||||||
|
self.playing.append(self._pm[playerNames[(i+self.temaSize)%len(playerNames)]])
|
||||||
|
|
||||||
|
return self.playing
|
||||||
Reference in New Issue
Block a user