diff options
| -rw-r--r-- | .idea/.gitignore | 8 | ||||
| -rw-r--r-- | .idea/inspectionProfiles/Project_Default.xml | 10 | ||||
| -rw-r--r-- | .idea/modules.xml | 8 | ||||
| -rw-r--r-- | .idea/sakura.iml | 17 | ||||
| -rw-r--r-- | .idea/vcs.xml | 6 | ||||
| -rw-r--r-- | engine/action.go | 49 | ||||
| -rw-r--r-- | engine/game.go | 19 | ||||
| -rw-r--r-- | engine/pool/pool.go | 4 | ||||
| -rw-r--r-- | server/web/index.gohtml | 4 |
9 files changed, 114 insertions, 11 deletions
diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..e157b11 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ +<component name="InspectionProjectProfileManager"> + <profile version="1.0"> + <option name="myName" value="Project Default" /> + <inspection_tool class="GoDfaErrorMayBeNotNil" enabled="true" level="WARNING" enabled_by_default="true"> + <methods> + <method importPath="github.com/gorilla/websocket" receiver="*Upgrader" name="Upgrade" /> + </methods> + </inspection_tool> + </profile> +</component>
\ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c21cfee --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/sakura.iml" filepath="$PROJECT_DIR$/.idea/sakura.iml" /> + </modules> + </component> +</project>
\ No newline at end of file diff --git a/.idea/sakura.iml b/.idea/sakura.iml new file mode 100644 index 0000000..ab77839 --- /dev/null +++ b/.idea/sakura.iml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="WEB_MODULE" version="4"> + <component name="Go" enabled="true"> + <buildTags> + <option name="customFlags"> + <array> + <option value="server" /> + </array> + </option> + </buildTags> + </component> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$" /> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
\ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project>
\ No newline at end of file diff --git a/engine/action.go b/engine/action.go index 2a73982..38749c7 100644 --- a/engine/action.go +++ b/engine/action.go @@ -43,20 +43,53 @@ type DesignateDamage struct { SourceCard *Card } -func (d *DesignateDamage) Actor() *Player { - return d.Defender +func (d *DesignateDamage) Then(g *Game) { } -func (d *DesignateDamage) Instigator() *Player { - return d.Attacker + +type PlayCard struct { + *BaseAction } -func (d *DesignateDamage) Then(g *Game) { +func (u *PlayCard) Then(g *Game) { + g.Actions = Interactions(&PlayCard{}, &UseVigor{}) } -func (d *DesignateDamage) Source() IsCard { - return d.SourceCard +type PlayAllOutCard struct { + *BaseAction } -type PlayCard struct { +func (p *PlayAllOutCard) Then(g *Game) { + g.Actions = Interactions(&EndTurn{}) +} + +type ShuffleDeck struct { + *BaseAction +} + +func (s *ShuffleDeck) Then(g *Game) { + g.Actions = Interactions(&DrawCard{}) +} + +type DrawCard struct { *BaseAction } + +func (d *DrawCard) Then(g *Game) { + g.Actions = Interactions(&PlayCard{}, &PlayAllOutCard{}, &UseVigor{}) +} + +type UseVigor struct { + *BaseAction +} + +func (u *UseVigor) Then(g *Game) { + g.Actions = Interactions(&PlayCard{}, &UseVigor{}) +} + +type EndTurn struct { + *BaseAction +} + +func (e *EndTurn) Then(g *Game) { + g.NextTurn() +} diff --git a/engine/game.go b/engine/game.go index 0ed93e2..19880f0 100644 --- a/engine/game.go +++ b/engine/game.go @@ -13,6 +13,8 @@ type Game struct { Stack []IsCard Actions map[InteractionID]Action + + CurrentPlayer *Player } func (g *Game) propagate() { @@ -28,6 +30,7 @@ func NewGame() *Game { g.Yin = NewPlayer(g) g.Yang = NewPlayer(g) g.propagate() + g.NextTurn() return g } @@ -45,3 +48,19 @@ func (g *Game) Winner() *Player { } return nil } + +func (g *Game) NextTurn() { + current := g.CurrentPlayer.Opponent(g) + g.CurrentPlayer = current + g.Actions = Interactions(&ShuffleDeck{ + &BaseAction{ + User: current, + BaseSource: nil, + }, + }, &DrawCard{ + &BaseAction{ + User: current, + BaseSource: nil, + }, + }) +} diff --git a/engine/pool/pool.go b/engine/pool/pool.go index 2179a12..5443baa 100644 --- a/engine/pool/pool.go +++ b/engine/pool/pool.go @@ -4,8 +4,8 @@ const Infinite = -1 const Empty = 0 type Pool struct { - OverflowsTo *Pool - SubtractsTo *Pool + OverflowsTo *Pool `json:"-"` + SubtractsTo *Pool `json:"-"` Max int Value int } diff --git a/server/web/index.gohtml b/server/web/index.gohtml index bf60372..d7a90b4 100644 --- a/server/web/index.gohtml +++ b/server/web/index.gohtml @@ -11,7 +11,9 @@ <script> const start = async () => { - const game = await fetch("/api/game/create") + const game = await fetch("/api/game/create", { + method: "POST", + }) const gameId = await game.text() const connection = new WebSocket(`/api/game/${gameId}/connect`) connection.addEventListener("message", (ev) => { |
