Example #1
0
        //When the game is over to win or lose
        private void EndGame()
        {
            ControllersGame.Update(user);//Update points
            Form temp = this.FindForm();

            temp.Controls.Clear();
            if (MessageBox.Show("¿Desea jugar otra partida?",
                                "Consulta",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //Reload Data al newForm
                GameData.InitializeGame();
                //Application.Restart();
                LoadTiles();
                LoadPlayer();
                LoadPanel();
                temp.Close();
                FrmGame newGame = new FrmGame(user);
                newGame.Show();
            }
            else
            {
                //Restart App!
                Application.Restart();
            }
        }
Example #2
0
 private void FrmGame_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (GameData.lifes <= 3 && GameData.lifes >= 0 && GameData.points > 0 && e.CloseReason == CloseReason.UserClosing)
         {
             throw new GameClosedInProcess("Have 1+ Points");
         }
     }
     catch (GameClosedInProcess)
     {
         dtptimerForMovements.Stop();
         if (MessageBox.Show($"¿Desea guardar sus puntos actuales? Actualemente tienes: {GameData.points} puntos",
                             "Consulta",
                             MessageBoxButtons.YesNo,
                             MessageBoxIcon.Question) == DialogResult.Yes)
         {
             ControllersGame.Update(user);
             Application.Exit();
         }
         else
         {
             Application.Exit();
         }
     }
 }
        private void BttnPlay_Click(object sender, EventArgs e)
        {
            if (txtUsuario.Text.Equals(""))
            {
                MessageBox.Show("¡Debe registrarse para poder jugar!");
            }
            else
            {
                try
                {
                    //Query to DB
                    User u = new User();
                    if (txtUsuario.Text.Length >= 20)
                    {
                        throw new NameLength("Name Very Long");
                    }

                    u = ControllersGame.Exist(txtUsuario.Text);

                    MessageBox.Show("Bienvenido: " + u.name + ".\n Tus puntos actuales son: " + u.point);
                    newGame(u);
                }
                //Custom Exception for Create User
                catch (UserException ex)
                {
                    MessageBox.Show(ex.Message + "  Creando...");
                    ControllersGame.Add(txtUsuario.Text);
                    MessageBox.Show("Registrado\n" + "Nickname: " + txtUsuario.Text + "\nPuntos: 0");
                    User u = new User();
                    u = ControllersGame.Exist(txtUsuario.Text);
                    newGame(u);
                }
                //Custom Exception for Very long name
                catch (NameLength)
                {
                    MessageBox.Show("Nombre demasiado largo");
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message);
                }
            }
        }
Example #4
0
        private void Score_Load(object sender, EventArgs e)
        {
            try
            {
                txtLabel.Width  = 100;
                txtLabel.Height = 100;
                txtLabel.Top    = 30;
                txtLabel.Left   = 30;
                txtLabel.Text   = "Presione ESC para regresar";
                txtLabel.Anchor = AnchorStyles.Left;
                this.Controls.Add(txtLabel);

                //graph specifications
                Height          = ClientSize.Height;
                Width           = ClientSize.Width;
                chart.Top       = 10;
                chart.Left      = 10;
                chart.Width     = Convert.ToInt32(Width * 0.95);
                chart.Height    = Convert.ToInt32(Height * 0.95);
                chart.Anchor    = AnchorStyles.None;
                chart.BackColor = Color.Transparent;

                //get top list

                u = ControllersGame.Top();
                if (u.Count == 0)
                {
                    throw new NoAccounts("La base de datos no tiene elementos");
                }
                else if (u.Count > 0 && u.Count < 10)
                {
                    throw new TopTenException("Fail Load");
                }

                //creating empty graph
                chart.Series = new SeriesCollection
                {
                    new RowSeries {
                        Title = "Top 10", Values = new ChartValues <int>(), DataLabels = true
                    }
                };
                chart.AxisY.Add(new Axis {
                    Labels = new List <string>()
                });
                u.Reverse();
                chart.LegendLocation = LegendLocation.Bottom;

                //filling fields of the graph
                foreach (var x in u)
                {
                    chart.Series[0].Values.Add(x.point);
                    chart.AxisY[0].Labels.Add(x.name);
                }
                MessageBox.Show("Top 10");
            }
            catch (NoAccounts ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (TopTenException)
            {
                //creating empty graph
                chart.Series = new SeriesCollection
                {
                    new RowSeries {
                        Title = $"Top {u.Count}", Values = new ChartValues <int>(), DataLabels = true
                    }
                };
                chart.AxisY.Add(new Axis {
                    Labels = new List <string>()
                });
                u.Reverse();
                chart.LegendLocation = LegendLocation.Bottom;

                //filling fields of the graph
                foreach (var x in u)
                {
                    chart.Series[0].Values.Add(x.point);
                    chart.AxisY[0].Labels.Add(x.name);
                }
                MessageBox.Show($"Top {u.Count}");
            }
            catch (Exception)
            {
                MessageBox.Show("Error al cargar el top");
            }
        }