/// <summary> /// Returns the Full game status of a game with the particular GAME ID /// </summary> public FullGame GetStatus(string gt) { if (gt == null) { //403 Misssing parameters SetResponse("NF"); return(null); } //Create a Connection and a CreateTransaction Query Object MySqlConnection conn = new MySqlConnection(connectionString); TransactionQuery TQ = new TransactionQuery(conn); Queue <string> returnQ; //Variables for holding the strings that the query returns. string player2Token = "", player1Token = "", board = "", startTime = "", score1 = "0", score2 = "0", p1Name = "", p2Name = "", status = ""; int duration = 0; int Limit = 0; List <WordScore> p1Words = new List <WordScore>(); List <WordScore> p2Words = new List <WordScore>(); // Query Games table for the status and the Player1Token of the given game token. TQ.addCommand("select GameState, Player1Token from games where GameToken = ?gameToken"); TQ.addParms(new string[] { "gameToken" }, new string[] { gt }); TQ.addReadParms(new string[] { "GameState", "Player1Token" }, new bool[] { false, true }); TQ.addConditions((result, command) => { status = result.Dequeue(); player1Token = result.Dequeue(); TQ.injectComand("select Nickname from users where UserToken = ?player1Token", new string[, ] { { "player1Token", player1Token } }, new string[] { "Nickname" }, true, out returnQ); p1Name = returnQ.Dequeue(); if (status == "waiting" || status == "cancelled") { return(false); } if (status == "finished") { TQ.injectComand("select Word, Score from words where GameToken = ?gameToken and PlayerToken = ?player1Token", new string[, ] { }, new string[] { "Word", "Score" }, true, out returnQ); int count = returnQ.Count / 2; while (count > 0) { p1Words.Add(new WordScore() { word = returnQ.Dequeue(), score = Convert.ToInt32(returnQ.Dequeue()) }); count--; } } return(true); }); TQ.addCommand("select Player2Token, Board, StartTime, Score1, Score2 from pairedGames where GameToken = ?gameToken"); TQ.addReadParms(new string[] { "Player2Token", "Board", "StartTime", "Score1", "Score2" }, new bool[] { false, false, false, false, true }); TQ.addRepeatParm(); TQ.addConditions((result, command) => { player2Token = result.Dequeue(); board = result.Dequeue(); startTime = result.Dequeue(); score1 = result.Dequeue(); score2 = result.Dequeue(); Limit = Convert.ToInt32(TotalTime); GetTimeSpan(command, ref duration, ref status, startTime); TQ.injectComand("select Nickname from users where UserToken = ?player2Token", new string[, ] { { "player2Token", player2Token } }, new string[] { "Nickname" }, true, out returnQ); p2Name = returnQ.Dequeue(); if (status == "finished") { TQ.injectComand("select Word, Score from words where GameToken = ?gameToken and PlayerToken = ?player2Token", new string[, ] { }, new string[] { "Word", "Score" }, true, out returnQ); int count = returnQ.Count / 2; while (count > 0) { p2Words.Add(new WordScore() { word = returnQ.Dequeue(), score = Convert.ToInt32(returnQ.Dequeue()) }); count--; } } return(true); }); if (!TQ.Transaction()) { SetResponse("ISE"); return(null); } if (status == "") { SetResponse("gt"); return(null); } // Create return object from extracted data PlayerStatus ps1 = new PlayerStatus() { Score = Convert.ToInt32(score1), nickname = p1Name, wordsPlayed = p1Words }; PlayerStatus ps2 = new PlayerStatus() { Score = Convert.ToInt32(score2), nickname = p2Name, wordsPlayed = p2Words }; FullGame fg = new FullGame() { player1 = ps1, player2 = ps2, board = board, gameStatus = status, timeleft = duration, timelimit = Limit }; appLog.WriteEntry("BoggleServer: FullGame successfully returned", EventLogEntryType.Information); return(fg); }
public void SimpleDataStructureTest() { BoggleService Boggle = new BoggleService(); Player[] uT = new Player[USERS]; string[] gT = new string[GAMES]; for (int i = 0; i < USERS; i++) { string nn = i.ToString(); Player p = new Player { nickname = nn }; uT[i] = new Player() { userToken = MakeUser(p).Result.userToken }; } int gc = 0; //counter int pc = 0; foreach (Player tempP in uT) { if (pc % 2 == 0) { gT[gc] = JoinGame(tempP).Result.gameToken; Assert.AreEqual(GetBriefStatus(gT[gc]).Result.gameStatus, "waiting"); Assert.AreEqual(GetStatus(gT[gc]).Result.gameStatus, "waiting"); Assert.AreEqual(GetStatus(gT[gc]).Result.player1.Score, 0); Assert.AreEqual(GetStatus(gT[gc]).Result.board, ""); gc++; } else { string gt = JoinGame(tempP).Result.gameToken; Assert.AreEqual(GetBriefStatus(gT[gc - 1]).Result.gameStatus, "playing"); Assert.AreEqual(GetStatus(gT[gc - 1]).Result.gameStatus, "playing"); } pc++; } for (int i = 0; i < 30; i++) { int uc = 0; //counter foreach (string s in gT) { if (GetBriefStatus(s).Result.gameStatus == "playing") { BoggleBoard boggleboard = new BoggleBoard(GetStatus(s).Result.board); gameboard = GetStatus(s).Result.board; PlayerStatus p1 = GetStatus(s).Result.player1; PlayWord pw = new PlayWord() { gameToken = s, playerToken = uT[uc].userToken, word = playWords1[i] }; uT[uc].Score = uT[uc].Score + (int)PlayWord(pw).Result.wordScore; } else { Assert.Fail("Game in waiting"); } Assert.AreEqual(GetStatus(s).Result.player1.Score, uT[uc].Score); Assert.AreEqual(GetBriefStatus(s).Result.score1, uT[uc].Score); uc = uc + 2; } } }