• Making Monopoly game on Excel spreadsheet

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Making Monopoly game on Excel spreadsheet

    Author
    Topic
    #500591

    Hi

    I have been messing around in my leisure time designing a Monopoly game to be played on an excel spread sheet. It is certainly not Pulitzer prize material but is a challenge to myself if I can do it. It will also be entertaining when completed. Aligning columns and rows while using the color scheme, amazingly it resembles the game board fairly well. I have a data sheet that has all the data for the streets and an Info sheet the has the data for the Chance and Community Chest cards.

    I have been learning VBA slowly by scouring the Internet and picking up tid bits in this forum. Using Randomize and the Rnd function that I picked off from the help menu, I can randomly generate numbers that will pick a card (by the row number) and roll the dice. But that is as far as I got. The board logic seems that it will be mostly be “IF” statements and message boxes for the cards and statistics. I don’t think I will have a problem with that but that will be my next hurdle.

    I want to show an animation of a dice rolling across the board when the user clicks a “ROLL DICE” button. I prefer to do this directly on the sheet as opposed to a user form which was the only solution I found. Back in the day this was easy to do on my Texas Instrument TIAA “something or other” using extended basic and sprites. Is there an equivalent in VBA? Most of what I am reading refers to Visual Basic and gives me error messages when I attempt to run it from Excel.

    If anyone is up for the challenge, you will have at least one captive audience and a salute when I drink down my next beer.

    Thanks,
    Brian

    Viewing 23 reply threads
    Author
    Replies
    • #1511291

      Can you post the code you are using and the error it produces?

      cheers, Paul

    • #1511418

      Good Morning Paul,

      This is one of many I pasted into the module window and tried to run.

      Code:
      Public Function RollDice(value As String) As Integer
              ' setup working variables to make things easier
              Dim tmp As String = ""
              Dim modType As String = ""
              Dim numberOfDice As Integer = 0
              Dim numberOfSidesPerDice As Integer = 0
              Dim modifier As Integer = 0
              ' First we check to see if there is a "d" in the string
              If value.Contains("d") = True Then
                  ' There is so first we need to get the value infront of the d
                  tmp = Field(value, "d"c, 1).Trim
                  ' and convert it to an integer if it's a number, errors are silently
                  ' ignored for now. 
                  If Integer.TryParse(tmp, numberOfDice) = False Then
                      numberOfDice = 0
                  End If
                  ' Now look at the value after the d
                  tmp = Field(value, "d"c, 2).Trim
                  ' does it contain a + or a -?
                  If tmp.Contains("+") = True Then
                      modType = "+"
                  End If
                  If tmp.Contains("-") = True Then
                      modType = "-"
                  End If
                  ' if does not contain a + or a -, then there is no modifer
                  If modType = "" Then
                      ' and we take the right side of the d as the number of sides
                      ' of the dice
                      If Integer.TryParse(tmp, numberOfSidesPerDice) = False Then
                          numberOfSidesPerDice = 0
                      End If
                  Else
                      ' there is a + or a - so we need to extract the number on the left
                      ' side of the +/-
                      Dim bit As String = Field(tmp, CChar(modType), 1).Trim
                      If Integer.TryParse(bit, numberOfSidesPerDice) = False Then
                          numberOfSidesPerDice = 0
                      End If
                      ' now we take the right side of the +/- and set that to the modifier
                      bit = Field(tmp, CChar(modType), 2).Trim
                      If Integer.TryParse(bit, modifier) = False Then
                          modifier = 0
                      End If
                  End If
              Else
                  ' Ah so there is no d so we assume it's not a forumlar, just a number
                  numberOfDice = 0
                  numberOfSidesPerDice = 0
                  If Integer.TryParse(value, 0) = True Then
                      modifier = 0
                  Else
                      modifier = 0
                  End If
              End If
       
       
              ' Now comes time to roll the dice
              Dim lp As Integer
              Dim total As Integer = 0
              ' Set up a random object randomised by the syystem date and time
              Dim objRandom As New System.Random(CType(System.DateTime.Now.Ticks Mod System.Int32.MaxValue, Integer))
              ' loop through the number of dice
              For lp = 1 To numberOfDice
                  ' add each roll to the total
                  total = total + CInt(objRandom.Next(numberOfSidesPerDice) + 1)
              Next
              ' now modify the total if needed
              If modType = "+" Then
                  total += modifier
              ElseIf modType = "-" Then
                  total -= modifier
              End If
              ' we have the results of the dice roll
              Return total
          End Function
       
          ' Using the delimiter to split the string into chunks, return the pos chunk
          ' e.g. Field("1d6+1","d",2) would return "6+1"
          Public Function Field(ByVal sourceString As String, ByVal delimiter As Char, ByVal pos As Integer) As String
              Dim parts() As String = sourceString.Split(delimiter)
              If pos > parts.Length Then
                  Return ""
              Else
                  Return parts(pos - 1)
              End If
          End Function
       

      It seems that most descriptions of the graphics is stationary dice with flipping faces that eventually stop at some combination of numbers

      Thanks Brian

      • #1511444

        Good Morning Paul,

        This is one of many I pasted into the module window and tried to run.

        Code:
        Public Function RollDice(value As String) As Integer
                ' setup working variables to make things easier
                Dim tmp As String = ""
                Dim modType As String = ""
                Dim numberOfDice As Integer = 0
                Dim numberOfSidesPerDice As Integer = 0
                Dim modifier As Integer = 0
                ' First we check to see if there is a "d" in the string
                If value.Contains("d") = True Then
                    ' There is so first we need to get the value infront of the d
                    tmp = Field(value, "d"c, 1).Trim
                    ' and convert it to an integer if it's a number, errors are silently
                    ' ignored for now. 
                    If Integer.TryParse(tmp, numberOfDice) = False Then
                        numberOfDice = 0
                    End If
                    ' Now look at the value after the d
                    tmp = Field(value, "d"c, 2).Trim
                    ' does it contain a + or a -?
                    If tmp.Contains("+") = True Then
                        modType = "+"
                    End If
                    If tmp.Contains("-") = True Then
                        modType = "-"
                    End If
                    ' if does not contain a + or a -, then there is no modifer
                    If modType = "" Then
                        ' and we take the right side of the d as the number of sides
                        ' of the dice
                        If Integer.TryParse(tmp, numberOfSidesPerDice) = False Then
                            numberOfSidesPerDice = 0
                        End If
                    Else
                        ' there is a + or a - so we need to extract the number on the left
                        ' side of the +/-
                        Dim bit As String = Field(tmp, CChar(modType), 1).Trim
                        If Integer.TryParse(bit, numberOfSidesPerDice) = False Then
                            numberOfSidesPerDice = 0
                        End If
                        ' now we take the right side of the +/- and set that to the modifier
                        bit = Field(tmp, CChar(modType), 2).Trim
                        If Integer.TryParse(bit, modifier) = False Then
                            modifier = 0
                        End If
                    End If
                Else
                    ' Ah so there is no d so we assume it's not a forumlar, just a number
                    numberOfDice = 0
                    numberOfSidesPerDice = 0
                    If Integer.TryParse(value, 0) = True Then
                        modifier = 0
                    Else
                        modifier = 0
                    End If
                End If
         
         
                ' Now comes time to roll the dice
                Dim lp As Integer
                Dim total As Integer = 0
                ' Set up a random object randomised by the syystem date and time
                Dim objRandom As New System.Random(CType(System.DateTime.Now.Ticks Mod System.Int32.MaxValue, Integer))
                ' loop through the number of dice
                For lp = 1 To numberOfDice
                    ' add each roll to the total
                    total = total + CInt(objRandom.Next(numberOfSidesPerDice) + 1)
                Next
                ' now modify the total if needed
                If modType = "+" Then
                    total += modifier
                ElseIf modType = "-" Then
                    total -= modifier
                End If
                ' we have the results of the dice roll
                Return total
            End Function
         
            ' Using the delimiter to split the string into chunks, return the pos chunk
            ' e.g. Field("1d6+1","d",2) would return "6+1"
            Public Function Field(ByVal sourceString As String, ByVal delimiter As Char, ByVal pos As Integer) As String
                Dim parts() As String = sourceString.Split(delimiter)
                If pos > parts.Length Then
                    Return ""
                Else
                    Return parts(pos - 1)
                End If
            End Function
         

        It seems that most descriptions of the graphics is stationary dice with flipping faces that eventually stop at some combination of numbers

        Thanks Brian

        Does Excel actually run that code or does it fail when you try to compile it?

        That doesn’t look like VBA to me – it just looks like a chunk of VB code that’s been pasted into Excel and therefore won’t ever work!

        It might actually be easier if you wrote a short bit of pseudo-code describing what it is you’re trying to do 🙂

    • #1511429

      I don’t have Excel so you’ll have to wait for someone else to give it a whirl.

      cheers, Paul

      • #1511436

        I don’t have Excel so you’ll have to wait for someone else to give it a whirl.
        cheers, Paul

        Do you have the free LibreOffice? It has worked with a number of .xls files I’ve opened in it, latest versions even work with files from Office 2007 and later with the x added to the extension.
        http://www.openoffice.org

        Before you wonder "Am I doing things right," ask "Am I doing the right things?"
        • #1511599

          Do you have the free LibreOffice?

          Yep, but it doesn’t run VBA (it does sometimes).

          cheers, Paul

    • #1511447

      Hi Brian

      ..I knocked up this dice roller for Excel2007, 2010, 2013, 2016.
      It’s a first version.

      You could adapt it for your game.

      (I tested it also works for Excel2003 – just save it in .xls format)

      zeddy

      • #1511851

        Zeddy,

        You are a rockstar. Every time I read this forum, you seem to have something cool to share!
        When I saw this thread highlighted in WindowsSecrets, I thought someone would come up with either an animated GIF or, a solution based on Excel’s Camera tool.

        Yours is a cool hybrid of those. I’ve seen the camera in action (on Chandoo.org) but I can’t “picture” using it for a dice-roller, can you?

        Cheers,

        Mitch

        • #1511855

          Hi Mitch

          ..many thanks for the compliment!
          ..yes, I thought about using the camera tool and animated gifs.
          I’m still working on some things before posting back on this thread.
          I’m testing moving my ‘scottie dog’ and ‘top hat’ around too.

          zeddy

    • #1511553

      To answer your question Jeremy, I couldn’t get that specific code to run. It was stated to be VB but one of the few that was described as “Rolling dice with movement”.

      Thank you zeddy for your sample. It is the nicest one that I found that uses VBA. I would like the dice to move across the board if possible as if someone was throwing them. Could yours be adapted?

      • #1511643

        Hi Brian

        ..it can be done. What does your board look like?????

        Note:
        In my example file, you may notice that occasionally only one of the two dice will show.
        There is a mathematical reason for that.
        ..but I count it as ‘throwing the dice and one falls off the Board’.

        zeddy

    • #1511669

      You are a comedian Zeddy :rolleyes:

      The screen looks just like a Monopoly Board. I have a 4:3 aspect ration screen and it fits perfectly in that view.

      Thanks,
      Brian

      • #1511673

        Ok Brian

        ..you found me out!

        But, seriously, I wanted to know between what columns, and what rows, you wanted to have the dice ‘roll’.
        And is your zoom level set to 100%???
        And whether you see the ‘whole’ board on the screen, or if you have to ‘scroll’??

        I’ll work on the basis that everything fits into the display window then.

        zeddy

    • #1511695

      zeddy

      Here is my game board. I see the entire board at 90% and just the lower edge is missing at 100%. If I had a preference, the dice would come in from the lower left and rest somewhere in the center of the board.

      Now if a dice happens to accidently go off the table, we’ll just have to roll again.

      B.

      41153-Untitled

    • #1511728

      Doesn’t this break copyright laws? Just wondering…..

      Eliminate spare time: start programming PowerShell

    • #1511732

      Hi a-mdb,

      I do not plan on making any profits or distribution of my project. The board was generated not from a picture but from my design and work of an Excel spreadsheet which was not copied from another’s efforts. The code behind it that will give it functionality will be the result of my authoring and the help I get from this forum.

      IMHO, this would not be a copyright infringement but I do not claim to be a patent lawyer.

      Brian

    • #1511813

      Copyright law is a minefield. For example, you cannot take a photo of the Eiffel Tower at night when it’s lit up and use it commercially – and if the photographer puts it on, say, Facebook, she is then breaking the law (crazy but true). It’s up to the mods on this forum to decide if the Lounge might be at risk here – by getting advice about it. I’d hate it if it came a cropper over something like this. As I said, copyright law is a minefield.

      On the other hand, Hasbro may well come visiting you to buy the code…..

      Eliminate spare time: start programming PowerShell

    • #1512012

      Brian,

      Here is my attempt to do what you want to happen. I copied an image of the board unlike the fine job you did with constructing yours. Click the roll button. The dice roll in from the bottom and travel upward to the right. They bounce of the walls the produce a random combination. I was looking for a descent sound file of rolling dice and will add it if you like when I find one.

      HTH
      Maud

    • #1512016

      FYI: I have a Monopoly game on my Kindle Fire by Electronic Arts. Must be sanctioned as it has all the copyrighted images. :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1512155

      This is perfect Maudibe! Thank you to you and zeddy for all your help. I will leave this post open because I know zeddy was working on something.

      Great Forum
      Brian

      • #1512830

        Hi Brian

        I’ve been tied up with multi-dimensional tesseracts.
        ..But here is what I’ve got so far on moving pieces.
        more to follow when I get a chance.

        zeddy

    • #1512903

      Hey Zeddy,

      Nicely done!! While you were working on animating the game pieces, I was working on animating the picking of a chance card. Click the Chance button and the top Chance card will slide off the top of the pile, rotate 3-D and display the message. The Reset button places it back in the pile.

      XLD, you will have to add the code to the SetText Routine to select the message to display on the card.

      HTH,
      Maud

      41214-Monopoly1

      • #1513174

        Hi Brian

        This is it so far..
        ..I tweaked Maud’s code, and added some Chance cards.
        ..haven’t done anything on moving pieces.

        Some time ago I did a post that ‘translated Excel sheets and tabs’ according to language selected.
        I used the same technique for the ‘flags’ alongside the Board.
        Click and see the results.

        zeddy

    • #1512956

      Is there anything you guys can’t do with visual basic?

      These animations are fantastic!!!! I have been working on the logic of the game but I will need time to digest your codes and integrate them. I am anticipating that I will be able to just branch to your routines. Hope you will not mind if I have some questions. Seems like things are more complicated then my early days of extended basic but I am figuring it out.

      With the dice rolling, movement of the pieces, and the animated display of cards, this project is becoming even more interesting. Keep it coming.

      Thanks,
      Brian

      • #1513024

        Hi Brian

        ..please keep this thread open. I’m tweaking some more stuff. Maud’s twirling cards are magnificent.

        zeddy

    • #1514213

      What a great marketing Strategy Zeddy!

      Got rid of the buttons to turn over the card. Now just click on the Chance card to read it then click on it again to return it to the deck. The cursor will change to a pointing finger while hovering over the cards. Some also added code that will prevent the same card from displaying twice until the deck is reshuffled.

      Maud

    • #1514400

      Sorry for not responding sooner as I just got back from my vacation and what a treat I came back to!

      Thank you zeddy for the international selections. This is so clever. The game could be personalized to any situation. You set up your board very similar to the way I have so I am considering just using your board if you do not mind with some of your code as well as Maudibe’s Chance cards and rolling dice. My initial plans were to move the pieces to the different cells by the use of a table. Very interested on what you come up with on moving the tokens.

      Thanks Maudibe for your animations. The selection of the Chance cards with a finger cursor gives it a real sense of actually picking the card. I see you placed an invisible object on top. I am assuming because you can click it and have an action of some sort. I need to study this more.

      I have been working on the behind the scenes logic and forms that represent the deed cards. Very please with how it has developed so far. Now to integrate all this great stuff that you guys did.

      Thanks again,
      B

      • #1514481

        Hi Brian

        ..glad you liked the flags. I figured with you in Vancouver, Maud and RG in the USA, and me currently in UK, it would make it more interesting to have familiar names on the Board.

        I have been playing with moving pieces on the Board. Currently, I have the dog hopping from square to square (along, up, across and down etc etc). I thought it would be nicer to have the pieces ‘move’ on the squares, rather than just ‘beam-up-scotty’ to the destination square.
        Will post an updated copy when I’ve linked the moves to the dice throw. Maybe tomorrow.

        zeddy
        •Environmental Emergencies Planner

    • #1514551

      This is getting out of hand. 🙂

      cheers, Paul

      • #1514571

        ..having a project like this is a great way of learning all sorts of vba stuff.
        It will also require a lot of thinking about methods, rules, processes etc etc etc.

        zeddy
        •Nightclub Eviction Enforcer
        .

    • #1514567

      Yeah……aint it cool!!!!

      • #1514586

        Hi Brian

        Here’s the progress so far. I added Maud’s card-pointer for the Chance cards. Great idea.

        I’ve linked the dice to player, and to move their corresponding piece.

        I have not done anything with regard to the rules, i.e. if player lands on ‘Goto Jail’, I haven’t implemented that. Or if a player lands on Chance etc etc etc. Also, I haven’t done anything with regard to collecting money as you pass Go etc, or purchasing of property, or collecting rent etc etc.

        At some stage, we would need to see what other Players ‘have’, in the way of money, property, houses etc. So I added a sheet [B]Players[/B] where this info could be kept. And, using Excel’s camera tool, I took a ‘snapshot’ of this Player data-block, to show as a ‘picture’ on the main Board, when you click the [Show/Hide Player info] button.

        So, more input from others then?

        zeddy
        •Curfew Compliance Host

    • #1514645

      zeddy, CCH

      Well that is mighty cool! Played with it for a while walking through the code using F8. I believe I have a good grasp. Very Nice. Thanks a bunch!

      I have already taken care of the setup, rules, deeds, money distribution, players and their tokens which is all part of the logic that I am near completing. They will display on what I am calling the slate. You can leave that part to me.

      Maudibe, would it be possible to duplicate your animation for the Community chest cards? After that, I should be good.

      Thank you both zeddy and Maud for your talent.

      B

      • #1514839

        Very Interesting Project on Excel

        As mentioned by you -Maud & Zeddy have contributed enormously

        Please post you final product

    • #1514721

      XLD,

      Here is the code for the Community Chest Cards. You can see the objects you will need to copy over in the selection pane. If you need help, zeddy and I as well as the rest of the forum are ready to jump in. Post the game when you get it completed.

      Maud

      P.S. Zeddy..Well done with the moving pieces. Top Marks!

      41308-Monopoly2

    • #1514771

      Maud this is awesome! That’s just so wild. Thank you so much

      zeddy- I have been examining your code for the moving pieces. Can you explain why you chose to zigzag when moving. Was this to create an affect or was it a necessary step for the movement?

      Thanks for all your help
      B

      • #1514838

        Hi Brian

        explain why you chose to zigzag when moving

        ..I couldn’t help myself. It’s in my grizzly enzymes. It’s in my name. I zigged and zagged (to give a 3-d effect), rather than just whizzing along the sides. I also zoomed the pieces (when moving left along the bottom). I thought I’d add some pizzaz by resizing the pieces. After analyzing, turned out it was a breeze to move the pieces. I enjoyed the challenge of the puzzle, and was unfazed by Excel features I hadn’t utilized in a while. I was going to change the monopoly car for a midsize guzzler, but decided that would be bizarre. I’m working on some other jazzy features that I hope will dazzle you. My head is buzzing with a zillion ideas to make it zippier. Time for a pizza. (I could have a dip in a Jacuzzi – but that’z enuff zzzzzzz’z)

        zeddy
        •Genetic Baggage Handler
        .

    • #1515218

      This is absolutly brilliant, just proves the talents and vast Excel knowledge of the forum members.

      • #1515227

        Absolut???
        ..how did you know I was drinking vodka?????

        zeddy
        •Drain Surgeon
        .

    • #2410607

      Well done Brian, I’ve been doing the same thing for MONOPOLY GB London Board and it depends which Version of Excel your programming. The 2007 is the best Version and you run your code by Allowing MACROs to be recorded. I’ve found that because Microsoft changes the OS system every year so I have to change computers to the Latest HP Stream Laptop on Windows 7, 32-bit, and I’ve found an alternative to Microsoft Office which is Apache Open Office BASIC. It’s very similar to VBA and takes a bit of getting used to, but you should find the Syntax easy enough. I found it takes about 7,000 lines of Coding and to put a 6 PLAYER game into 6 MODULES.
      But even now I’m running into problems of how to go from one player to another and to take the token around the board from the numbers shown on the DICE which is to generate 6 random numbers and add them twice to give a total of 12 on the dice. If it’s a double, to take another turn.
      Also to work out the LEVELS of rent for each property, and how many colour groups you’ve got getting frustated. I hope you find this useful. At least I’m not on my own. That somebody else is doing this.

      • #2419106

        I have enjoyed reading this again!

        We now need to include the new Monopoly Speed Dice (the ones with Buses on!)

        zeddy

    Viewing 23 reply threads
    Reply To: Reply #1514567 in Making Monopoly game on Excel spreadsheet

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel