Consulting

Results 1 to 18 of 18

Thread: Creating simple games in Excel

  1. #1

    Question Creating simple games in Excel

    I am hoping someone could please give me some direction on getting started using rand, randbetween countif, vlookup and anything else to create a game. I am however familiar with the functions, well not too familiar I just need to know how to get started, I have no clue for flipping coins, dice, or card games, I am at a total loss.

    I just need to be pointed in the right direction to at least get started. Thanks in advance for any assistance anyone can provide.


  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi,

    Did this link not help any?

    Do you have a sample file? Here you can upload a file to the board. It must be zipped, while in the reply page (hit Alt + X from here) scroll down to Manage Attachments and Browse.. and Upload file. An example may help anybody reading this.

  3. #3
    Hi,

    I think that is my issue, I have no clue how to get started. I wished I had an example to post but I have nothing....I guess it's off to the book store to see what is available. This is definitely more programming than I would have expected in an intro Excel class.

    Thanks again!

    Quote Originally Posted by firefytr
    Hi,

    Did this link not help any?

    Do you have a sample file? Here you can upload a file to the board. It must be zipped, while in the reply page (hit Alt + X from here) scroll down to Manage Attachments and Browse.. and Upload file. An example may help anybody reading this.

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Dim Highest As Long
    Dim Lowest As Long
    Randomize
    Choice = Int((Highest + 1 - Lowest) * Rnd + Lowest)

    Just assign the values to "Highest" and "Lowest" as needed. 1 to 2 for coin, 1 to 6 for dice (six sided) etc.

  5. #5

    Wink

    Excellent, this should get me started in the right direction. Thanks alot. I will keep you up on my progress.

    Teko

    Quote Originally Posted by DRJ
    Dim Highest As Long
    Dim Lowest As Long
    Randomize
    Choice = Int((Highest + 1 - Lowest) * Rnd + Lowest)

    Just assign the values to "Highest" and "Lowest" as needed. 1 to 2 for coin, 1 to 6 for dice (six sided) etc.

  6. #6
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

  7. #7
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Maybe we have a candidate here, DRJ?
    ~Anne Troy

  8. #8

  9. #9
    VBAX Regular
    Joined
    Jul 2004
    Location
    Wellington, New Zealand
    Posts
    37
    Location
    Hi heres an example of single player Yahtzee I have built - run the PlayYahtzee macro. Its still work in progress but it gives you an idea.

    Stromma from MrExcel board has recently built a nice multi-player Yahtzee one with Swedish rules which is well done with sounds etc and I believe he's looking for testers. Send him a PM on MrExcel and Im sure he wouldnt mind giving you a copy.

  10. #10
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Stromma is also a member here.

    http://www.vbaexpress.com/forum/member.php?u=81
    ~Anne Troy

  11. #11

    Red face

    Ok, I was clowing around with a simple game and ran into a problem. Instead of either the "Heads or Tails" buttons actually perform calculations could I not instead have another button that performs the same as F9?

    I know the game is ugly but hey, this is my first go at it. Any insight assistance, whatever would be nice.

    Thanks all!

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Ants

    Hi Teknologist,
    Here's somthing, not exacatly a game, but it may be of interest to try variations. The "ant" steps in a cell, if red, he turns it black and goes left, if Black, he turns it Red and goes left. Be patient until he "settles down".
    MD

  13. #13
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi,
    I've had a play around and added some code to introduce you to some other possibilities, changing colours and fonts, keepng score, calling other routines etc. Sorry I've no time to Comment it properly, but if you step through, I'm sure you can follow what's happening.
    MD
    Sub Tails()
        Range("B1").Formula = "T"  'Set the call
        Flip  ' Do the flip
    End Sub
     
    Sub Heads()
        Range("B1").Formula = "H"
        Flip
    End Sub
     
    Sub Flip()
        Dim Success As Boolean
        Dim MyFlip As Double
        
        Randomize
        MyFlip = Rnd    'Random number between 0 & 1
        If MyFlip > 0.5 Then
            Range("B2").Formula = "Tails"
        Else
            Range("B2").Formula = "Heads"
        End If
        'Compare first letter of Result weith Guess
        If Left(Range("B2"), 1) = Range("B1") Then   'Win
            With Range("B3:C3")
                .Interior.ColorIndex = 6
                .Font.Name = "Arial"
                .Font.FontStyle = "Bold Italic"
                .Font.Size = 14
            End With
            With Range("B3")
                .Formula = "You win !!!"
            End With
            
            Success = True   'for keeping score
        Else                                    'Lose
            With Range("B3:C3")
                .Interior.ColorIndex = 8
                .Font.Name = "Arial"
                .Font.FontStyle = "Bold"
                .Font.Size = 12
            End With
            With Range("B3")
                .Formula = "Sorry, you lose."
            End With
    Success = False
         End If
        ' Call another routine to keep score    
         CountScore Success
    End Sub
     
    Sub CountScore(Success)
    'Set up the cell format    
        Range("B8").NumberFormat = "0 ""wins"""
        Range("B9").NumberFormat = "0 "" losses"""
    'Make sure there's a numeric value    
        If Range("B8") = "" Then Range("B8").Formula = 0
        If Range("B9") = "" Then Range("B9").Formula = 0
    'Change the score by the result "passed" by the Success parameter    
        If Success = True Then
            Range("B8").Formula = Range("B8") + 1
        Else
            Range("B9").Formula = Range("B9") + 1
        End If
    End Sub

  14. #14
    Whew, yup, definitely gottah have patience. I will attempt playing with it after class tonight, if not too late...

    Thanks for sharing.

    Did you get the chance to look at mine?

    Quote Originally Posted by mdmackillop
    Hi,
    I've had a play around and added some code to introduce you to some other possibilities, changing colours and fonts, keepng score, calling other routines etc. Sorry I've no time to Comment it properly, but if you step through, I'm sure you can follow what's happening.
    MD
     Sub Tails()
         Range("B1").Formula = "T"  'Set the call
         Flip  ' Do the flip
     End Sub
      
     Sub Heads()
         Range("B1").Formula = "H"
         Flip
     End Sub
      
     Sub Flip()
         Dim Success As Boolean
         Dim MyFlip As Double
         
         Randomize
         MyFlip = Rnd    'Random number between 0 & 1
         If MyFlip > 0.5 Then
             Range("B2").Formula = "Tails"
         Else
             Range("B2").Formula = "Heads"
         End If
         'Compare first letter of Result weith Guess
         If Left(Range("B2"), 1) = Range("B1") Then   'Win
             With Range("B3:C3")
                 .Interior.ColorIndex = 6
                 .Font.Name = "Arial"
                 .Font.FontStyle = "Bold Italic"
                 .Font.Size = 14
             End With
             With Range("B3")
                 .Formula = "You win !!!"
             End With
             
             Success = True   'for keeping score
         Else                                    'Lose
             With Range("B3:C3")
                 .Interior.ColorIndex = 8
                 .Font.Name = "Arial"
                 .Font.FontStyle = "Bold"
                 .Font.Size = 12
             End With
             With Range("B3")
                 .Formula = "Sorry, you lose."
             End With
    Success = False
          End If
         ' Call another routine to keep score    
          CountScore Success
    End Sub
      
     Sub CountScore(Success)
     'Set up the cell format    
         Range("B8").NumberFormat = "0 ""wins"""
         Range("B9").NumberFormat = "0 "" losses"""
     'Make sure there's a numeric value    
         If Range("B8") = "" Then Range("B8").Formula = 0
         If Range("B9") = "" Then Range("B9").Formula = 0
     'Change the score by the result "passed" by the Success parameter    
         If Success = True Then
             Range("B8").Formula = Range("B8") + 1
         Else
             Range("B9").Formula = Range("B9") + 1
         End If
     End Sub

  15. #15
    VBAX Regular
    Joined
    Jun 2004
    Location
    The Netherlands
    Posts
    34
    Location
    here another link with some simple examples:
    http://www.erlandsendata.no/english/...ndownloadgames

  16. #16
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Some of those are pretty good. I really like the Calculate Your Bonus joke User Form.

  17. #17
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi.
    You could try making up a two player verion of Reversi for an excel spreadsheet;
    challenging, but not too "heavy" on ther coding front
    MD

  18. #18
    MS Excel MVP VBAX Regular Ken Wright's Avatar
    Joined
    Jun 2004
    Posts
    17
    Location
    Tekno, if you are looking for a very very simple example for your intro class, then the attached modification of your file may help. Uses VBA to give a Heads/Tails result, and then Conditional formatting and a formula to display whether they have won or not.

    Regards
    Ken.............
    It's easier to beg forgiveness than ask permission

Posting Permissions

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