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

Java program to play minesweeper , Project Requirements Write and tes...

Project Requirements Write and test a Java program to play Minesweeper using Model-View-Presenter design (The model is an interface defining the data to be displayed or other

Explain role of actionservlet , ActionServlet performs the role of Contro...

ActionServlet performs the role of Controller: ? Process user requests ? Verify what the user is trying to achieve according to the request ? Pull data from the model (if

Streaming and decorator construction in java i/o, Java output and input is ...

Java output and input is described in terms of an abstract concept named a " stream ", which is a sequence of data. There are 2 types of streams. 1.      Byte streams (8 bit

What is jdbc abstraction and dao module, Using this module we can keep up t...

Using this module we can keep up the database code clean and easy, and prevent problems that result from a failure to close database resources. A new layer of meaningful exceptions

Write a program in javascript that will read in an xml file, Write a progra...

Write a program in Javascript that will read in an XML file. This file will contain details of devices maintained by the IT department of an organisation including an ID number, de

Integration of neo4j and opengeo, Integration: Neo4J, OpenGeo, Ikanow Pr...

Integration: Neo4J, OpenGeo, Ikanow Project Description: I have an ongoing project to loosely integrate a variety of existing Open Source products: OpenGeo (geospatial server

Convert an existing flash file into html5, REQUIREMENT: We are seeking a si...

REQUIREMENT: We are seeking a simple tool that will convert an existing flash file (.SWF) into HTML5. Our purpose is to convert small flash games into html5 games. Please NOTE: We

Determine the types of object oriented programme, Determine the types of ob...

Determine the types of object oriented programme Classes - Prototypes for objects - Definition or a blueprint of a user-defined datatype - Think of it as a ma

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