Thread: Sharing variables and code architecture

  1. #1
    Registered User
    Join Date
    Sep 2006

    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?


  2. #2
    The larch
    Join Date
    May 2006
    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
    Euless, TX
    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, 11:34 AM
  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
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. Replies: 2
    Last Post: 09-10-2001, 12:00 PM