diff --git a/main.go b/main.go index 94ef43203dd301fbec3d0fafd2d4da6f89723dab..fde405162c2228d2d9a03673cecc1554e0498993 100644 --- a/main.go +++ b/main.go @@ -17,8 +17,8 @@ type Player struct { // Game represents a game object in the database type Game struct { ID int - Player1 Player - Player2 Player + Player1 string + Player2 string } // Move represents a move in the game @@ -30,12 +30,14 @@ type Move struct { } var ( - gameData map[int]Game + gameData map[int]Game + idCounter int ) /************** MAIN FUNCTION **********************/ func main() { + // Initialise global variables gameData = make(map[int]Game) http.HandleFunc("/", hello) @@ -73,9 +75,25 @@ func move(w http.ResponseWriter, r *http.Request) { } func createGame(w http.ResponseWriter, r *http.Request) { + //jsonData := readJsonFromRequest(r) + + newGameID := generateID() + newGame := Game{ + ID: newGameID, + // Player1: , + // Player2: , + } + gameData[newGameID] = newGame + fmt.Fprintf(w, "hello") } func joinGame(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "hello") } + +/************** Helper functions *******************/ + +func generateID() int { + return idCounter + 1 +}