Compare commits

...

10 Commits

Author SHA1 Message Date
28f9c01f14 Added more notes / todos 2025-06-23 22:20:36 +01:00
24d6addc24 Added note 2025-06-23 21:18:59 +01:00
c0ebfa42b7 Added more TODOs for me (: 2025-06-23 20:37:52 +01:00
44696a0ac3 Added TODO for me to deal with later 2025-06-23 20:10:55 +01:00
1686e53b28 Did more unforgivable sins 2025-06-23 14:45:29 +01:00
132cfab990 Started work on turn based systems 2025-06-23 12:30:39 +01:00
c2db8b386e Added TODO 2025-06-22 20:01:19 +01:00
265322f58b My bad team, this one will work for sure 2025-06-22 18:09:09 +01:00
5dbd9211de Added awaitingTimeout function (not tested, good luck team) 2025-06-22 18:00:42 +01:00
2a0def7fa6 Added NoPELib integration 2025-06-22 17:36:43 +01:00
4 changed files with 100 additions and 8 deletions

2
TODO.md Normal file
View File

@ -0,0 +1,2 @@
# TODO
- Add turn / round based systems

View File

@ -4,4 +4,6 @@ from .anim import AnimationHandler
from .anim import AnimatedObject 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

View File

@ -1,5 +1,6 @@
from .events import Timeout from .events import Timeout
from .anim import AnimatedObject from .anim import AnimatedObject
import NoPELib
import tomllib import tomllib
import time import time
@ -12,15 +13,15 @@ class Game:
surface (pygame.Surface): The surface the game devs draw on. surface (pygame.Surface): The surface the game devs draw on.
""" """
self.surf = surface
self.size = self.surf.size
self.pm = None
# Holds all the timeouts that haven't been fired yet
self._timeouts = []
with open('./game.toml', 'r') as f: with open('./game.toml', 'r') as f:
self.cfg = tomllib.loads(f.read()) self.cfg = tomllib.loads(f.read())
self.surf = surface
self.size = self.surf.size
self.pm = NoPELib.PlayersManager(self.cfg['name'], playersPath='../players.json')
# Holds all the timeouts that haven't been fired yet
self._timeouts = []
def update(self): def update(self):
""" """
Updates some core things in the background. Updates some core things in the background.
@ -59,4 +60,22 @@ class Game:
to wait before firing. to wait before firing.
""" """
self._timeouts.append(Timeout(id, time.perf_counter()+delay)) self._timeouts.append(Timeout(id, time.perf_counter()+delay))
def awaitingTimeout(self, id: str):
"""
Tells you if a timeout ID is on the timeout stack.
Args:
id (str): The timeout ID.
Returns:
bool: True if there is a timeout with that ID
ID on the stack, False otherwise.
"""
return any([timeout.timeoutID == id for timeout in self._timeouts])
# TODO: Add popup method
# TODO: add punish(player, intensity)

69
src/gameUtils/turns.py Normal file
View File

@ -0,0 +1,69 @@
# TODO: Add a variable for the game developers to see if pain is "avaialbe",
# I.E. has the shocker been passed to the next player.
# Also add a pop-up, probably using pygame-gui, to tell the player
# to pass the shocker to the next person.
# NOTE: Each expansion is assigned multiple players, if an expansion has a tag
# such as "ONE_PERSON_ONLY", it means that when the game developer wants
# to go to the next player, it must self.notify() the players to pass the
# physical object around.
# NOTE: That tag IS NOT a part of NoPE-Lib or PDO-Lib. It simply acts as an
# identifier for games to use.
# TODO: Add player config editor.
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.teamSize = teamSize
self.turns //= self.teamSize
self.turn -= 1
self.next()
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 = list(self._pm.keys())
for i in range(self.teamSize):
self.playing.append(self._pm[playerNames[(i+self.turn)%len(playerNames)]])
return self.playing