I'd like to ask you a question about Java coding.

Asked 2 years ago, Updated 2 years ago, 24 views

Hello, I'm a freshman who's posting on hash code for the first time.

It's nothing else

There's one task I have to do right now.

What I can't solve is

Take the array plate 10*10 and use the panel to move the yellow and blue balls randomly

If the blue ball sticks to one of the yellow cavity, west, south, and north, the yellow ball moves in the direction

I'm going to do something that makes me move along.

But I don't know how to do it on the code.

As soon as the blue ball sticks to the yellow ball, the blue ball should move in the same direction as the yellow ball moves.

The blue ball and yellow ball have different positions, so the array index values are completely different.

I'm curious about how the blue ball changes the same as the yellow ball changes when it sticks.

For example,

When the yellow ball is located on the [5][5] and the blue ball is on the [5][6], it's stuck next to it, so when the yellow ball goes from [5][5] to [4][5], the blue ball moves like this, [4][6] I don't even know how to code it.

I don't know if I explained it well, but please answer TT.

java

2022-09-22 19:55

1 Answers

I think we can make it a conditional statement.

if(list[i][j] == yellow ball && list[i][j+1] == blue ball)

{ list[i][j] == null ;

list[i][j+1] == null;

list[i-1][j] == yellow ball;

list[i-1][j+1] == blue ball; }

Wouldn't it be possible to handle it this way?


2022-09-22 19:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.