Exemplo n.º 1
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (timeLeft > 0)
     {
         timeLeft   = timeLeft - 1;
         timer.Text = timeLeft.ToString();
     }
     else if (timeLeft == 0)
     {
         timer1.Stop();
         MessageBox.Show("Out of time!");
         EndGame endgame = new EndGame();
         endgame.Show();
         this.Hide();
     }
 }
Exemplo n.º 2
0
Arquivo: Main.cs Projeto: J4FZ/CMP307
        private void timer1_Tick(object sender, EventArgs e)
        {
            //code for timer
            int timeleftdis;

            if (timeLeft > 0)
            {
                //code for counting timer down
                timeLeft    = timeLeft - 1;
                timeleftdis = timeLeft + 1;
                timer.Text  = timeleftdis.ToString();
            }
            else if (timeLeft == 0)
            {
                timer.Text = "0";
                timer1.Stop();
                MessageBox.Show("Out of time!");
                //ends game if timer reaches 0
                EndGame endgame = new EndGame();
                endgame.Show();
                this.Hide();
            }
        }
Exemplo n.º 3
0
        private void no_button_Click(object sender, EventArgs e)
        {
            Globals.score  = Globals.score + Globals.wealthy;
            Globals.pop    = Globals.pop + Globals.popn;
            Globals.wealth = Globals.wealth + Globals.wealthy;

            if (Globals.pop > 100)
            {
                Globals.pop = 100;
            }

            if (Globals.wealth > 100)
            {
                Globals.wealth = 100;
            }

            popularity_score.Text = Globals.pop.ToString();
            wealth_score.Text     = Globals.wealth.ToString();
            total_score.Text      = Globals.score.ToString();

            if (Globals.pop < 1)
            {
                popularity_score.Text = "0";
                MessageBox.Show("Your popularity reached 0! Please try again.");
                EndGame endgame = new EndGame();
                endgame.Show();
                this.Hide();
            }
            else if (Globals.wealth < 1)
            {
                wealth_score.Text = "0";
                MessageBox.Show("Your earnings reached 0! Please try again.");
                EndGame endgame = new EndGame();
                endgame.Show();
                this.Hide();
            }
            else
            {
                if (Globals.nran < Globals.maxn)
                {
Existcheck2:

                    Globals.nran = Globals.nran + 1;


                    SqlConnection conn2;
                    string        connectionstring2 = "Data Source=vmwsql07.uad.ac.uk; Initial Catalog=sql1605044; User ID=sql1605044; Password=q?D46+il";
                    conn2 = new SqlConnection(connectionstring2);
                    conn2.Open();
                    string     selectText = "Select * from dbo.DogeCards where id = " + Globals.nran + ";";
                    SqlCommand Command2   = new SqlCommand(selectText);
                    Command2.Connection = conn2;

                    int exists = System.Convert.ToInt32(Command2.ExecuteScalar());


                    if (exists > 0)
                    {
                        Globals.nran = System.Convert.ToInt32(Command2.ExecuteScalar());//change nran to id from execute scalar

                        SqlDataReader dataR2;
                        dataR2 = Command2.ExecuteReader();

                        while (dataR2.Read())
                        {
                            Globals.id      = dataR2[6].ToString();
                            Globals.nran    = System.Convert.ToInt32(dataR2[0]);
                            Globals.url     = dataR2[5].ToString();
                            Globals.wealthy = System.Convert.ToInt32(dataR2[1]);
                            Globals.wealthn = System.Convert.ToInt32(dataR2[2]);
                            Globals.popy    = System.Convert.ToInt32(dataR2[3]);
                            Globals.popn    = System.Convert.ToInt32(dataR2[4]);
                        }
                        dataR2.Close();
                        conn2.Close();
                    }
                    else if (exists == 0)
                    {
                        goto Existcheck2;
                    }
                    image_card.ImageLocation = Globals.url;
                    image_description.Text   = Globals.id;
                    int score = Convert.ToInt32(total_score.Text);
                }
                else if (Globals.nran >= Globals.maxn)
                {
                    MessageBox.Show("Training complete.");
                    EndGame endgame = new EndGame();
                    endgame.Show();
                    this.Hide();
                }
            }
        }
Exemplo n.º 4
0
Arquivo: Main.cs Projeto: J4FZ/CMP307
        private void no_button_Click(object sender, EventArgs e)
        {
            //update the popualarity, earnings and total score variables
            Globals.score  = Globals.score + Globals.wealthy;
            Globals.pop    = Globals.pop + Globals.popn;
            Globals.wealth = Globals.wealth + Globals.wealthy;

            //cap popularity and wealth at 100
            if (Globals.pop > 100)
            {
                Globals.pop = 100;
            }

            if (Globals.wealth > 100)
            {
                Globals.wealth = 100;
            }


            //update popularity, wealth and total score on form
            popularity_score.Text = Globals.pop.ToString();
            wealth_score.Text     = Globals.wealth.ToString();
            total_score.Text      = Globals.score.ToString();


            //end game if popularity  or wealth reaches 0
            if (Globals.pop < 1)
            {
                popularity_score.Text = "0";
                MessageBox.Show("Your popularity reached 0! Please try again.");
                EndGame endgame = new EndGame();
                endgame.Show();
                this.Hide();
            }
            else if (Globals.wealth < 1)
            {
                wealth_score.Text = "0";
                MessageBox.Show("Your earnings reached 0! Please try again.");
                EndGame endgame = new EndGame();
                endgame.Show();
                this.Hide();
            }
            else
            {
                //check if current card is not last card in database
                if (Globals.cardid < Globals.maxn)
                {
Existcheck2:

                    Globals.cardid = Globals.cardid + 1;

                    //get next card data
                    Globals.conn.Open();
                    string     selectText = "Select * from dbo.DogeCards where id = " + Globals.cardid + ";";
                    SqlCommand Command2   = new SqlCommand(selectText);
                    Command2.Connection = Globals.conn;


                    //returns value of next id in database (if row doesn't exist then returns 0)
                    int exists = System.Convert.ToInt32(Command2.ExecuteScalar());

                    //if card exists
                    if (exists > 0)
                    {
                        Globals.cardid = System.Convert.ToInt32(Command2.ExecuteScalar());//change cardid to id from execute scalar

                        SqlDataReader dataR2;
                        dataR2 = Command2.ExecuteReader();

                        //get all card data
                        while (dataR2.Read())
                        {
                            Globals.id      = dataR2[6].ToString();
                            Globals.cardid  = System.Convert.ToInt32(dataR2[0]);
                            Globals.url     = dataR2[5].ToString();
                            Globals.wealthy = System.Convert.ToInt32(dataR2[1]);
                            Globals.wealthn = System.Convert.ToInt32(dataR2[2]);
                            Globals.popy    = System.Convert.ToInt32(dataR2[3]);
                            Globals.popn    = System.Convert.ToInt32(dataR2[4]);
                        }
                        dataR2.Close();
                        Globals.conn.Close();
                    }
                    else if (exists == 0)
                    {
                        //if executescalar returns null then go back and try again with next row in database
                        Globals.conn.Close();
                        goto Existcheck2;
                    }

                    //display card details
                    image_card.ImageLocation = Globals.url;
                    image_description.Text   = Globals.id;
                    int score = Convert.ToInt32(total_score.Text);
                }
                else if (Globals.cardid >= Globals.maxn)
                {
                    //if card is last in database then end game
                    EndGame endgame = new EndGame();
                    endgame.Show();
                    this.Hide();
                }
            }
        }