0

Heads up, I am a beginer so please ignore the fact that I have a limited vocabulary!

So I want to make a game of dominoes. I want to make each domino an object so I can know all the important information (like if it is on the board and if so then where) Basically the code would look like this if I were just creating the numbers for the domino:

for(int x = 12; x >= 0; x--)
{
  for(int y = 0; y <= x; y++)
  {
    Domino domxy = new Domino(x,y);
  }
}

Where "domxy" if x = 12 and y = 0, the name is dom120 giving each domino a unique name.

Sam Hamblin
  • 101
  • 5

1 Answers1

0

Simply create a 2D array of Domino objects like this:

Domino[][] array = new Domino[x][y]

and assign every element like this:

array[x][y] = new Domino(x, y);
ŁukaszG
  • 596
  • 1
  • 3
  • 16
  • Ok so with this solution would it be possible to have different categories of dominoes like InHand, Boneyard, and OnBoard which are subclasses of Domino I failed to mention. With these classes I would have to be able to change the Boneyard domino to a InHand domino if the player drew it. – Sam Hamblin May 19 '15 at 22:23
  • @SaigeHamblin This is not a very object-orientated solution, you could rather create classes for Boneyard and Hand which contain Objects of type Domino. Changing the classes of Objects at runtime is something I would not do in this case. – Jannik Michel May 20 '15 at 07:38
  • If all of your objects are subclasses then yes, u cant just delete old object, create new as subclass and set it to be under main class reference. – ŁukaszG May 20 '15 at 22:32