Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA ... Im creating a mahjong game . I'm storing the tile objects in a 3 dimensional array. I need to figure out a way

JAVA ... Im creating a mahjong game . I'm storing the tile objects in a 3 dimensional array. I need to figure out a way to determine which tiles are clickable or not. clickable is defined as.. Clickable is defined A clickable tile does not have a tile on top of it or on either its left or right side.

Below Is the code that im using to draw out my mahjong game board, and then a jpg of how it is currently printing out the game board when i run the game

private void fillGameBoardArray(){

int i=0;

Collections.shuffle(tilesArrayList);

for(int z = 0; z

for(int y = 0; y

for(int x = 0; x

if(boardMap[z][y][x] == 1){

//read board map and place tile onto board at spot

board[z][y][x] = new TileContainer(tilesArrayList.get(i),x,y,z);

System.out.println("board z "+z+"board y "+y +"board x "+x + board[z][y][x].getTile());

i++;

//randomizedTiles.remove(1);

} else {

//or place an empty piece

board[z][y][x] = new TileContainer(false);

}

}

}

}

}

private void drawTiles(){

int zOrder = 0;

for(int z = Z_AXIS - 1; z >= 0; z--){

for(int y = Y_AXIS-1; y >= 0; y--){

for(int x = 0; x

if (board[z][y][x].isTile()){

Tile t = board[z][y][x].getTile();

//Handle Special Cases

if(x==0 && y==4 & z==0){

//Left most tile

t.setBounds(x * (100-30) + (z*10) + 70, y * (100-35) - (z*20) - 30 + 20, 100, 100);

} else if(x==14 && y==3 & z==0) {

//Right most tile

t.setBounds(x * (100-30) + (z*10) + 70, y * (100-35) - (z*20)+30 + 20, 100, 100);

} else if(x==13 && y==3 & z==0) {

//2nd right most tile

t.setBounds(x * (100-30) + (z*10) + 70, y * (100-35) - (z*20)+30 + 20, 100, 100);

} else if(x==6 && y==3 & z==4) {

//Top center

t.setBounds(x * (100-30) + (z*10) + (35) + 70, y * (100-35) - (z*20) + (40) + 20, 100, 100);

} else{

t.setBounds(x * (100-30) + (z*10) + 70, y * (100-35) - (z*20) + 20, 100, 100);

}

setComponentZOrder(t, zOrder);

board[z][y][x].setZOrder(zOrder);

zOrder ++;

System.out.println(t);

final int[] c = {x,y,z};

t.setCoords(c);

t.addMouseListener(new MouseAdapter() {

@Override public void mousePressed(MouseEvent e) {

Tile temp = (Tile)e.getSource();

System.out.println(temp.getParent());

System.out.println(temp.getParent().getComponentZOrder(temp));

if(isClickable(c[0], c[1], c[2])){

{

if(first == null)

{

first = temp;

first.setClicked(true);

repaint();

revalidate();

return;

}

else if(temp==first)

{

temp.setClicked(false);

first=null;

repaint();

revalidate();

return;

}

second = temp;

if(first.matches(second))

{

remove(first);

remove(second);

first=second=null;

repaint();

revalidate();

}

repaint();

revalidate();

}

}

}

});

add(t);

//System.out.println(getComponentZOrder(t));

}

}

}

}

}

}

here is what the gameboard looks like when i run the game.

image text in transcribed

t1 Circle 5 ?1? t1 Circle 5 ?1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions