public async void joinGame(String gameId, String joinName) { FirebaseResponse response = await client.GetTaskAsync(gameId + "/gameBoard"); if (response == null) { serverError = true; } else { gbdb = response.ResultAs <GameBoardDB>(); // number of players info updated if (gbdb.numberOfPlayers < 4) { gbdb.numberOfPlayers += 1; pdb[gbdb.numberOfPlayers - 1].name = joinName; pdb[gbdb.numberOfPlayers - 1].id = gbdb.numberOfPlayers - 1; pdb[gbdb.numberOfPlayers - 1].pawnId = -1; myID = gbdb.numberOfPlayers - 1; SetResponse responsegame = await client.SetTaskAsync(gameId + "/gameBoard/", gbdb); //Other player info received PlayerDB temp = new PlayerDB(); FirebaseResponse response1 = await client.GetTaskAsync(gbdb.gameId + "/players/0/"); temp = response1.ResultAs <PlayerDB>(); pdb[0] = temp; if (gbdb.numberOfPlayers == 2) { _ = await client.SetTaskAsync(gameId + "/players/1", pdb[1]); } if (gbdb.numberOfPlayers == 3) { FirebaseResponse response2 = await client.GetTaskAsync(gbdb.gameId + "/players/1/"); pdb[1] = response2.ResultAs <PlayerDB>(); _ = await client.SetTaskAsync(gameId + "/players/2", pdb[2]); } if (gbdb.numberOfPlayers == 4) { FirebaseResponse response2 = await client.GetTaskAsync(gbdb.gameId + "/players/1/"); pdb[1] = response2.ResultAs <PlayerDB>(); FirebaseResponse response3 = await client.GetTaskAsync(gbdb.gameId + "/players/2/"); pdb[2] = response3.ResultAs <PlayerDB>(); _ = await client.SetTaskAsync(gameId + "/players/3", pdb[3]); } // gameboard info is received } else { serverError = true; } } }
public Storage() { gbdb = new GameBoardDB(); pdb = new PlayerDB[4] { new PlayerDB(), new PlayerDB(), new PlayerDB(), new PlayerDB() }; serverError = false; client = new FireSharp.FirebaseClient(config); }
public async void getGameBoardDB() { FirebaseResponse response1 = await client.GetTaskAsync(gbdb.gameId + "/gameBoard"); gbdb = response1.ResultAs <GameBoardDB>(); }