7 Replies - 1123 Views - Last Post: 13 August 2011 - 02:17 PM Rate Topic: -----

#1 Priyotosh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-August 11

How to show winner of a simple dice game through messagebox?

Posted 12 August 2011 - 09:45 AM

Below is the form that I'm facing problems with.


Here, the Red Player and Blue Player will throw the Dice. The Red and Blue colored dice bounces and shows a random number from 1 to 6. The throw number and their individual scores are shown through labels beside them. The score label shows the total by adding up the score of each throw.

What I want to do is to show the name of the winner (Red Player/Blue Player is the winner!) through a messagebox. I think I should use a Do Until Loop to show the winner, but i'm confused how?

The messagebox needs to appear when the decided number of throws beside the play button matches the throw number of blue player.

The names are -
Label beside the Play button - lblThrow
Red Player Throw number Label - lblRedThrow
Blue Player Throw number Label - lblBlueThrow
Blue Player Throw button - btnBlueThrow

Below is the code i've tried
Private Sub btnBlueThrow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBlueThrow.Click
   Do Until lblThrow.Text = lblBlueThrow.Text
            MessageBox.Show("The winner is Winner")
        Loop
      End Sub


It freezes the whole window when I click the Blue Player Throw button only once.

Is This A Good Question/Topic? 0
  • +

Replies To: How to show winner of a simple dice game through messagebox?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: How to show winner of a simple dice game through messagebox?

Posted 12 August 2011 - 10:15 AM

It would help if you showed your actual program structure. However, it will go wherever the action is done (throwing the dice) and the score is compared. If your throws are in a loop, then the message would be towards the end of the loop in a simple comparison. It then would break the loop. You can also make it as the condition of the loop. This would be the OPPOSITE of what you have...you don't want do until they are equal, you want to do it WHEN they are equal.

1. Throw die
2. Sum up score
3. Compare throws to total needed to win...

if lblThrow.text = lblBlueThrow.Text then
   MessageBox.Show("The winner is..")
end if



4. If throws don't match, start back at step 1.

:)

This post has been edited by Martyr2: 12 August 2011 - 10:17 AM

Was This Post Helpful? 0
  • +
  • -

#3 Priyotosh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-August 11

Re: How to show winner of a simple dice game through messagebox?

Posted 12 August 2011 - 11:50 AM

View PostMartyr2, on 12 August 2011 - 10:15 AM, said:

It would help if you showed your actual program structure. However, it will go wherever the action is done (throwing the dice) and the score is compared. If your throws are in a loop, then the message would be towards the end of the loop in a simple comparison. It then would break the loop. You can also make it as the condition of the loop. This would be the OPPOSITE of what you have...you don't want do until they are equal, you want to do it WHEN they are equal.

1. Throw die
2. Sum up score
3. Compare throws to total needed to win...

if lblThrow.text = lblBlueThrow.Text then
   MessageBox.Show("The winner is..")
end if



4. If throws don't match, start back at step 1.

:)


Actually, I wanted to upload an image, but it doesn't allow me to. How do I show you the design of my form?
Was This Post Helpful? 0
  • +
  • -

#4 NY Andrew  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 79
  • Joined: 25-May 11

Re: How to show winner of a simple dice game through messagebox?

Posted 12 August 2011 - 07:30 PM

View PostPriyotosh, on 12 August 2011 - 11:50 AM, said:

View PostMartyr2, on 12 August 2011 - 10:15 AM, said:

It would help if you showed your actual program structure. However, it will go wherever the action is done (throwing the dice) and the score is compared. If your throws are in a loop, then the message would be towards the end of the loop in a simple comparison. It then would break the loop. You can also make it as the condition of the loop. This would be the OPPOSITE of what you have...you don't want do until they are equal, you want to do it WHEN they are equal.

1. Throw die
2. Sum up score
3. Compare throws to total needed to win...

if lblThrow.text = lblBlueThrow.Text then
   MessageBox.Show("The winner is..")
end if



4. If throws don't match, start back at step 1.

:)


Actually, I wanted to upload an image, but it doesn't allow me to. How do I show you the design of my form?

To upload an image of your form:
1. Take a screenshot of your form with the PRINT SCREEN button on your keyboard (Might have to use a function button if on a laptop).
2. Open up paint and paste the screenshot into there.
3. Save it.
4. Click the CHOOSE FILE button when posting a reply and select the image, and you should be good to go! :D
Was This Post Helpful? 1
  • +
  • -

#5 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: How to show winner of a simple dice game through messagebox?

Posted 12 August 2011 - 08:02 PM

Windows 7 has that nifty snipping tool, which takes some really great quality desktop images for ya. ;)
Was This Post Helpful? 0
  • +
  • -

#6 NY Andrew  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 79
  • Joined: 25-May 11

Re: How to show winner of a simple dice game through messagebox?

Posted 12 August 2011 - 08:07 PM

View Posttrevster344, on 12 August 2011 - 08:02 PM, said:

Windows 7 has that nifty snipping tool, which takes some really great quality desktop images for ya. ;)

Unless your still on Vista :rolleyes2: Nothing like doing things the old fashioned way.
Was This Post Helpful? 0
  • +
  • -

#7 Priyotosh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-August 11

Re: How to show winner of a simple dice game through messagebox?

Posted 13 August 2011 - 11:47 AM

After working some hours last night (local time), I managed to finish almost 90% of my assignment and also the problem of this thread. :)

Feels good to sort out solutions on my own! :D

Thanks to NY Andrew, I had followed all the steps you mentioned, except the last step. I chose the 'Insert Image' button in the Reply Form. It says that the board doesn't support the specified format of JPEG and GIF.

Was This Post Helpful? 0
  • +
  • -

#8 NY Andrew  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 79
  • Joined: 25-May 11

Re: How to show winner of a simple dice game through messagebox?

Posted 13 August 2011 - 02:17 PM

View PostPriyotosh, on 13 August 2011 - 11:47 AM, said:

After working some hours last night (local time), I managed to finish almost 90% of my assignment and also the problem of this thread. :)

Feels good to sort out solutions on my own! :D

Thanks to NY Andrew, I had followed all the steps you mentioned, except the last step. I chose the 'Insert Image' button in the Reply Form. It says that the board doesn't support the specified format of JPEG and GIF.

Happy I could help! :bigsmile: As to why it does not allow you to upload the image, I'm not sure, but it's good to hear that you have finished the majority of your project!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1