Exemple #1
0
        private static int GameOver(FormMainPage form)
        {
            int score = Convert.ToInt32(form.lblDieTotalValue.Text);

            if (GameVariables.Round == 1)
            {
                if (GameVariables.Wins.Contains(score))
                {
                    return(1);
                }
                else if (GameVariables.Loses.Contains(score))
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                if (score == GameVariables.PointWin)
                {
                    return(1);
                }
                else if (score == GameVariables.PointLose)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
        }
Exemple #2
0
        public static void AddAndActivatePlayer(string inputName, FormMainPage form)
        {
            string userName = CleanUserName(inputName);

            if (!string.IsNullOrWhiteSpace(userName))
            {
                if (form.crapsDataSet.User.Select("Name = '" + userName + "'").Length != 0)
                {
                    MessageBox.Show("That player already exists. Please enter a new player or select your name from the list.");
                }
                else
                {
                    CrapsDataSet.UserRow userRow = form.crapsDataSet.User.NewUserRow();
                    userRow.Name = userName.ToUpper();
                    form.crapsDataSet.User.Rows.Add(userRow);
                    try
                    {
                        form.userTableAdapter.Insert(userName.ToUpper());
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                    form.userTableAdapter.Fill(form.crapsDataSet.User);
                    ViewController.PlayerActivate(userName, form);
                }
            }
            else
            {
                MessageBox.Show("Your name cannot be empty.");
            }
        }
Exemple #3
0
        private static void ResetGame(string winorlose, FormMainPage form)
        {
            int currentGame = (form.crapsDataSet.Game.Select("[Player ID] = " + GameVariables.UserID, "Id DESC").Count() > 0)
                                ? (int)form.crapsDataSet.Game.Select("[Player ID] = " + GameVariables.UserID, "Id DESC")[0]["Id"]
                                : 0;

            CrapsDataSet.GameRow gameRow = form.crapsDataSet.Game.FindById(currentGame);
            gameRow["Result"] = winorlose;
            gameRow["Time"]   = DateTime.Now;
            if (GameVariables.PointWin > 0)
            {
                gameRow["Point"] = GameVariables.PointWin.ToString();
            }
            form.gameTableAdapter.Update(form.crapsDataSet.Game);
            try
            {
                form.gameTableAdapter.Update(form.crapsDataSet.Game);
            }
            catch
            {
                MessageBox.Show(currentGame.ToString());
            }
            form.gameTableAdapter.Fill(form.crapsDataSet.Game);
            GameController.NewGame(form);
        }
Exemple #4
0
 public static void DeletePlayer(FormMainPage form)
 {
     CrapsDataSet.UserRow userRow = form.crapsDataSet.User.FindById(GameVariables.UserID);
     ClearPlayerHistory(form);
     userRow.Delete();
     form.userTableAdapter.Update(form.crapsDataSet.User);
     form.userTableAdapter.Fill(form.crapsDataSet.User);
     form.rollHistTableAdapter.Fill(form.crapsDataSet.RollHist);
 }
Exemple #5
0
 private static void ShowDice(FormMainPage form)
 {
     form.lblDie1Value.Visible     = true;
     form.lblDie2Value.Visible     = true;
     form.lblDieTotalValue.Visible = true;
     form.lblRollDie1.Visible      = true;
     form.lblRollDie2.Visible      = true;
     form.lblRollTotal.Visible     = true;
 }
Exemple #6
0
 private static void ClearPlayerGames(FormMainPage form)
 {
     for (int i = form.crapsDataSet.Game.Rows.Count - 1; i >= 0; i--)
     {
         DataRow dataRow = form.crapsDataSet.Game.Rows[i];
         if (dataRow.Field <int>("Player ID") == GameVariables.UserID)
         {
             dataRow.Delete();
         }
     }
     form.gameTableAdapter.Update(form.crapsDataSet.Game);
     form.gameTableAdapter.Fill(form.crapsDataSet.Game);
 }
Exemple #7
0
        internal static async Task <int[]> RollDice(FormMainPage form, HttpClient client)
        {
            DiceController dice = await GetDiceAsync("https://rolz.org/api/?2d6.json", form, client);

            if (dice != null)
            {
                int[] diceValues = new int[2];
                diceValues[0] = Convert.ToInt32(Regex.Match(dice.details, @"(?<=\()\d").ToString());
                diceValues[1] = Convert.ToInt32(Regex.Match(dice.details, @"(?<=\+)\d").ToString());
                return(diceValues);
            }
            else
            {
                MessageBox.Show("Connection Failed. Generating Rolls Locally");
                Random rnd = new Random();
                return(new int[] { rnd.Next(1, 7), rnd.Next(1, 7) });
            }
        }
Exemple #8
0
        private static async Task <DiceController> GetDiceAsync(string path, FormMainPage form, HttpClient httpClient)
        {
            try
            {
                DiceController      dice     = null;
                HttpResponseMessage response = await httpClient.GetAsync(path);

                if (response.IsSuccessStatusCode)
                {
                    dice = await response.Content.ReadAsAsync <DiceController>();
                }
                return(dice);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(null);
            }
        }
Exemple #9
0
 public static void NewGame(FormMainPage form)
 {
     CrapsDataSet.GameRow gameRow = form.crapsDataSet.Game.NewGameRow();
     gameRow["Player Id"] = GameVariables.UserID;
     form.crapsDataSet.Game.AddGameRow(gameRow);
     try
     {
         form.gameTableAdapter.Update(form.crapsDataSet.Game);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
     GameVariables.Round    = 1;
     form.lblWinValue.Text  = string.Join(" or ", GameVariables.Wins);
     form.lblLossValue.Text = string.Join(" or ", GameVariables.Loses);
     GameVariables.PointWin = 0;
     form.rollHistTableAdapter.Fill(form.crapsDataSet.RollHist);
     form.gameTableAdapter.Fill(form.crapsDataSet.Game);
 }
Exemple #10
0
 public static void UpdateGameState(FormMainPage form)
 {
     if (GameOver(form) == 0)
     {
         form.lblOutcome.Text = "You Lost :(";
         ResetGame("Loss", form);
     }
     else if (GameOver(form) == 1)
     {
         form.lblOutcome.Text = "You Win!";
         ResetGame("Win", form);
     }
     else
     {
         if (GameVariables.Round == 1)
         {
             SetPoint(form);
             form.lblOutcome.Text = "Roll again!";
         }
         GameVariables.Round++;
     }
 }
Exemple #11
0
        public static void UpdateUser(string inputName, FormMainPage form)
        {
            string userName = CleanUserName(inputName);

            if (form.crapsDataSet.User.Select("Name = '" + userName + "'").Length != 0)
            {
                MessageBox.Show("That player already exists.");
            }
            else
            {
                CrapsDataSet.UserRow userRow = form.crapsDataSet.User.FindById(GameVariables.UserID);
                userRow.Name = userName.ToUpper();
                try
                {
                    form.userTableAdapter.Update(form.crapsDataSet);
                    form.userTableAdapter.Fill(form.crapsDataSet.User);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }
Exemple #12
0
        public static void PopulateRolls(int[] rolls, FormMainPage form)
        {
            form.lblOutcome.Visible    = true;
            form.lblDie1Value.Text     = rolls[0].ToString();
            form.lblDie2Value.Text     = rolls[1].ToString();
            form.lblDieTotalValue.Text = (rolls[0] + rolls[1]).ToString();
            ShowDice(form);

            int currentGame = (form.crapsDataSet.Game.Select("[Player ID] = " + GameVariables.UserID).Count() > 0)
                                ? (int)form.crapsDataSet.Game.Select("[Player ID] = " + GameVariables.UserID, "Id DESC")[0]["Id"]
                                : 0;

            CrapsDataSet.RollRow rollRow = form.crapsDataSet.Roll.NewRollRow();
            rollRow["PlayerID"] = GameVariables.UserID;
            rollRow["Game"]     = currentGame;
            rollRow["Die1"]     = rolls[0];
            rollRow["Die2"]     = rolls[1];
            rollRow["RollNum"]  = GameVariables.Round;

            if (GameVariables.PointWin != 0)
            {
                rollRow["Point"] = GameVariables.PointWin.ToString();
            }

            form.crapsDataSet.Roll.AddRollRow(rollRow);
            try
            {
                form.rollTableAdapter.Update(form.crapsDataSet.Roll);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            form.rollTableAdapter.Fill(form.crapsDataSet.Roll);
            form.rollHistTableAdapter.Fill(form.crapsDataSet.RollHist);
        }
Exemple #13
0
 public static void ClearPlayerHistory(FormMainPage form)
 {
     ClearPlayerRolls(form);
     ClearPlayerGames(form);
 }
Exemple #14
0
 private static void SetPoint(FormMainPage form)
 {
     GameVariables.PointWin = Convert.ToInt32(form.lblDieTotalValue.Text);
     form.lblWinValue.Text  = GameVariables.PointWin.ToString();
     form.lblLossValue.Text = GameVariables.PointLose.ToString();
 }