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

Write an application for a video store, Do you provides a Complete source C...

Do you provides a Complete source Codes for this application: " a. Write an application for a video store. Place the names of 10 of your favorite movies in a combo box. Let the use

Encapsulation, Defines to keeping all the related members together in an ob...

Defines to keeping all the related members together in an object. Specifying member variables as private may hide the methods and variables. Objects should hide their inner working

I want android expert, I want android expert Project Description: I h...

I want android expert Project Description: I have too many android project pending anyone who will start work right away, with me will bid here , only bid if you can work rig

Myfirstprogram in java, The purpose of this assignment is to help you learn...

The purpose of this assignment is to help you learn the Java environment and practice I/O instructions, assignment, and simple arithmetic operators. Teams: The assignment can

Elaborate the + operator and its constraints with example, Elaborate the ‘+...

Elaborate the ‘+ ' operator and its constraints along with the help of examples? The + Operator Used on Strings. The + operator could also be used to add string variables or te

Programming, write a Java program that accept two integers and determine we...

write a Java program that accept two integers and determine weather they are Coprime or not

Inheritance, Your task for this assignment is to define multiple classes vi...

Your task for this assignment is to define multiple classes via inheritance. Your classes should implement various "snacks" including "M&Ms", "Popcorn", etc. To begin, create an a

Advanced java info1414, This is a working program that shows election resul...

This is a working program that shows election results from the infamous 2000 presidential election involving a lot of Floridians and 'hanging chads'. The program as written reads a

Write a java code to draw ovals and circles, Write a java code to draw Oval...

Write a java code to draw Ovals and Circles? Java has techniques to draw outlined and filled ovals. As you'd probably guess these methods are called drawOval() and fillOval() c

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