2d world of ants and doodlebugs, JAVA Programming

Assignment Help:
We have to create a world class that contains a 2d array
then create an abstract class called organism that contains move() method
the organism should move randomly one step at the time.

public void move() {
Random r = new Random();
int a = r.nextInt(4);
if (a == 0) {
if (y - 1 >= 0 && world.getAt(x, y - 1) == null) {
y -= 1;
world.setAt(x, y, this);

}
} else if (a == 1) {
if (y + 1 < World.WORLDSIZE && world.getAt(x, y + 1) == null) {
y += 1;
world.setAt(x, y, this);
}
} else if (a == 2) {
if (x - 1 >= 0 && world.getAt(x - 1, y) == null) {
x -= 1;
world.setAt(x, y, this);

}
} else if (a == 3) {
if (x + 1 < World.WORLDSIZE && world.getAt(x + 1, y) == null) {
x += 1;
world.setAt(x, y, this);

}
}
this is my code but the organisms are not moving

Related Discussions:- 2d world of ants and doodlebugs

Multitreading, what is multithreading in Java? Explain with example.

what is multithreading in Java? Explain with example.

What are adding methods, What are adding methods? A subclass isn't rest...

What are adding methods? A subclass isn't restricted to changing the behavior of its superclass. It can also add fully latest techniques and fields that are not shared along wi

Performs simple editsusing html and javascript, You are to write two versio...

You are to write two versions of this assignment. One using HTML and VBScript and one using HTML and Javascript. In both, you are to create an HTML webpage that: performs simple

Explain about drawing lines, Explain about Drawing Lines? Drawing strai...

Explain about Drawing Lines? Drawing straight lines along with Java is easy. Just call g.drawLine(x1, y1, x2, y2) where (x1, y1) and (x2, y2) are the endpoints of your lines

Program that instantiates a number of actors and writers, Talent agencies l...

Talent agencies like ICM, CAA and Paradigm represent writers, directors and actors (among other talent).  These agencies take in hundreds of millions of dollars a year collecting 1

Need mahjong puzzle game, Need Mahjong puzzle game I want someone to mak...

Need Mahjong puzzle game I want someone to make this game ( Mahjong puzzle game) for me in Android ONLY. If you have high level programming knowledge in Android then please b

Online Store Website, Project Requirements • Create your own online store ...

Project Requirements • Create your own online store Web site, selling products of your choice. • Create pages that allow you to search and buy available products, as well as add,

Code for calculatr, how i made a calculator in java plz tell help me

how i made a calculator in java plz tell help me

Write a javascript program which having two functions, Write a JavaScript p...

Write a JavaScript program which having two functions that are sum and mean. The web page will ask the user to enter five values to be added. After taking input it will compute

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd