Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ceddral
fahrradwurstmond
Commits
60956f99
Commit
60956f99
authored
Sep 23, 2021
by
ceddral
Browse files
game: allow leaving at the end of a game
parent
d32bd3d3
Changes
1
Hide whitespace changes
Inline
Side-by-side
game.go
View file @
60956f99
...
...
@@ -24,6 +24,8 @@ type GameStateWithPiece interface {
}
func
(
g
*
Game
)
broadcastState
(
state
GameState
)
{
g
.
Lock
()
defer
g
.
Unlock
()
for
_
,
p
:=
range
g
.
players
{
select
{
case
p
.
gameEvent
<-
state
:
...
...
@@ -97,6 +99,7 @@ type GamePlayer struct {
tokens
map
[
Token
]
int
inputEvent
chan
[]
byte
gameEvent
chan
GameState
gameKill
chan
struct
{}
scr
*
tg
.
Screen
menu
GameMenu
menuv
*
tg
.
View
...
...
@@ -306,6 +309,7 @@ func NewGame(pns []string, extensions []string) (g *Game) {
tokens
:
make
(
map
[
Token
]
int
),
inputEvent
:
glp
.
inputEvent
,
gameEvent
:
make
(
chan
GameState
,
100
),
gameKill
:
make
(
chan
struct
{},
1
),
scr
:
glp
.
scr
,
menuv
:
tg
.
NewView
(
glp
.
scr
,
0
,
0
,
30
,
glp
.
scr
.
H
),
boardv
:
tg
.
NewView
(
glp
.
scr
,
30
,
0
,
glp
.
scr
.
W
-
30
,
glp
.
scr
.
H
),
...
...
@@ -415,6 +419,11 @@ func (g *Game) Loop(p *GamePlayer) {
}
if
anyStateAnyRoleAction
(
state
,
p
,
key
)
{
break
}
}
select
{
// check kill before doing anything that may lock
case
<-
p
.
gameKill
:
return
default
:
}
p
.
menu
.
Redraw
(
state
)
g
.
board
.
Redraw
(
p
,
state
)
if
fullRedraw
{
...
...
@@ -838,5 +847,21 @@ func (s *StateFinished) agentTransition(p *GamePlayer) {
})
}
func
(
s
*
StateFinished
)
patientTransition
(
p
*
GamePlayer
)
{}
func
(
s
*
StateFinished
)
agentAction
(
p
*
GamePlayer
,
key
Key
)
bool
{
return
false
}
func
(
s
*
StateFinished
)
patientAction
(
p
*
GamePlayer
,
key
Key
)
bool
{
return
false
}
func
(
s
*
StateFinished
)
agentAction
(
p
*
GamePlayer
,
key
Key
)
bool
{
return
s
.
action
(
p
,
key
)
}
func
(
s
*
StateFinished
)
patientAction
(
p
*
GamePlayer
,
key
Key
)
bool
{
return
s
.
action
(
p
,
key
)
}
func
(
s
*
StateFinished
)
action
(
p
*
GamePlayer
,
key
Key
)
bool
{
if
key
==
keyReturn
{
s
.
g
.
Lock
()
delete
(
s
.
g
.
players
,
p
.
name
)
s
.
g
.
Unlock
()
p
.
gameKill
<-
struct
{}{}
p
.
scr
.
Clear
()
gs
.
Lock
()
glp
:=
gs
.
players
[
p
.
name
]
glp
.
context
=
glgl
glp
.
context
.
Register
(
glp
)
gs
.
Unlock
()
return
true
}
return
false
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment