Sharing variables and code architecture

This is a discussion on Sharing variables and code architecture within the C++ Programming forums, part of the General Programming Boards category; Hello all, I am trying to decide how to structure my code for a simple "ball and hole" game. In ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    27

    Sharing variables and code architecture

    Hello all,

    I am trying to decide how to structure my code for a simple "ball and hole" game. In this game, there is a table with several holes in it. The object of the game is to tilt the table along 2 axes to guide a ball into one of the holes, while avoiding the others.

    I am going to create a class for the ball and one for the table. There are several variables that are needed by both the ball and the table.
    These variables include:
    current rotation around the axes
    boundaries for table (we do not want to ball to roll into infinity, and we need this to draw the table too)
    location of the holes (used to draw holes on table, and lets ball know when it should stop rolling along the top of the table and start falling into the hole)

    What is the best way to structure the code so those variables are available to both the ball and the table?

    Thanks,
    JackR

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    The ball probably doesn't need to know much about the world. When you update its movement, you can pass the tilt as an argument. To do collision detection against the walls and holes, you might ask it for its coordinates.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    Seems to me that you just need a 'table' object and a 'ball' object, probably declared inside the table object? You should be able to manipulate the position of the ball based on the position of the table. Both objects will probably need x,y coordinates (not shared), unless you want to make an object that just holds coordinates?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reusing code blocks for different variables
    By Queue in forum C Programming
    Replies: 16
    Last Post: 09-16-2006, 12:34 PM
  2. forking and sharing variables
    By Boomba in forum C Programming
    Replies: 2
    Last Post: 11-20-2005, 08:09 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. Replies: 2
    Last Post: 09-10-2001, 01:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21