示例#1
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection()) {
                conn.ConnectionString = DAO.ConnectionString();
                System.Diagnostics.Debug.WriteLine(WebConfigurationManager.ConnectionStrings[0].ConnectionString);
                try
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        cmd.CommandText = "CreateUser";
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = tbUsername.Text;
                        cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = tbPassword.Text;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                        //            conn.Open();
                        //          cmd.Parameters.Clear();
                        //        cmd.CommandText = "SelectAccount";
                        //      cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        //    cmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = tbUsername.Text;
                        //   cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = tbPassword.Text;
                        // SqlDataReader reader = cmd.ExecuteReader();

                        // Player player = Player.GetPlayer(reader);
                        //   Session["User"] = player;
                        Server.Transfer("Home.aspx");
                    }
                }
                catch (Exception ex) {
                    lbResult.Text = ex.ToString();
                }
            }
        }
示例#2
0
        private void WinOrLose(int landingPoint, List <int> bet, int muti)
        {
            bool won = false;

            for (int i = 0; i < bet.Count; i++)
            {
                if (bet[i] == landingPoint)
                {
                    won = true;
                }
            }
            if (won)
            {
                win(muti);
                player.rouletteWins++;
            }
            else
            {
                lose();
                player.roulettelosses++;
            }
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = DAO.ConnectionString();

                using (SqlCommand cmd = DAO.updatePlayer((Player)Session["User"]))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.ExecuteScalar();
                }
            }
        }
示例#3
0
        void Stay(decimal multiplier)
        {
            // draw the dealer until at least 17
            while (HandWorth(((List <Card>)Session["DealerHand"])) < 17)
            {
                ((List <Card>)Session["DealerHand"]).Add(deck.RandomPick(rnd));
            }
            //((List<Card>)Session["DealerHand"]).Add(deck.RandomPick(rnd));

            int dealerHandWorth = HandWorth(((List <Card>)Session["DealerHand"]));
            int playerHandWorth = HandWorth(((List <Card>)Session["PlayerHand"]));

            if ((HandWorth(((List <Card>)Session["DealerHand"])) == HandWorth(((List <Card>)Session["PlayerHand"]))))
            {
                lbWin.Text = "break even";
                DisplayDealerHand(true);
                player.money += ((decimal)Session["bet"]);
            }
            else if ((playerHandWorth <= 21) && ((playerHandWorth > dealerHandWorth) || dealerHandWorth > 21))
            {
                lbWin.Text = "Player win";
                DisplayDealerHand(true);
                System.Diagnostics.Debug.WriteLine("Bet before " + ((decimal)Session["bet"]));
                decimal newBet = ((decimal)Session["bet"]);
                newBet *= multiplier;
                System.Diagnostics.Debug.WriteLine("Bet wit multi: " + ((decimal)Session["bet"]));
                System.Diagnostics.Debug.WriteLine("Money before: " + player.money);
                player.money += newBet;
                System.Diagnostics.Debug.WriteLine("Money after: " + player.money);
                player.blackjackWins++;
            }
            else
            {
                lbWin.Text = "Dealer Win";
                player.blackjacklosses++;
                DisplayDealerHand(true);
            }


            Session["User"] = player;
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = DAO.ConnectionString();

                using (SqlCommand cmd = DAO.updatePlayer((Player)Session["User"]))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.ExecuteScalar();
                }
            }
            btnHit.Visible              = false;
            btnStay.Visible             = false;
            btnDoubleDown.Visible       = false;
            Session["OngoingBlackjack"] = null;



            ((Label)this.Master.FindControl("lbMoney")).Text = player.money.ToString();
        }
示例#4
0
        protected void btnStart_Click(object sender, EventArgs e)
        {
            lbWin.Text = "";
            try
            {
                decimal bet = Convert.ToDecimal(tbBet.Text);
                Session["bet"] = bet;
                System.Diagnostics.Debug.WriteLine("Bet:" + bet + " Money:" + player.money);
                if (bet <= player.money && bet > 0 && player.money - bet >= 0)
                {
                    lbBet.Text            = "";
                    btnHit.Visible        = true;
                    btnStay.Visible       = true;
                    btnDoubleDown.Visible = true;

                    List <Card> dealerHand = new List <Card>();
                    List <Card> playerHand = new List <Card>();
                    Session["OngoingBlackjack"] = true;
                    Session["PlayerHand"]       = null;
                    Session["dealerHand"]       = null;

                    playerHand.Add(deck.RandomPick(rnd));
                    playerHand.Add(deck.RandomPick(rnd));
                    dealerHand.Add(deck.RandomPick(rnd));
                    dealerHand.Add(deck.RandomPick(rnd));
                    Session["PlayerHand"] = playerHand;
                    Session["dealerHand"] = dealerHand;



                    ClearDealerHand();
                    ClearPlayerHand();
                    DisplayPlayerHand();
                    DisplayDealerHand(false);
                    player.money   -= bet;
                    Session["User"] = player;
                    ((Label)this.Master.FindControl("lbMoney")).Text = player.money.ToString();

                    using (SqlConnection conn = new SqlConnection())
                    {
                        conn.ConnectionString = DAO.ConnectionString();

                        using (SqlCommand cmd = DAO.updatePlayer((Player)Session["User"]))
                        {
                            conn.Open();
                            cmd.Connection = conn;
                            cmd.ExecuteScalar();
                        }
                    }
                }
                else
                {
                    lbBet.Text = "Your bet exceeds your money";
                }
            }
            catch {
                lbBet.Text = "Please enter a valid bet";
            }
        }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
                using (SqlConnection conn = new SqlConnection())
                {
                    conn.ConnectionString = DAO.ConnectionString();


                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection = conn;
                        conn.Open();
                        cmd.CommandText = "SelectAccountNoPass";
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = ((Player)Session["User"]).username;

                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.Read())
                        {
                            Player player = Player.GetPlayer(reader);
                            Session["User"] = player;
                        }

                        conn.Close();
                    }



                    lbLoginOrLogout.Text     = "Log Out";
                    lbRegisterOrAccount.Text = "Account";
                    lbUserMessage.Text       = "You are logged in as: " + ((Player)Session["User"]).username;
                    lbMoney.Text             = "    |    $" + ((Player)Session["User"]).money.ToString();
                    if (((Player)Session["User"]).role == "Owner")
                    {
                        lbRegisterOrAccount.Text = "Control Panel";
                    }
                }
            }
            else
            {
                lbMoney.Text       = "";
                lbUserMessage.Text = "";
            }
        }
示例#6
0
        private void NumberMatch(int LandingPoint, int bet)
        {
            if (LandingPoint == bet)
            {
                win(35);
                player.rouletteWins++;
            }
            else
            {
                lose();
                player.roulettelosses++;
            }
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = DAO.ConnectionString();

                using (SqlCommand cmd = DAO.updatePlayer((Player)Session["User"]))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.ExecuteScalar();
                }
            }
        }
示例#7
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection()) {
                conn.ConnectionString = DAO.ConnectionString();
                try
                {
                    using (SqlCommand cmd = new SqlCommand()) {
                        cmd.Connection = conn;
                        conn.Open();
                        cmd.CommandText = "SelectAccount";
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = tbLogin.Text;
                        cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = tbPass.Text;
                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.Read())
                        {
                            Player player = Player.GetPlayer(reader);
                            Session["User"] = player;
                        }

                        conn.Close();
                        if (((Player)Session["User"]).role == "Owner")
                        {
                            Response.Redirect("Owner.aspx");
                        }
                        else
                        {
                            Response.Redirect("Account.aspx");
                        }
                    }
                }
                catch (Exception ex) {
                    lbResult.Text = ex.ToString();
                }
            }
        }
示例#8
0
        protected void SpinButton_Click(object sender, EventArgs e)
        {
            Session["alreadyWon"] = null;
            int wheelLandingPoint = RandomNumber();

            //   wheelLandingPoint = 5;

            RouletteNumberlbl.Text = wheelLandingPoint.ToString();
            List <int> numBets            = NumberBets();
            int        NumberOfBetsPlaced = numBets.Count + SpecialBets().Count;

            try
            {
                decimal bet;
                bet            = Convert.ToDecimal(tbBet.Text);
                Session["bet"] = bet;
                if (NumberOfBetsPlaced == 0)

                {
                    resultLbl.Text = "You Must Place A Bet";
                }
                else if (player.money - bet * NumberOfBetsPlaced < 0)
                {
                    resultLbl.Text = "Your bets exceed your money.";
                }
                else
                {
                    player.money   -= bet * NumberOfBetsPlaced;
                    Session["User"] = player;
                    using (SqlConnection conn = new SqlConnection())
                    {
                        conn.ConnectionString = DAO.ConnectionString();

                        using (SqlCommand cmd = DAO.updatePlayer((Player)Session["User"]))
                        {
                            conn.Open();
                            cmd.Connection = conn;
                            cmd.ExecuteScalar();
                        }
                    }
                    // the number bets
                    for (int i = 0; i < numBets.Count; i++)
                    {
                        NumberMatch(wheelLandingPoint, numBets[i]);
                    }
                }
                // the special bets

                // top 2 to 1
                if (cbs0.Checked)
                {
                    int[] bets = { 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36 };
                    WinOrLose(wheelLandingPoint, bets, 3);
                }
                //mid 2 to 1
                if (cbs1.Checked)
                {
                    int[] bets = { 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35 };
                    WinOrLose(wheelLandingPoint, bets, 3);
                }
                //bottom 2 to 1
                if (cbs2.Checked)
                {
                    int[] bets = { 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34 };
                    WinOrLose(wheelLandingPoint, bets, 3);
                }

                //first 12
                if (cbs3.Checked)
                {
                    int[] bets = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
                    WinOrLose(wheelLandingPoint, bets, 3);
                }
                //second 12
                if (cbs4.Checked)
                {
                    int[] bets = { 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
                    WinOrLose(wheelLandingPoint, bets, 3);
                }
                //third 12
                if (cbs5.Checked)
                {
                    int[] bets = { 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 };
                    WinOrLose(wheelLandingPoint, bets, 3);
                }
                // 1-18
                if (cbs6.Checked)
                {
                    int[] bets = { 1,   2,  3,  4,  5, 6, 7, 8, 9, 10, 11, 12,
                                   13, 14, 15, 16, 17, 18 };
                    WinOrLose(wheelLandingPoint, bets, 2);
                }
                // even
                if (cbs7.Checked)
                {
                    List <int> bets = new List <int>();
                    for (int i = 1; i < 37; i++)
                    {
                        if (i % 2 == 0)
                        {
                            bets.Add(i);
                        }
                    }
                    WinOrLose(wheelLandingPoint, bets, 2);
                }
                // black
                if (cbs8.Checked)
                {
                    int[] bets = { 2,  4,  6,  8, 10, 11, 13, 15,  17
                                   ,  20, 22, 24, 26, 28, 29, 31,33, 35 };
                    WinOrLose(wheelLandingPoint, bets, 2);
                }
                // red
                if (cbs9.Checked)
                {
                    int[] bets = { 1,   3,  5,  7,  9, 12, 14, 16, 18, 19,
                                   21, 23, 25, 27, 30, 32, 34, 36 };
                    WinOrLose(wheelLandingPoint, bets, 2);
                }
                // odd
                if (cbs10.Checked)
                {
                    List <int> bets = new List <int>();
                    for (int i = 1; i < 37; i++)
                    {
                        if (i % 2 == 1)
                        {
                            SelectDeSelect(i);
                        }
                    }
                    WinOrLose(wheelLandingPoint, bets, 2);
                }
                //19-36
                if (cbs11.Checked)
                {
                    int[] bets = { 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 };
                    WinOrLose(wheelLandingPoint, bets, 2);
                }
                ((Label)this.Master.FindControl("lbMoney")).Text = player.money.ToString();
            }
            catch { }
        }
示例#9
0
        protected void Spinbtn_Click(object sender, EventArgs e)
        {
            //   try {
            //decimal bet = 50;
            decimal bet;

            try {
                bet = Convert.ToDecimal(tbBet.Text);
                if (bet > 0 && player.money - bet > -1)
                {
                    resultLbl.Text = "";
                    Session["bet"] = bet;
                    SpinandDisplay();


                    if (Pos[0, 0] == Pos[1, 0] && Pos[1, 0] == Pos[2, 0] && Pos[1, 0] == Pos[3, 0] && Pos[3, 0] == Pos[4, 0])
                    {
                        win(2);
                    }
                    else if (Pos[0, 1] == Pos[1, 1] && Pos[1, 1] == Pos[2, 1] && Pos[2, 1] == Pos[3, 1] && Pos[3, 1] == Pos[4, 1])
                    {
                        win(2);
                    }
                    else if (Pos[0, 2] == Pos[1, 2] && Pos[1, 2] == Pos[2, 2] && Pos[2, 2] == Pos[3, 2] && Pos[3, 2] == Pos[4, 2])
                    {
                        win(2);
                    }
                    else if (Pos[0, 0] == Pos[1, 1] && Pos[1, 1] == Pos[2, 0] && Pos[2, 0] == Pos[3, 1] && Pos[3, 1] == Pos[4, 0])
                    {
                        win(2);
                    }
                    else if (Pos[0, 2] == Pos[1, 1] && Pos[1, 1] == Pos[2, 0] && Pos[2, 0] == Pos[3, 1] && Pos[3, 1] == Pos[4, 2])
                    {
                        win(2);
                    }
                    else if (Pos[2, 0] == Pos[1, 1] && Pos[1, 1] == Pos[2, 1] && Pos[2, 1] == Pos[3, 1] && Pos[3, 1] == Pos[4, 2])
                    {
                        win(2);
                    }
                    else if (Pos[0, 0] == Pos[1, 2] && Pos[1, 2] == Pos[2, 0] && Pos[2, 0] == Pos[3, 2] && Pos[3, 2] == Pos[4, 2])
                    {
                        win(2);
                    }
                    else if (Pos[0, 2] == Pos[1, 1] && Pos[1, 1] == Pos[2, 1] && Pos[2, 1] == Pos[3, 1] && Pos[3, 1] == Pos[4, 0])
                    {
                        win(2);
                    }
                    else if (Pos[0, 2] == Pos[1, 2] && Pos[1, 2] == Pos[2, 0] && Pos[2, 0] == Pos[3, 2] && Pos[3, 2] == Pos[4, 2])
                    {
                        win(2);
                    }
                    else if (Pos[0, 1] == Pos[1, 2] && Pos[1, 2] == Pos[2, 1] && Pos[2, 0] == Pos[3, 2] && Pos[3, 2] == Pos[4, 1])
                    {
                        win(2);
                    }
                    else if (Pos[0, 0] == Pos[1, 2] && Pos[1, 2] == Pos[2, 2] && Pos[2, 2] == Pos[3, 2] && Pos[3, 2] == Pos[4, 0])
                    {
                        win(2);
                    }
                    else if (Pos[0, 0] == Pos[1, 1] && Pos[1, 1] == Pos[2, 0] && Pos[2, 0] == Pos[3, 1] && Pos[3, 1] == Pos[4, 2])
                    {
                        win(2);
                    }
                    else if (Pos[0, 2] == Pos[1, 0] && Pos[1, 0] == Pos[2, 2] && Pos[2, 2] == Pos[3, 0] && Pos[3, 0] == Pos[4, 2])
                    {
                        win(2);
                    }
                    else if (Pos[0, 2] == Pos[1, 1] && Pos[1, 1] == Pos[2, 1] && Pos[2, 1] == Pos[3, 1] && Pos[3, 1] == Pos[4, 2])
                    {
                        win(2);
                    }
                    else if (Pos[0, 0] == Pos[1, 2] && Pos[1, 2] == Pos[2, 1] && Pos[2, 1] == Pos[3, 2] && Pos[3, 2] == Pos[4, 1])
                    {
                        win(2);
                    }
                    else
                    {
                        lose();
                    }

                    Session["User"] = player;
                    using (SqlConnection conn = new SqlConnection())
                    {
                        conn.ConnectionString = DAO.ConnectionString();

                        using (SqlCommand cmd = DAO.updatePlayer((Player)Session["User"]))
                        {
                            conn.Open();
                            cmd.Connection = conn;
                            cmd.ExecuteScalar();
                        }
                    }
                }
            }catch {
                lbWarning.Text = "Please enter a valid number";
            }
        }