Results 1 to 6 of 6

Thread: Can Anyone Help Me With Visual Basics Dice Battle Game?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    3

    Can Anyone Help Me With Visual Basics Dice Battle Game?

    Hey everyone, I'm new to Visual Basics programming and I need help ASAP with a project I'm working on that is a dice battle game. So far I finished creating the GUI and I got some of the coding done, however I got stuck and I need help in finding out why my program is not doing what it needs to do and how to go about it. Basically, a human player is playing against a computer using VB's built in random number generator. The objective of the game is for either opponent to have a higher score than the other to win the game in a best of an odd number of matches format from 1 up to 99 ( like 1, 3, 5, 7, 9, 11, 13 and so forth).

    The instructions are: 1. The input number of matches must be checked for validity, a message box must pop up with the appropriate message to indicate that the input is invalid. A popup must show if the input is invalid. 2. Once the game starts, the Best of Games input box (text box) should be disabled (or grayed out) until the Restart button is pressed or the match ends. 3. Either opponents score must be tracked, follow the Game User Interface screenshot format and other details below. The PC vs You boxes (labels) should display the current scores. 4.The Outcome boxes (label) should display who won the current game or if there is a tie (i.e. "You Win", "PC Wins", "Its a tie"). 5. Each of the Roll Total Boxes (label) should display the total of the PC's and the human player's roll accordingly. 6. Only games with one score higher than the other count, tied games do not. 7. The following message box pop ups should come up depending on the outcome of the set. 8. Pressing the Exit button should show the following popup: Do you want to exit?

    So I will post up my code and take a post a pic of my GUI to show you where I'm at and how to finally get this program working and see what I need to fix or add to my code. Thank you all so much for your help everyone and hope to hear from you soon.

    Public Class DiceBattleForm

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
    Dim RESPONSE As MsgBoxResult
    RESPONSE = MsgBox("Do you want to exit?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question)
    If RESPONSE = MsgBoxResult.Yes Then
    Me.Dispose()
    End If
    End Sub

    Private Sub RollButton_Click(sender As Object, e As EventArgs) Handles RollButton.Click
    If GameTextBox.Text <= "0" Then
    MsgBox("Number of Games > 0", MsgBoxStyle.Critical)
    Application.Restart()
    End If

    If GameTextBox.Text > "0" Then
    BestOfGamesCounter = Convert.ToInt32(GameTextBox.Text)
    End If


    DisplayDie(PCDice1)
    DisplayDie(PCDice2)
    DisplayDie(PCDice3)

    DisplayDie(YouDice1)
    DisplayDie(YouDice2)
    DisplayDie(YouDice3)
    End Sub

    Private Sub GameTextBox_Validating(sender As Object, e As EventArgs) Handles GameTextBox.TextChanged
    If GameTextBox.Text > "0" Then
    Do
    MsgBox(GameTextBox.Text + " round(s) will be played GOOD LUCK")
    Loop While GameTextBox.Text = "STOP"
    End If
    GameTextBox.Enabled = False
    End Sub
    End Class

    Name:  post-660517-141640467835.jpg
Views: 204
Size:  43.2 KB

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Can Anyone Help Me With Visual Basics Dice Battle Game?

    You have basically said "here's my requirements, here's my code, tell me what I have to do". How about you tell us EXACTLY what issue you want help with instead of expecting us to first find the issues and then fix them for you. Address one issue at a time. Tell us "this is what I expect to happen, this is what I've done, this is what actually happens". Once we've addressed that issue you can mark the thread Resolved and then create a new thread for the next issue.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    3

    Re: Can Anyone Help Me With Visual Basics Dice Battle Game?

    So the problems I'm having are that I cannot get the dice to roll and I can't see the outcome results show up either. What codes do I need to add in order for it to work?

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    3

    Re: Can Anyone Help Me With Visual Basics Dice Battle Game?

    I also forgot to add this to the code since this is part of it:

    Sub DisplayDie(diPictureBox As PictureBox)
    'generate random integer in range 1 to 6
    Dim face As Integer = randomObject.Next(1, 7)

    'retrieve specific die image from resources
    Dim pictureResource = My.Resources.ResourceManager.GetObject(String.Format("die{0}", face))

    'Convert pictureResource to type Image and display in ImageBox
    diePictureBox.Image = CType(pictureResource, Image)
    End Sub

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Can Anyone Help Me With Visual Basics Dice Battle Game?

    Quote Originally Posted by rj125 View Post
    So the problems I'm having are that I cannot get the dice to roll and I can't see the outcome results show up either. What codes do I need to add in order for it to work?
    That's really rather vague. Again, you're basically saying "here's my requirement, I can't do it, you do it for me". What EXACTLY are you expecting to happen? Please don't say "for the dice to roll" because your application isn't actually rolling any dice. It's doing things to simulate a dice roll from the user's perspective. What are you actually expecting the application to do? What code have you written to do that specifically, i.e. just the code relevant to that specific functionality? What actually happens when you do it, including any errors and/or specifically incorrect behaviour, i.e. not just "it doesn't work"? What have you done to try to correct the problem? Have you actually debugged your code? If so, where exactly did the reality diverge from the expectation? If you don't even have code that you can run then where exactly are you stuck?

    Rolling the dice is not a single step. It's comprised of several smaller steps. Which of those are you stuck on? If you don't know then you haven't really thought the whole thing through sufficiently and it's not a surprise that you can't write the code. One of the keys to complex problem solving is breaking a problem down into smaller parts and that's critical to software development. You should have done that part before writing your first line of code. Not necessarily to the Nth degree but certainly moreso than rolling the dice being your smallest unit of work.

  6. #6
    Member
    Join Date
    Oct 2007
    Posts
    63

    Re: Can Anyone Help Me With Visual Basics Dice Battle Game?

    Given that you state you are new to programming you still need to post your code and show that you have attempted to obtain/write a solution even if its way off the mark.
    Many people will not even try to answer if your work shows that you have not attempted the code yourself.

    Creating a GUI doesn't show willing at all, this *ONLY* shows that you placed objects on the form.

    Where is your code for the dice roll?

    Edit: I see that you are displaying a random object from your images but you dont use that objects number anywhere else in the code you supplied.
    How are you keeping track of the numbers?

    You can use a random number generator but this in itself is a minefield.
    Code:
    CInt(Math.Ceiling(Rnd() * n))
    This will generate a number between 0 and n where n is your higher number, but if you do the research you will find that this is not exactly random and becomes predicatable. Also you need to ignore the 0's generated.

    Try doing some yourself then post again.
    Last edited by mickle026; Nov 20th, 2014 at 08:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width