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

Channels so players wait for response

parent e0d3b299
No related branches found
No related tags found
No related merge requests found
...@@ -11,14 +11,16 @@ import ( ...@@ -11,14 +11,16 @@ import (
// Player represents a player // Player represents a player
type Player struct { type Player struct {
ID int ID int
Name string
} }
// Game represents a game object in the database // Game represents a game object in the database
type Game struct { type Game struct {
ID int ID int
Player1 Player Player1 Player
Player2 Player Player2 Player
Channels [2]chan string
} }
// Move represents a move in the game // Move represents a move in the game
...@@ -65,11 +67,18 @@ func move(w http.ResponseWriter, r *http.Request) { ...@@ -65,11 +67,18 @@ func move(w http.ResponseWriter, r *http.Request) {
log.Println("could not decode json data into Move struct") 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 { 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) { 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