none
Help with Small Basic program RRS feed

  • Question

  • Hi,

    I am trying to make a Monopoly game in Small Basic TextWindow. I have declared the 2d arrays for the squares, chance and community chest. What should my game loop be like? Inside the game loop, the program has to show the board, input some key (to roll the dice), then show the player's statistics (which are stored in an array). It will also show the square he is on, and if it is owned by the other player (my plan is to make a 2-player game) will try to deduct the rent. If he has no rent, it will sell one of his properties and calculate the remainder. It should also do the necessary if he ends up in a special square like community chest, chance, go to jail and go. Please help.

    Thanks,

    Rahul Yedida

    Thursday, May 3, 2012 10:27 AM

Answers

  • Here are some things that I think might help, and how I would approach the problem...

    In your mind separate the game from the display of the game.

    That means, in your code, the main game loop would look something like this:

    While playing
      TakeTurn()
      UpdateDisplay()
      Continue()
    EndWhile

    TakeTurn() is where you play out the turn, in the computer's "mind", modifying all the relevant game status variables: e.g. roll the dice, move the player on, pay any charges, buy property, react to special squares, etc.

    UpdateDisplay() is where you show the current status of the board, based on all the relevant game status variables, and anything else you want to display.

    Continue() is where you check if the game should continue, i.e. does player want to take the next turn, has a player gone bankrupt?

    Also, I would just use single-dimension arrays...

    I'll see if I can knock up a quick code example that demonstrates the core game framework like I have suggested.





    Sunday, May 6, 2012 9:41 PM
  • Rahul,

    OK. This is my sample for you.

    DFZ772


    Nonki Takahashi


    Monday, May 7, 2012 7:14 AM
    Moderator

All replies

  • Game loop may be

    nextgame = "True"
    While nextgame
      ' Prepare the game
      ' Start the game
      continue = "True"
      While continue
        ' Play by player 1
        If continue Then
          ' Play by player 2
        EndIf
      EndWhile
      ' Game ending
      ' Ask next game
    EndWhile
      


    Nonki Takahashi


    Thursday, May 3, 2012 2:43 PM
    Moderator
  • Rahul,

    This is my guess that Monopoly will become a few or several hundred lines of program or far bigger.  I recommend you to begin writing a small program which can run.  When you repeat to add a small part and debug, that is easier to develop than write a lot at a time.

    And my first recommendation is to write a program to show the initial board of Monopoly.  Or design screen image such as



    Nonki Takahashi

    Friday, May 4, 2012 1:04 PM
    Moderator
  • Hi Nonki,

    1. It has already reached over 100 lines of code just to store the information about the squares in 2d arrays. I have also stored the player's initial information.

    2. In the board you have shown, it would be hard to find out where the player is. So I have taken another approach, but I found it impossible to mark the players' positions:

    11 12 13 14 15 16 17 18 19 20 21

    10                                       22

    9                                         23

    8                                         24

    7                                         25

    6                                         26

    5                                         27

    4                                         28

    3                                         29

    2                                         30

    GO 40 39 38 37 36 35 34 33 32 31

    Somewhat like this.


    • Edited by rahuly1039 Saturday, May 5, 2012 7:18 AM
    Saturday, May 5, 2012 7:09 AM
  • Here are some things that I think might help, and how I would approach the problem...

    In your mind separate the game from the display of the game.

    That means, in your code, the main game loop would look something like this:

    While playing
      TakeTurn()
      UpdateDisplay()
      Continue()
    EndWhile

    TakeTurn() is where you play out the turn, in the computer's "mind", modifying all the relevant game status variables: e.g. roll the dice, move the player on, pay any charges, buy property, react to special squares, etc.

    UpdateDisplay() is where you show the current status of the board, based on all the relevant game status variables, and anything else you want to display.

    Continue() is where you check if the game should continue, i.e. does player want to take the next turn, has a player gone bankrupt?

    Also, I would just use single-dimension arrays...

    I'll see if I can knock up a quick code example that demonstrates the core game framework like I have suggested.





    Sunday, May 6, 2012 9:41 PM
  • Here is the core framework that I suggested.

    I'm afraid it seems I may have coded too much for you, as all you'd need to do is fill in the blanks. ;)

    I haven't played Monopoly for years, but I think this code elucidates the way I'd implement all the key points.

    This is a two-player demo that observes the following rules.

    • Game runs until a player goes bankrupt or quits.
    • Players start off with £2600
    • Player gets £200 for passing go
    • Player buys every free property they land on
    • Board squares 1, 3 & 8 have been marked as special squares, so players can't buy these.
    • Property purchase costs are assigned randomly
    • Property rent charges are assigned randomly

    At the end of each turn the display is updated to show their bank balance and which properties the players own.

    Because the costs and charges are being assigned randomly: some games a player will go bankrupt, other times they can co-exist happily. :)

    Program Import ID: ZCF870

    PS. I think it would be simpler to implement a graphics window, instead of a text window, for this.



    • Edited by EzyMCP Sunday, May 6, 2012 11:06 PM
    Sunday, May 6, 2012 11:03 PM
  • Rahul,

    OK. This is my sample for you.

    DFZ772


    Nonki Takahashi


    Monday, May 7, 2012 7:14 AM
    Moderator
  • Hi EzyMCP,

    Thank you for your help. I was just wondering which would be easier to program - one sub for everything in TakeTurn, or different subs for activites like rolling dice.

    Also, what is the advatage of using 1d arrays? For example, I have programmed the squares like this:

    info[13]["Location"] = "Mars"

    info[13]["Price"] = 500

    info[13]["Owner"] = "None"

    so on, and I thought during gameplay if something happens (like if someone buys the place) I would change the values. Just tell me if I am wrong somewhere in my idea.

    Thanks,

    Rahul

    Tuesday, May 8, 2012 3:37 AM