Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7532173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:22:29+00:00 2026-05-30T05:22:29+00:00

I am making a program similar to the famous game Tetris and I’ve run

  • 0

I am making a program similar to the famous game Tetris and I’ve run into some problems when it comes to rotating a block.

I know you are able to rotate figures in a coordinate system by using “x = -y” and “y = x” but the problem is that because I am using an array of integers to represent the block it makes things so much more difficult.

My array looks like:

int[][] space = new int[20][10];

And if a coordinate contains a block the value is 1 else it’s 0.

So how can I rotate a block in that space without getting trouble with negative numbers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:22:31+00:00Added an answer on May 30, 2026 at 5:22 am

    Here’s a sample piece (reusing your int[][] using 0’s and 1’s, which might as well be done using a boolean array):

    private static final int[][] piece = new int[][] {
            { 0, 1, 0, },
            { 1, 1, 1, },
    };
    

    You can rotate a piece doing this:

    private static int[][] rotate( final int[][] piece ) {
        final int[][] res = new int[piece[0].length][piece.length];
        for (int x = 0; x < piece.length; x++) {
            for (int y = 0; y < piece[0].length; y++) {
                res[(res.length-1)-y][x] = piece[x][y];
            }
        }
        return res;
    }
    

    The starting piece:

    010
    111
    

    Here’s rotate(piece):

    01
    11
    01
    

    Here’s rotate(rotate(piece)):

    111
    010
    

    And here’s rotate(rotate(rotate(piece))):

    10
    11
    10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making an encyclopedia program of sorts similar to RAWR for World of Warcraft.
I am doing some reverse engineering on a 3rd party program that is making
I am making a program to play a game of UNO. In the UNO
I am making my first program using Java3D. I have setup some transformGroups that
For some reason my C program is refusing to convert elements of argv into
This is similar to my last question. I'm making a simple tcp/ip chat program
I'm making a program in wxWidgets that has similar functionality to, say, MS Paint,
I'm making myself familiar with C programming and want to write a program similar
This is frustrating. I'm trying to run a program which loads into memory a
I am using the cool map making program DIY map and i want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.