-
90 degree Rotation
Hi, I'm trying to create a program that rotates a figure by 90 degrees clockwise. It is run in the command prompt, is supposed to output the new position of the figure. This program can be viewed as a foundation for tetris pieces. Here is an example of how it should look:
[***]
[-*-]
[-*-]
90 rotate
[--*]
[***]
[--*]
90 rotate
[-*-]
[-*-]
[***]
This is the result I get for the first 3 or 4 times the figure is rotated, but then I get random results after that. Could someone run my code and tell me what is going on?
public class Rotation
{
public static boolean[][] isBlockPresent = new boolean[3][3];
public static boolean[][] isMatrixBuffer = new boolean[3][3];
public static void main(String args[])
{
isBlockPresent[1][0] = true;
isBlockPresent[1][1] = true;
isBlockPresent[2][1] = true;
isBlockPresent[1][2] = true;
for(int r = 0; r<3; r++)
{
System.out.print("[");
for(int c = 0; c<3; c++)
{
if(isBlockPresent[c][r])
System.out.print("*");
else
System.out.print("-");
}
System.out.println("]");
}
for(int m = 0; m<5; m++)
{
System.out.println();
RotateClockwise();
}
}
public static void RotateClockwise()
{
for(int r = 0; r<3; r++)
{
for(int c = 0; c<3; c++)
isMatrixBuffer[c][r] = isBlockPresent[r][2 - c];
}
isBlockPresent = isMatrixBuffer;
for(int r = 0; r<3; r++)
{
System.out.print("[");
for(int c = 0; c<3; c++)
{
if(isBlockPresent[c][r])
System.out.print("*");
else
System.out.print("-");
}
System.out.println("]");
}
}
}
Thanks,
Ben.
-
nvm, i solved it already. thx.
Similar Threads
-
By Skeptical in forum Database
Replies: 0
Last Post: 03-01-2005, 06:31 AM
-
Replies: 12
Last Post: 12-22-2001, 12:41 AM
-
By Gregg in forum Talk to the Editors
Replies: 4
Last Post: 12-12-2001, 07:43 AM
-
Replies: 6
Last Post: 03-14-2001, 05:21 PM
-
By R. Freywith in forum Careers
Replies: 2
Last Post: 10-05-2000, 07:36 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|