Esempio n. 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         board = new GameBoard();
         pdao  = new PlayerDAO(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString);
         string playerName = pdao.GetNamebyEmail(Session["currentEmail"].ToString());
         int    pid        = pdao.GetIdByEmail(Session["currentEmail"].ToString());
         player             = new ConnectPlayer(pid, playerName, Session["currentEmail"].ToString());
         bot                = new ConnectBot(null, null);
         game               = new ConnectFour(bot, player, board);
         tblBoard.GridLines = GridLines.Both;
         printBoard();
         Session.Add("board", board);
         Session.Add("player", player);
         Session.Add("bot", bot);
         Session.Add("game", game);
     }
     else
     {
         board  = (GameBoard)Session["board"];
         player = (ConnectPlayer)Session["player"];
         bot    = (ConnectBot)Session["bot"];
         game   = (ConnectFour)Session["game"];
     }
 }
Esempio n. 2
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!";
        }
Esempio n. 3
0
        /// <summary>
        /// Enables hit/stand buttons, shows default blue for dealers 2nd card, deals new hand to both players, and
        /// updates the images associated with the cards dealt. Shows the score.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnNewGame_Click(object sender, EventArgs e)
        {
            btnHit.Enabled       = true;
            btnStand.Enabled     = true;
            lblResultMsg.Visible = false;
            pCard3.Visible       = false;
            pCard4.Visible       = false;
            pCard5.Visible       = false;

            dCard2.ImageUrl = "../images/cards/Card_Blue_Ver.png";
            dCard3.Visible  = false;
            dCard4.Visible  = false;
            dCard5.Visible  = false;

            deck            = new Deck();
            Session["deck"] = deck;

            dealer            = new Dealer("AI", null);
            Session["dealer"] = dealer;

            string playerName = playerDAO.GetNamebyEmail(Session["currentEmail"].ToString());
            int    pid        = playerDAO.GetIdByEmail(Session["currentEmail"].ToString());

            human            = new BJPlayer(pid, playerName, Session["currentEmail"].ToString());
            Session["human"] = human;

            blackjack       = new Blackjack(deck, dealer, human);
            Session["game"] = blackjack;

            ViewState["hitCounter"] = hitCounter;

            human.PlayerHand = blackjack.DealNewHand();
            human.PlayerHand.CheckAceAfterHit(human.PlayerHand.CardsInHand.Last());

            dealer.PlayerHand = blackjack.DealNewHand();
            dealer.PlayerHand.CheckAceAfterHit(dealer.PlayerHand.CardsInHand.Last());

            pCard1.ImageUrl = human.PlayerHand.CardsInHand.First().Image;
            pCard2.ImageUrl = human.PlayerHand.CardsInHand.ElementAt(1).Image;

            dCard1.ImageUrl = dealer.PlayerHand.CardsInHand.First().Image;

            pPanel.Visible = true;
            dPanel.Visible = true;

            dScore.Text = dealer.PlayerHand.CardsInHand.First().Number.ToString();
            pScore.Text = human.PlayerHand.HandValue.ToString();
        }