-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
I need to access shape from currentPiece.shape
Where is the shape variable defined?
Quote:
pass currentPiece.shape into the MatrixMultiplication method.
Again where is the variable shape defined?
Code :
case KeyEvent.VK_DOWN: // down arrow
case KeyEvent.VK_KP_DOWN:
currentPiece.rotateClockwise();
Here the code calls a rotate method in the currentPiece object.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
it's defined in Grid, but the variable name is different in Grid.
Code :
public class Grid extends JComponent {
public int contents[][]; // contents = shape
It's defined as shape. However, setting a getter method in Grid won't help as currentPiece is a Piece object...
Can you take a look at the code and tell me how I think I should implement the rotation method based on the data structure and the class structure?
--- Update ---
Quote:
Originally Posted by
Norm
Here the code calls a rotate method in the currentPiece object.
Yeah, I have a question on that. Since it doesn't pass currentPiece as an argument. How do they expect us to modify currentPiece with rotateClockWise()?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
defined in Grid, but the variable name is different in Grid.
The name of the variable can not change from a base class to an extending class. If the variable names are different, then the variables are different.
Quote:
It's defined as shape
Can you copy the code that defines a class variable named shape? I'm having a hard time finding it.
Quote:
setting a getter method in Grid won't help as currentPiece is a Piece object...
What class does the Piece class extend? Do you understand what it means when a class extends another class?
Quote:
implement the rotation method
Define what you mean by "rotation". Post an example array before it is rotated and after it is rotated and explain the steps that were taken to do the rotation.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
Originally Posted by
Norm
The name of the variable can not change from a base class to an extending class. If the variable names are different, then the variables are different.
Can you copy the code that defines a class variable named shape? I'm having a hard time finding it.
What class does the Piece class extend? Do you understand what it means when a class extends another class?
Define what you mean by "rotation". Post an example array before it is rotated and after it is rotated and explain the steps that were taken to do the rotation.
Piece calls super(shape). Piece extends Grid, which has a constructor that takes shape and turn it into contents.
Shape isn't declared anywhere. The class variable shape doesn't exist, because Piece inherits contents (or shape, it's under a different name)
matrixMultiplication is supposed to do:
1 0 0
1 0 0
1 1 0
X
0 0 1
0 1 0
1 0 0
=
0 0 1
0 0 1
0 1 1
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
What are the steps for the rotation? Can you list the steps for doing the "rotation"?
Your post looks like it multiplication: A x B = C Two operands and an operator generates a product
How does that relate to "rotation"? I was expecting two arrays: one before and one after the rotation.
Quote:
constructor that takes shape and turn it into contents.
From what you have said, the variable contents in the Grid class seems to be the "shape" you are talking about.
Does the rotateClockwise() method in the Piece class do what you want? Or at least work on the data that you want to change?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
Originally Posted by
Norm
What are the steps for the rotation? Can you list the steps for doing the "rotation"?
Your post looks like it multiplication: A x B = C Two operands and an operator generates a product
How does that relate to "rotation"? I was expecting two arrays: one before and one after the rotation.
From what you have said, the variable contents in the Grid class seems to be the "shape" you are talking about.
Does the rotateClockwise() method in the Piece class do what you want? Or at least work on the data that you want to change?
It just multiply the 2d array with a predefined 2d array to get the product of their matrices and instead of a value between 0 and max int value we get either 1 or 2. I posted the code already.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Does the rotateClockwise() method in the Piece class do what you want? Or at least work on the data that you want to change?
Quote:
I posted the code already.
Does that mean you have the code that does the rotation?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
I didn't implement the rotateClockwise method, because I can't access any of the variables as I said.
I only have the code that does matrix multiplication. I can't use it, because I can't modify the shape attribute of currentPiece. Did you look at the codes?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
I didn't implement the rotateClockwise method, because I can't access any of the variables as I said.
There is a rotateClockwise() method in the Piece class. What is wrong with that?
Be more specific than "any of the variables". Where are you trying to call that method? What variables do you need access to?
Quote:
I can't modify the shape attribute of currentPiece.
Please use variable names and class names when talking about your problem. There is no variable: shape. The variable currentPiece is a Piece object.
Why can't you modify the code?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
there is no variable shape, but the constructor pass the argument shape to the constructor of Grid.
the method rotateClockwise doesn't work, because I implemented it and it didn't work because I didn't have access to it.
Can you take a look at the code and tell me how I can change the form of the blocks?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
the method rotateClockwise doesn't work
Please explain what "doesn't work" means?
What needs to be changed to make it work?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
It needs to be able to change the form of the currentShape.
ex:
0 1 1
0 0 1
0 0 1
It's a tetris game.
(currentShape contains an attribute that stores an int[][] type that supposed to represent a shape. The shapes are inside an enum inside Piecefactory
Did you try running the code?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
It needs to be able to change the form of the currentShape.
That's a very vague answer that skips or ignores the questions I asked.
Are you saying that the rotateClockwise() method in the code needs to be rewritten to generate the correct results?
It currently executes but the output is wrong.
Sorry, I know nothing about a tetrix game.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
It can't output anything because it can't get the shape of the current object.
I didn't skip your question I already told you there was a shape attribute that was constructed by the parent class of Piece.
Code :
public Piece(int shape[][]) {
super(shape);
currentX = 7;
currentY = 2;
updateLocation();
}
Did you even look at the code?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
It can't output anything because it can't get the shape of the current object.
Please explain what "it" is?
By "shape" do you mean the contents variable defined in the Grid class?
Do you know what it means when a class extends another class?
Quote:
Did you even look at the code?
Yes, that was why I asked where the class variable shape was. I can not see it in the code.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
the variable is not there, but it's an attribute. the method matrixMultiplication and the method rotateCounterClockwise can't get the shape.
--- Update ---
Code :
public Grid(int[][] contents) {
this.contents = contents;
Dimension d = new Dimension(getColumns()*Tetris.SQUARE_SIZE,
getRows()*Tetris.SQUARE_SIZE);
setSize(d);
setPreferredSize(d);
setOpaque(false);
}
Can you explain to me what this does?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
but it's an attribute
Sorry, I have no idea how to code with attributes.
Quote:
rotateCounterClockwise can't get the shape.
Are you talking about accessing the Grid class variable: contents?
What problem(s) are you having accessing the contents variable from the rotateCounterClockwise() method?
"can't get" is not an error message from the java compiler. If you get compiler errors, copy the full text of the error messages and paste them here.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Code :
public Grid(int[][] contents) {
this.contents = contents;
Dimension d = new Dimension(getColumns()*Tetris.SQUARE_SIZE,
getRows()*Tetris.SQUARE_SIZE);
setSize(d);
setPreferredSize(d);
setOpaque(false);
}
Ok then just explain me what this does at the very least.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
It looks like a constructor.
Which line(s) are you having problems with?
I don't see anything unusual.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
I know it's a constructor, but I would like to know what it does exactly. It seems to be printing something, but I don't know if it's printing an individual shape or something else.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Quote:
if it's printing an individual shape or something else.
Where do you see it printing anything? I don't see it.
Which statement are you talking about?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Nevermind,
what do these do?
Code :
Dimension d = new Dimension(getColumns()*Tetris.SQUARE_SIZE,
getRows()*Tetris.SQUARE_SIZE);
setSize(d);
setPreferredSize(d);
setOpaque(false);
the last 3 seems to change some attributes, but they weren't declared in the class.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
The last three are methods in the JComponent class. Read the API doc for that class to get descriptions of what those methods do. The Grid class extends the JComponent class, so these methods can be called in the Grid class as local methods.
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
Ok, one last question. Are you a programmer and did you work in the industry? And were you involved in complex projects, and do you find a Tetris program to be complex?
-
Re: Changing the attribute of an instance object of a class that's declared in another package and whose variable is constructed by its parent class
I did not find the Tetris program complex.