diff --git a/main.go b/main.go index fde405162c2228d2d9a03673cecc1554e0498993..73eebfb8bd4fab50b0177d53d4fbe64e7b754cf3 100644 --- a/main.go +++ b/main.go @@ -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) { diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index d144b52c95291919a98f675ffdce988d20a6d1aa..0000000000000000000000000000000000000000 --- a/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -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