83

So I was messing around with Java and decided to make a Tetris clone... : Progra...

 6 years ago
source link: https://www.reddit.com/r/ProgrammerHumor/comments/7az207/so_i_was_messing_around_with_java_and_decided_to/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

So I was messing around with Java and decided to make a Tetris clone...

Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
Search within r/ProgrammerHumor
Subreddit Iconr/ProgrammerHumor
Found the internet!
Posted by5 years ago

So I was messing around with Java and decided to make a Tetris clone...

Settings
Fullscreen
97% Upvoted
This thread is archived
New comments cannot be posted and votes cannot be cast
level 1

I was impressed, then I chuckled. Then, I was still impressed.

level 2

Honestly it’s a pretty impressive “insane mode” feature

level 2

He made a tetris game that pukes a rainbow, how about that?

level 1

When I mess around in java i make a yes no button output box and a string that says hello. Damn

level 2

I took a Java class am and currently in AP computer science and I'll tell you I have no idea how to make a yes no button output box.

level 1

Can someone please explain this to me?? It’s funny because it glitched out at the end?

level 2
[deleted]
· 5 yr. ago

Yes, that's pretty much it.

I get that there are posts in this subreddit that aren't humorous, but I think this post definitely is okay for this subreddit. Anyone who has programmed anything knows the feeling of your programming doing some super fucked up behavior that you didn't intend it to do.

level 2

It's funny because it's relatable

level 2

It's because throughout the program this feeling of "fuck yeah, it actually works!" keeps growing, and then you let your guard down and it shits buckets all over your face.

It's relatable indeed.

level 2
[deleted]
· 5 yr. ago

Yes, at least it is an unexpected event that related to programming, but not those unrelated random events that claim as jokes like on YouTube.

level 1

I make my projects the same way. Jframe and buffered image. Looping through.

level 1

Reminds me of early versions of my chess engine, which was plagued by what came to be known as the Black Knight Invasion. No survivors.

level 2

I wrote a chess wrapper in Java for the chess engine Stockfish a while ago that had a funny bug.

What the wrapper was actually doing was waiting for a move from the player, sending the move history to Stockfish, seeing the responded move, and performing that move on the board.

Because of this, near the beginning of development, if you made an invalid move (the wrapper used to allow you), the computer would then move one of your pieces, making a move for you!

This was because Stockfish was ignoring any invalid piece moves, so it thought it was white's (your) turn to move a piece, so it did.

It was almost like the chess engine was saying "no, that's not right. this is what you should do"

level 1

I was beginning to wonder why this was on r/ProgrammerHumor

level 1

Upload to git please

level 1

Genuinely thought you would spell send nudes

level 1

Looks like java puked all over itself and said yea hand me another beer mate!

level 1

Seems like this may have not been Java’s fault

level 1

Boom, Tetris for Jeff

level 1
[deleted]
· 5 yr. ago

Can you please share code or at least the algorithm? I can't even get to where you are currently at.

level 2

If i had to guess, he made a Matrix of 10x20, where each position is a square. Then he sets each position a value, from 0 to 6, 0 being empy white and 1 to 6 being each piece.

What I (Totally not a programmer) would do is:

Randomly decide which piece is coming down and "draw it" on the top. Then, every "tick" move that piece down until it touches the floor. After that, I would check for complete lines remove them and move everything on top 1 line down:

for (int line = 0; line < 20; line++) {
    complete = true;
    for (int x = 0; x < 10; x++) {
        if (position[line][x] == 0) { complete = false;}
    }
    if (complete) { removeLine(line);}
}

After checking all 20 lines for completed lines, I would generate a new random piece.

level 2
OpAvid Voter+1 · 5 yr. ago · edited 5 yr. ago

The code is on GitHub, however I think there are far better Tetris examples with comments out there, just need to google. The hardest part for me was blocks rotation, I found this video, which I think explains the concept really good: https://www.youtube.com/watch?v=Atlr5vvdchY Other than that it's just 2d array iteration. I am using Java's Graphics2D class to draw the Tetris board. Mainly the fill3DRect method to display individual blocks with 1 pixel of space in between blocks. If you feel like messing around you might add a smaller rect on top of each block for a weird looking lego effect. Good luck.

level 2

I would think something like having one matrix, and then have a system for automatic game things (spawn random piece, moving active piece down once every x seconds, checking if the piece can go further down, if not check if the rows any of it ended up in are cleared, if so move higher rows down, and then start that loop from the top), and one for player action (moving pieces left/right, rotating pieces, no need to worry about making pieces move faster down right away but that's a thing you can add later). Overall just have a thread for these two loops and it'll work out fine.

level 1

You should try intellij idea, found it a lot nicer to use than eclipse 👀

level 1

Total flashbacks to when I made Tetris in the 3DS browser. So proud of that program.

level 1
[deleted]
· 5 yr. ago

So what went wrong?

level 2

So what went wrong?

Forgot to put a "break;" in a switch statement :D

level 1

Wow...

level 1

Java. Not even once.

level 1

Cool, I found the dickbutt

level 1

Game-breaking glitches aside, why are the J and Z blocks the same color!?

level 1
[deleted]
· 5 yr. ago

yOU ARE WINNER

level 1

The floor is lava

level 1

It works. Ship it!

level 1

If you look really close, you can see it break at the end

level 1

I don't get it, where's the fuck up...oh

level 1
[deleted]
· 5 yr. ago

"That's just... accurate" ~Hillary Clinton

level 1

I want to see the code XDDD

level 1

Wait did you ever figure out the origin of this bug? I don't know why I randomly thought about this post, but I'm extremely curious.

Advertisement

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK