diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c2c0c15 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "src/main.py", + "console": "internalConsole" + } + ] +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7279eaa..0768f44 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ gevent==24.2.1 greenlet==3.0.3 -websocket==0.2.1 +websockets==12.0 zope.event==5.0 zope.interface==6.2 diff --git a/src/game/Card.py b/src/game/Card.py new file mode 100644 index 0000000..65153f6 --- /dev/null +++ b/src/game/Card.py @@ -0,0 +1,42 @@ +from enum import Enum + + +class CardType(str, Enum): + """Playable card types""" + + HERO = "hero" + HERO_ABILITY = "hero_ability" + CURRENCY = "currency" + WEAPON = "weapon" + CHAMPION = "champion" + ACTION = "action" + + +class CardFaction(str, Enum): + """Playable card factions""" + + BLUE = "blue" + RED = "red" + GREEN = "green" + YELLOW = "yellow" + + +class Card: + """Represents any playable card""" + + sprite: str + name: str + text: str + cost: int + card_type: CardType + faction: CardFaction + + def __init__(self): + pass + + +class CardGuard(Card): + """Represents any guard card""" + + defense: int + guard: bool diff --git a/src/game/Game.py b/src/game/Game.py new file mode 100644 index 0000000..ee1e648 --- /dev/null +++ b/src/game/Game.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +from typing import List + +from game.Card import Card +from game.Team import Team + + +class Game: + """Instance of the game, with players and a market""" + + market_stack: List[Card] + market: List[Card] + gem_stack: List[Card] + teams: List[Team] + + started: bool + + default_health = 80 + + def __init__(self): + self.market_stack = [] + self.market = [] + self.gem_stack = [] + self.teams = [] + self.started = False + + def create_team(self): + if self.started: + return False + team = Team(self, health=self.default_health) + self.teams.append(team) diff --git a/src/game/Player.py b/src/game/Player.py new file mode 100644 index 0000000..d5970d8 --- /dev/null +++ b/src/game/Player.py @@ -0,0 +1,16 @@ +from typing import List +from game.Card import Card +from game.Team import Team + + +class Player: + """Game player, controller by a Client""" + + stack_pile: List[Card] + discard_pile: List[Card] + team: Team + + def __init__(self, team: Team): + self.stack_pile = [] + self.discard_pile = [] + self.team = team diff --git a/src/game/Team.py b/src/game/Team.py new file mode 100644 index 0000000..822f57a --- /dev/null +++ b/src/game/Team.py @@ -0,0 +1,33 @@ +from typing import List +from game.Game import Game +from game.Player import Player + + +class Team: + _team_id = 1 + + game: Game + players: List[Player] + + health: int + color: str + name: str + + def __init__(self, game, health=80, color="red", name="Team " + _team_id): + Team._team_id += 1 + self.game = game + self.players = [] + + self.health = health + self.color = color + self.name = name + + def delete(self): + """Get garbage collected you idiot""" + if len(self.players) == 0: + self.game.teams.remove(self) + else: + raise Warning("Tried to delete an empty team!") + + def removePlayer(self): + pass diff --git a/src/game/__init__.py b/src/game/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..bbb00ae --- /dev/null +++ b/src/main.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python + +from game.Game import Game diff --git a/src/netcode/Client.py b/src/netcode/Client.py new file mode 100644 index 0000000..e69de29 diff --git a/src/netcode/GameServer.py b/src/netcode/GameServer.py new file mode 100644 index 0000000..b1db2e1 --- /dev/null +++ b/src/netcode/GameServer.py @@ -0,0 +1,15 @@ +import asyncio +from websockets.server import serve + + +async def echo(websocket): + async for message in websocket: + await websocket.send(message) + + +async def main(): + async with serve(echo, "localhost", 8765): + await asyncio.Future() # run forever + + +asyncio.run(main()) diff --git a/src/netcode/PlayerServer.py b/src/netcode/PlayerServer.py new file mode 100644 index 0000000..633c6f9 --- /dev/null +++ b/src/netcode/PlayerServer.py @@ -0,0 +1,12 @@ +import asyncio +from websockets.server import serve + + +async def echo(websocket): + async for message in websocket: + await websocket.send(message) + + +async def main(): + async with serve(echo, "localhost", 8765): + await asyncio.Future() # run forever