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
f0d3d138
Commit
f0d3d138
authored
Sep 30, 2021
by
ceddral
Browse files
gamelobby: restrict actions to agent player
parent
48be6f05
Changes
1
Hide whitespace changes
Inline
Side-by-side
gamelobby.go
View file @
f0d3d138
...
...
@@ -16,6 +16,7 @@ type GameLobbyPlayer struct {
type
GameLobby
struct
{
lock
*
sync
.
Mutex
agent
*
GameLobbyPlayer
players
map
[
string
]
*
GameLobbyPlayer
playerOrder
[]
string
}
...
...
@@ -50,6 +51,7 @@ func (gl *GameLobby) Register(glp *Player) {
}
gl
.
players
[
glp
.
name
]
=
p
gl
.
playerOrder
=
append
(
gl
.
playerOrder
,
p
.
name
)
gl
.
agent
=
gl
.
players
[
gl
.
playerOrder
[
0
]]
go
gl
.
Loop
(
p
)
gl
.
Update
()
gl
.
Unlock
()
...
...
@@ -59,6 +61,11 @@ func (gl *GameLobby) Register(glp *Player) {
func
(
gl
*
GameLobby
)
Unregister
(
name
string
)
{
gl
.
Lock
()
gl
.
unregisterUnlocked
(
name
)
if
len
(
gl
.
playerOrder
)
>
0
{
gl
.
agent
=
gl
.
players
[
gl
.
playerOrder
[
0
]]
}
else
{
gl
.
agent
=
nil
}
gl
.
Unlock
()
glp
:=
gs
.
players
[
name
]
glp
.
Close
()
...
...
@@ -116,16 +123,29 @@ func (gl *GameLobby) StartGame() {
NewGame
(
ps
,
[]
string
{
"base"
,
"ext1"
})
}
func
(
gl
*
GameLobby
)
agentAction
(
p
*
GameLobbyPlayer
,
key
Key
)
{
switch
key
{
case
keyReturn
:
go
gl
.
StartGame
()
}
}
func
(
gl
*
GameLobby
)
patientAction
(
p
*
GameLobbyPlayer
,
key
Key
)
{
}
func
(
gl
*
GameLobby
)
Loop
(
p
*
GameLobbyPlayer
)
{
for
{
select
{
case
<-
p
.
lobbyEvent
:
case
input
:=
<-
p
.
inputEvent
:
key
:=
toKey
(
input
)
switch
key
{
case
keyReturn
:
// TODO only allow starting game for player #1
go
gl
.
StartGame
()
gl
.
Lock
()
a
:=
gl
.
agent
gl
.
Unlock
()
if
a
==
p
{
gl
.
agentAction
(
p
,
key
)
}
else
{
gl
.
patientAction
(
p
,
key
)
}
}
select
{
// check kill before doing anything that may lock
...
...
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