コード例 #1
0
ファイル: Game.cs プロジェクト: mahowa/School-Projects
        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
        /// <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);
        }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: mahowa/School-Projects
        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");
            }
        }