Ejemplo n.º 1
0
        //update the road, who won , money won and lost
        public void UpdateLogic()
        {
            if (moving == 1)
            {
                Gl.glTranslatef(0, 0, 0.35f);
            }
            else
            if (moving == -1)
            {
                Gl.glTranslatef(0, 0, -0.35f);
            }
            count++;
            if (Controller.FinishedRace == true && mostrado == 0)
            {
                int        result;
                RacePunter obj = new RacePunter();
                mostrado = 1;
                moving   = 0;
                MessageBox.Show("The winner was the: " + lblPrimero.Text + " (car no: " + lblbettingno.Text + ")"); //display the actual result of race
                if (lblPrimero.Text == "Blue car")                                                                  //call overriden abstract metod to get and set winning better name
                {
                    result = obj.getWinning(carno, 1);                                                              //1 for blue car
                }
                else if (lblPrimero.Text == "Red car")
                {
                    result = obj.getWinning(carno, 2); //2 for red car
                }
                else if (lblPrimero.Text == "Green car")
                {
                    result = obj.getWinning(carno, 3); //3 for green car
                }
                else
                {
                    result = obj.getWinning(carno, 4); //else 4 for violet car
                }
                //based on carnumber which won set opposite punter winning status to true
                if (result == 0)
                {
                    joe_won = true;
                }
                else if (result == 1)
                {
                    bob_won = true;
                }
                else if (result == 2)
                {
                    ai_won = true;
                }
                //change the textboxes to who won/lost and money won/lost and left
                changeText();
                for (int i = 0; i < 3; i++)
                {
                    carno[i]    = 0;
                    betValue[i] = 0;
                }
            }

            if (count == 10)
            {
                if (Controller.StartedRace == true && mostrado == 0)
                {
                    int   primero            = control.GetFirstPlace();
                    float distanciaRecorrida = control.GetDistanceInMeters(primero);
                    lblDistancia.Text = Convert.ToString((int)distanciaRecorrida);
                    switch (primero)
                    {
                    //ui changes based on which car is first
                    case 0:
                    {
                        lblPrimero.Text      = "Blue car";
                        lblbettingno.Text    = "1";
                        lblPrimero.ForeColor = Color.Blue;
                        break;
                    }

                    case 1:
                    {
                        lblPrimero.Text      = "Red car";
                        lblbettingno.Text    = "2";
                        lblPrimero.ForeColor = Color.Red;
                        break;
                    }

                    case 2:
                    {
                        lblPrimero.Text      = "Green car";
                        lblbettingno.Text    = "3";
                        lblPrimero.ForeColor = Color.Green;
                        break;
                    }

                    case 3:
                    {
                        lblPrimero.Text      = "Violet car";
                        lblbettingno.Text    = "4";
                        lblPrimero.ForeColor = Color.Violet;
                        break;
                    }
                    }
                }
                count = 0;
            }
        }
Ejemplo n.º 2
0
        //change textboxes values for punters
        private void changeText()
        {
            RacePunter punter = new RacePunter(); //create punter object

            if (joe_won == true)
            {
                joe_total   = Convert.ToInt32(joe_total + betValue[0]);
                txtJoe.Text = punter.getPunterName(0) + " won and now has " + joe_total;
                joe_won     = false;
            }
            else
            {
                joe_total = Convert.ToInt32(joe_total - betValue[0]);
                if (joe_total <= 0)
                {
                    txtJoe.Text      = "Busted";
                    txtJoe.ForeColor = Color.Red;
                    rbJoe.Enabled    = false;
                    bustCount++;
                }
                else
                {
                    txtJoe.Text = punter.getPunterName(0) + " lost and now has " + joe_total;
                }
            }
            if (bob_won == true)
            {
                bob_total   = Convert.ToInt32(bob_total + betValue[1]);
                txtBob.Text = punter.getPunterName(1) + " won and now has " + bob_total;
                bob_won     = false;
            }
            else
            {
                bob_total = Convert.ToInt32(bob_total - betValue[1]);
                if (bob_total <= 0)
                {
                    txtBob.Text      = "Busted";
                    rbBob.Enabled    = false;
                    txtBob.ForeColor = Color.Red;
                    bustCount++;
                }
                else
                {
                    txtBob.Text = punter.getPunterName(1) + " lost and now has " + bob_total;
                }
            }
            if (ai_won == true)
            {
                ai_total   = Convert.ToInt32(ai_total + betValue[2]);
                txtAI.Text = punter.getPunterName(2) + " won and now has " + ai_total;
                ai_won     = false;
            }
            else
            {
                ai_total = Convert.ToInt32(ai_total - betValue[2]);
                if (ai_total <= 0)
                {
                    txtAI.Text      = "Busted";
                    rbAI.Enabled    = false;
                    txtAI.ForeColor = Color.Red;
                    bustCount++;
                }
                else
                {
                    txtAI.Text = punter.getPunterName(2) + " lost and now has " + ai_total;
                }
            }
            if (bustCount > 1)
            {
                MessageBox.Show("Game Over");
            }
        }