Archived
Type definition
This commit is contained in:
Vendored
+15
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from game.Game import Game
|
||||
@@ -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())
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user