예제 #1
0
        /// <summary>
        /// Uses DAO to retrieve current users ID and email, then uses those to retrieve a list of results
        /// for that user. Displays the user's name and number of wins for each game.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            playerDAO = new PlayerDAO(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString);
            resultDAO = new ResultDAO(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString);

            string playerName = playerDAO.GetNamebyEmail(Context.User.Identity.Name);

            lblWelcomeMsg.Text = $"Welcome back, {playerName}!";

            int           playerID   = playerDAO.GetIdByEmail(Context.User.Identity.Name);
            List <Result> allResults = resultDAO.GetAllResultsByID(playerID);

            int bCount = 0, cCount = 0, allCount = 0;

            foreach (Result r in allResults)
            {
                if (r.HumanWin == 1)
                {
                    allCount += 1;

                    if (r.GameID == "BLA")
                    {
                        bCount += 1;
                    }
                    else if (r.GameID == "CON")
                    {
                        cCount += 1;
                    }
                }
            }
            lblBWins.Text   = $"Blackjack Wins: {bCount}";
            lblCWins.Text   = $"Connect Four Wins: {cCount}";
            lblAllWins.Text = $"You have {allCount} total wins!";
        }
예제 #2
0
        public MainWindow()
        {
            InitializeComponent();

            tableDatas = new List <string>();
            tableDatas.Add("form");
            tableDatas.Add("question");
            tableDatas.Add("question_option");
            UpdateTableData.ItemsSource = tableDatas;
            DeleteTableData.ItemsSource = tableDatas;

            formdata           = new FormDAO();
            questiondata       = new QuestionDAO();
            questionOptiondata = new QuestionOptionDAO();
            resultdata         = new ResultDAO();
            usersdata          = new UsersDAO();

            MySqlConnection connection = MyMySQLConnection.ConnectionSingleton();

            connection.Open();
            formColumnNames           = formdata.FindColumnNamesOnlyString(connection);
            questionColumnNames       = questiondata.FindColumnNamesOnlyString(connection);
            questionOptionColumnNames = questionOptiondata.FindColumnNamesOnlyString(connection);
            resultColumnNames         = resultdata.FindColumnNamesOnlyString(connection);
            connection.Close();
        }
예제 #3
0
 public MeetingService(IUserAuthorization userAuthorization, IUserProvider userProvider, MeetingDAO meetingDao, InvitationDAO invitationDao, TaskDAO taskDao, ResultDAO resultDao)
 {
     _userAuthorization = userAuthorization;
     _meetingDao        = meetingDao;
     _invitationDao     = invitationDao;
     _taskDao           = taskDao;
     _resultDao         = resultDao;
     _userId            = userProvider.GetUserId();
 }
 //更新战绩
 public void UpdateResult(bool isVictory)
 {
     result.TotalCount++;
     if (isVictory)
     {
         result.WinCount++;
     }
     ResultDAO.UpdateResult(mySqlConnection, ref result);
 }
예제 #5
0
        /// <summary>
        /// Performs multiple checks using blackjack rules to determine if any player has won or busted.
        /// </summary>
        /// <param name="playerID">The player's ID. Needed to query the database.</param>
        /// <returns>A message to the player containing the result of the game.</returns>
        public string CheckWin(int playerID)
        {
            resultDAO = new ResultDAO(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString);

            // If the player has busted, Dealer wins and game is over
            if (CheckHandStatus(player) == 0)
            {
                this.GameResult = DBLibrary.GameResult.AIWIN;
                resultDAO.AddResult(new Result(this.GameID, playerID, 0));
                return("You busted!");
            }
            // Dealer has busted, player wins and game is over
            else if (CheckHandStatus(dealer) == 0)
            {
                this.GameResult = DBLibrary.GameResult.PLAYERWIN;
                resultDAO.AddResult(new Result(this.GameID, playerID, 1));
                return("Dealer busted. You win!");
            }
            // If both dealer and player have completed their turns, check for highest hand
            else if (player.TurnComplete && dealer.TurnComplete)
            {
                // If player and dealer have the same hand value(including blackjacks), its a draw
                if (player.PlayerHand.HandValue == dealer.PlayerHand.HandValue)
                {
                    this.GameResult = DBLibrary.GameResult.PUSH;
                    return("It's a push!");
                }
                // Player's hand is higher than the dealers hand
                else if (player.PlayerHand.HandValue > dealer.PlayerHand.HandValue)
                {
                    this.GameResult = DBLibrary.GameResult.PLAYERWIN;
                    resultDAO.AddResult(new Result(this.GameID, playerID, 1));
                    return("You win!");
                }
                // Dealers hand is higher than players hand
                else if (dealer.PlayerHand.HandValue > player.PlayerHand.HandValue)
                {
                    this.GameResult = DBLibrary.GameResult.AIWIN;
                    resultDAO.AddResult(new Result(this.GameID, playerID, 0));
                    return("You lose!");
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #6
0
        /// <summary>
        /// Modifies the GameResult to indicate who won the game, push is a tie.
        /// </summary>
        /// <param name="owner">Symbolizes who won the game</param>
        public void EndGame(int owner)
        {
            ResultDAO dao = new ResultDAO(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString);

            if (owner == 1)
            {
                this.GameResult = DBLibrary.GameResult.PLAYERWIN;
                dao.AddResult(new Result("CON", player.PlayerID, 1));
            }
            else if (owner == 2)
            {
                this.GameResult = DBLibrary.GameResult.AIWIN;
                dao.AddResult(new Result("CON", player.PlayerID, 0));
            }
            else
            {
                this.GameResult = DBLibrary.GameResult.PUSH;
            }
        }
예제 #7
0
        // 登录请求的处理
        //todo,未判断是否已经登录,不能避免重复登录问题
        public string Login(Server server, Client client, string data)
        {
            string[] strs = data.Split(',');                                              //利用逗号分割用户名和密码
            User     user = UserDAO.VerifyUser(client.MySqlConnection, strs[0], strs[1]); //通过DAO判断用户名密码是否正确

            if (user == null)
            {
                return(((int)RetuenCode.Fail).ToString());//返回登录失败
            }

            //取得战绩
            Result res        = ResultDAO.GetResultByUserid(client.MySqlConnection, user.Id);
            int    totalCount = res.TotalCount;
            int    winCount   = res.WinCount;

            //把账户和战绩信息保存到Client实例中
            client.SetUserData(user, res);

            //返回账户、战绩数据
            return(string.Format("{0},{1},{2},{3}", (int)RetuenCode.Sucess, user.Name, totalCount, winCount));
        }