Skip to content
Snippets Groups Projects
Commit 8bac3451 authored by fr3517's avatar fr3517
Browse files

Merge branch 'channels'

# Conflicts:
#	main.go
parents d11c704f c11e48d3
No related branches found
No related tags found
No related merge requests found
......@@ -11,12 +11,14 @@ import (
// Player represents a player
type Player struct {
ID int
ID int
Name string
}
// Game represents a game object in the database
type Game struct {
ID int
ID int
Channels [2]chan string
Player1 string
Player2 string
}
......@@ -67,11 +69,18 @@ func move(w http.ResponseWriter, r *http.Request) {
log.Println("could not decode json data into Move struct")
}
game := gameData[move.GameID]
sendChan := game.Channels[move.Player]
recChan := game.Channels[1-move.Player]
sendChan <- move.MoveData
if move.GameOver {
fmt.Println("Game over!")
fmt.Fprintf(w, "Game over!")
return
}
fmt.Fprintf(w, move.MoveData)
response := <-recChan
fmt.Fprintf(w, response)
}
func createGame(w http.ResponseWriter, r *http.Request) {
......
Click==7.0
Flask==1.1.1
itsdangerous==1.1.0
Jinja2==2.11.1
MarkupSafe==1.1.1
pkg-resources==0.0.0
Werkzeug==1.0.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment