Exemplo n.º 1
0
        private void userManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UManage UserManagement = new UManage(LoggedInPlayer, users);

            UserManagement.ShowDialog(this);
            if (UserManagement.DialogResult == DialogResult.OK)
            {
                LoggedInPlayer = UserManagement.LoggedInUser.guid;
                PlayerBalance += UserManagement.AddAmount;
                GetLoggedinUser();
            }
            UserManagement.Dispose();
        }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            bets.Items.Add(10); //betsList.Items.Add("$10.00");
            bets.Items.Add(20); //betsList.Items.Add("$20.00");
            bets.Items.Add(30); //betsList.Items.Add("$30.00");
            bets.Items.Add(50);
            bets.Items.Add(100);
            bets.Items.Add(250);
            bets.Items.Add(500);
            bets.SelectedIndex = 0;
            _ = bets.Focus();

            //set array for visible cards
            Playercards[0] = Playercard1;
            Playercards[1] = Playercard2;
            Playercards[2] = Playercard3;
            Playercards[3] = Playercard4;
            Playercards[4] = Playercard5;
            Playercards[5] = Playercard6;
            Playercards[6] = Playercard7;
            Dealercards[0] = Dealercard1;
            Dealercards[1] = Dealercard2;
            Dealercards[2] = Dealercard3;
            Dealercards[3] = Dealercard4;
            Dealercards[4] = Dealercard5;
            Dealercards[5] = Dealercard6;
            Dealercards[6] = Dealercard7;
            //load player balance
            FileStream reader = null;

            try
            {
                reader = File.Open(Path.Combine(Application.UserAppDataPath, "BlackJack07", "Balance.sav"), FileMode.Open);
            }
            catch (DirectoryNotFoundException)
            {
                Directory.CreateDirectory(Path.Combine(Application.UserAppDataPath, "BlackJack07"));
                File.Create(Path.Combine(Application.UserAppDataPath, "BlackJack07", "Balance.sav")).Close();
            }
            catch (FileNotFoundException)
            {
                File.Create(Path.Combine(Application.UserAppDataPath, "BlackJack07", "Balance.sav")).Close();
            }
            catch (PathTooLongException)
            {
                MessageBox.Show("Due to technical issues, we cannot retrieve or save the balance of your game today. Sorry!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                saveTheData = false;
            }
            catch (NotSupportedException)
            {
                MessageBox.Show("Due to technical issues, we cannot retrieve or save the balance of your game today. Sorry!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                saveTheData = false;
            }
            finally
            {
                if (reader != null)
                {
                    try
                    {
                        saveData = (SaveData)formatter.Deserialize(reader);
                    }
                    catch (FormatException) { saveData = null; }
                    catch (SerializationException)
                    {
                        saveData = null;
                    }
                    catch (EndOfStreamException)
                    {
                        saveData = null;
                    }
                    catch (OverflowException)
                    { }
                    reader.Close();
                }
            }
            if (saveData != null)
            {
                users          = saveData.userlist;
                PlayerBalance  = saveData.balance;
                LoggedInPlayer = saveData.LoggedInPlayer;
                if (saveData.playStarted)
                {
                    theDeck            = saveData.deck;
                    thePlayer          = saveData.player;
                    theDealer          = saveData.dealer;
                    bets.SelectedIndex = saveData.theBet;
                    insurancebet       = saveData.insuranceBet;
                    lockedbet          = saveData.lockedInBet;
                    insurance          = saveData.insurance;
                    Playercardvisible  = saveData.Playercardvisible;
                    Dealercardvisible  = saveData.Dealercardvisible;
                    for (int counter = 0; counter < 7; counter++)
                    {
                        Playercards[counter].Visible = saveData.PlayerVisibleBools[counter];
                        Dealercards[counter].Visible = saveData.DealerVisibleBools[counter];
                        if (Playercards[counter].Visible)
                        {
                            Playercards[counter].Image = thePlayer.PlayerHand.ElementAt(counter).CardFront();
                        }
                        if (Dealercards[counter].Visible)
                        {
                            if (counter == 0)
                            {
                                Dealercards[counter].Image = theDealer.DealerHand.ElementAt(counter).CardFront();
                            }
                            else
                            {
                                Dealercards[counter].Image = Card.GetBackImage();
                            }
                        }
                    }
                }
                else
                {
                    for (int counter = 0; counter < 2; counter++)
                    {
                        Playercards[counter].Visible = true;
                        Playercards[counter].Image   = Card.GetBackImage();
                        Dealercards[counter].Visible = true;
                        Dealercards[counter].Image   = Card.GetBackImage();
                    }
                }
            }
            else
            {
                for (int counter = 0; counter < 2; counter++)
                {
                    Playercards[counter].Visible = true;
                    Playercards[counter].Image   = Card.GetBackImage();
                    Dealercards[counter].Visible = true;
                    Dealercards[counter].Image   = Card.GetBackImage();
                }
            }
            for (int counter = 2; counter < 7; counter++)
            {
                Playercards[counter].Visible = false;
                Playercards[counter].Image   = Card.GetBackImage();
                Dealercards[counter].Visible = false;
                Dealercards[counter].Image   = Card.GetBackImage();
            }
            UManage UserManagement = new UManage(LoggedInPlayer, users);

            UserManagement.ShowDialog(this);
            if (UserManagement.DialogResult == DialogResult.OK)
            {
                LoggedInPlayer = UserManagement.LoggedInUser.guid;
                PlayerBalance += UserManagement.AddAmount;
                GetLoggedinUser();
            }
            UserManagement.Dispose();
            GetLoggedinUser();
            PlayerBalanceLabel.Text = string.Format("Your balance is {0}", PlayerBalance.ToString("C0"));
            if (PlayerBalance < 10)
            {
                MessageBox.Show("You must add more money before you can play");
                Application.Exit();
            }
        }