示例#1
0
        public Game(string GT, string GS, Player P1, string GB)       //Constuct a new game object

        {
            _FG = new FullGame()
            {
                player1 = new PlayerStatus(), player2 = new PlayerStatus()
            };
            _BG      = new BriefGame();
            _Player2 = new Player()
            {
                nickname = string.Empty
            };
            gameToken     = GT;
            gameStatus    = GS;
            Player1       = P1;
            board         = GB;
            timelimit     = 120;
            timeleft      = 120;
            Player1.Score = 0;
        }
示例#2
0
        public void ComplexTest()
        {
            Player player1 = new Player()
            {
                nickname = "test"
            };

            player1.userToken = MakeUser(player1).Result.userToken;

            Player player2 = new Player()
            {
                nickname = "test3"
            };

            player2.userToken = MakeUser(player2).Result.userToken;

            String    gameToken = JoinGame(player1).Result.gameToken;
            BriefGame bg        = GetBriefStatus(gameToken).Result;

            Assert.AreEqual(bg.gameStatus, "waiting");

            Assert.AreEqual(gameToken, JoinGame(player2).Result.gameToken);
            Assert.AreEqual(GetBriefStatus(gameToken).Result.gameStatus, "playing");
        }
示例#3
0
        /// <summary>
        /// Returns the Brief game status of a game with a particular GAME ID
        /// </summary>
        public BriefGame GetBriefStatus(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);

            //Variable for holding the status of the game, if status returns "", it means the queury didn't work
            string status = "";

            // Query Games table for the status of the given game token.
            TQ.addCommand("select GameState from games where GameToken = ?gameToken");
            TQ.addParms(new string[] { "gameToken" }, new string[] { gt });
            TQ.addReadParms(new string[] { "GameState" }, new bool[] { true });
            TQ.addConditions((result, command) =>
            {
                status = result.Dequeue();
                if (status == "waiting" || status == "finished")
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            });

            //Variables for keeping duration, score1 and score2.
            string startTime = "", sc1 = "0", sc2 = "0";
            int    duration = 0;

            ///Query the Paried Game for GetBrief status, get the duration, score for player1 and player 2
            TQ.addCommand("select  StartTime, Score1, Score2 from pairedGames where GameToken = ?gameToken");
            TQ.addReadParms(new string[] { "StartTime", "Score1", "Score2" }, new bool[] { false, false, true });
            TQ.addRepeatParm();
            TQ.addConditions((result, command) =>
            {
                startTime = result.Dequeue();
                sc1       = result.Dequeue();
                sc2       = result.Dequeue();
                GetTimeSpan(command, ref duration, ref status, startTime);
                return(true);
            });



            //Proccess the transactions
            if (!TQ.Transaction())
            {
                SetResponse("ISE");
                return(null);
            }
            if (status == "")
            {
                SetResponse("gt");
                return(null);
            }
            BriefGame bf = new BriefGame()
            {
                gameStatus = status, score1 = Convert.ToInt32(sc1), score2 = Convert.ToInt32(sc2), timeleft = duration
            };

            appLog.WriteEntry("BoggleServer: FullGame successfully returned", EventLogEntryType.Information);
            return(bf);
        }
示例#4
0
        public void ResponseTest()
        {
            Player p = null;
            string gt;
            string ut = MakeUser(p).Result.userToken;

            if (!String.IsNullOrEmpty(ut))
            {
                Assert.Fail("Not failing");
            }

            gt = JoinGame(p).Result.gameToken;
            if (!String.IsNullOrEmpty(gt))
            {
                Assert.Fail("Not failing");
            }

            p = new Player()
            {
                userToken = null
            };
            gt = JoinGame(p).Result.gameToken;
            if (!String.IsNullOrEmpty(gt))
            {
                Assert.Fail("Not failing");
            }

            p = new Player()
            {
                userToken = "0"
            };
            gt = JoinGame(p).Result.gameToken;
            if (!String.IsNullOrEmpty(gt))
            {
                Assert.Fail("Not failing");
            }
            p = new Player()
            {
                nickname = "test"
            };
            ut          = MakeUser(p).Result.userToken;
            p.userToken = ut;
            gt          = JoinGame(p).Result.gameToken;
            gt          = JoinGame(p).Result.gameToken;
            if (!String.IsNullOrEmpty(gt))
            {
                Assert.Fail("Not failing");
            }
            //TODO these tests are not working need to figure out why???
            if (DeleteGame("", null).Result)
            {
                Assert.Fail("delete game nulll user token respones not working");
            }
            if (DeleteGame(null, "").Result)
            {
                Assert.Fail("delete game nulll user game respones not working");
            }
            if (DeleteGame("", "").Result)
            {
                Assert.Fail("delete game couldnt find gametoken in games list response not working");
            }

            FullGame fg = GetStatus(null).Result;

            if (fg != null)
            {
                Assert.Fail("full game null respones not working");
            }

            fg = GetStatus("").Result;
            if (fg != null)
            {
                Assert.Fail("full game not game with game token respones not working");
            }

            BriefGame bg = GetBriefStatus(null).Result;

            if (bg != null)
            {
                Assert.Fail("brief game null respones not working");
            }

            bg = GetBriefStatus("").Result;
            if (bg != null)
            {
                Assert.Fail("brief game not game with game token respones not working");
            }

            PlayWord w  = null;
            int?     pw = PlayWord(w).Result.wordScore;

            if (pw != null)
            {
                Assert.Fail("playword respones failing");
            }
            w = new PlayWord()
            {
                playerToken = ""
            };
            pw = PlayWord(w).Result.wordScore;
            if (pw != null)
            {
                Assert.Fail("playword respones failing");
            }
        }