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

Define the n-tier architecture or j2ee 3-tier?, Normal 0 false ...

Normal 0 false false false EN-US X-NONE X-NONE

Classifieds android app from my word press classifieds, Classifieds Android...

Classifieds Android app from my Word press Classifieds website with Google gps/ map augmented reality for ads Project Description: 1. Prepare an Android Classifieds app for m

What is event handler works, What is Event Handler works? An event hand...

What is Event Handler works? An event handler is a command which is used to call a function when an event happens, such as the user clicking a button or mouse.

I want to copy an iphone app with some changes, I want to copy an iphone ap...

I want to copy an iphone app with some changes Project Description: I want to copy an iphone app with some changes i need the best programmer to do this for me Skills r

Difference between hashmap and hash table, Difference between HashMap and H...

Difference between HashMap and Hash table HashMap: It allow us to have null values and also one null key It is Unsynchronized. Iterator in HashMap is Fail-Safe.

Relate java with C/C++, Relate Java with C/C++ Very similar C/C++ synta...

Relate Java with C/C++ Very similar C/C++ syntax, operators, etc. Core language is simpler than C++ -- no pointers, no operator overloading, and no multiple inheritance.

Dijkstra''s algorithm, How can I convert Dijkstra''s algorithm to do max fl...

How can I convert Dijkstra''s algorithm to do max flow instead of min flow, and how can I implement it into Ford Fulkerson algorithm?

Loop statements, A loop is a set of commands which executes repeatedly till...

A loop is a set of commands which executes repeatedly till a denoted condition is met. JavaScript supports two loop statements: for & while. Additionally, you can employ the break

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