Beginner experimenting with making a simple game

I've just started learning some Java and it's my first programming language. I'd really appreciate input and assistance figuring out how to do various things.

I've already gone through a few tutorials and read some additional info
but decided to put some of the knowledge to the test and also force myself to try some new things. Unfortunately this means I'm in unknown territory and don't know how to do everything I'm wanting to.

[b]Game premise:[/b]

A simple top down 6x6 grid. Each square is either empty, occupied by an enemy, occupied by the Robot(player controlled), or is a wall object and can't be occupied.

I'm starting with the basics and trying to find out how to move up, down, left and right while checking first to see if the square is occupiable. To do this I need to figure out how to create the game board. My initial thought is to do this with each square of the grid having an x and y value to indicate vertical and horizontal squares as in chess. The Robot and the enemies would also have an x and y variable to show where they are at the time. Below is an example of the Robot class so far.

[b]Questions for the experts:[/b]

1)Would an array[][] be useful for creating and/or referencing the game board or would you create 36 individual uniquely named objects to represent the spaces?

2)If the array[][], how do I use it to access the x and y positions of a square and find out if it's occupiable or not.

3)Also give any suggestions that might help me in case I'm going the wrong way about this.

Thanks, Justin

[code]public class Robot {

//Robot Variables
int xLoc;
int yLoc;
int health = 10;
int techLvl;

//Robot contructor
public Robot() {
this.techLvl = 1;
this.xLoc = 1;
this.yLoc = 1;

//Movement methods
public void moveUp(int y) {
//check if the square is occupied
if (checkValidLoc(this.xLoc,this.yLoc+1)) {
this.yLoc = this.yLoc + 1;
public void moveDown(int y) {
//check if the square is occupied
if (checkValidLoc(this.xLoc,this.yLoc-1)) {
this.yLoc = this.yLoc-1;


  • Justin,
    I think an array will work just fine. One observation is that the two methods have an argument, y, that is not used.
    Using google to ask for an example is a great way to see how to do things, or at least get an idea.
    Also, using an IDE like NetBeans has a learning curve, but it makes finding and getting the syntax right 1000 times easier and faster.

    g.l. se52
  • Thanks for the reply.

    I did notice that the y argument is unnecessary but not until after I had posted it. I'm currently using Eclipse IDE. I've been happy with it so far but I'm interested to try NetBeans sometime too.

    Somebody turned me on to the fact that I can create an array of objects. I was under the impression that arrays were only for primitives before. I'm going to try to figure out how to create one and then access the variables.
  • I've created an array of GameTile objects that each have default stats for "terrain type", "damageAmount", etc. A 2x2 array for now.

    Here's the problem:

    How do I create a blueprint for each level that will be able to iterate through the array and change specific parts of the array?
  • This post has been deleted.
  • If I understand the problem, the answer is that the GameTile is the "blueprint".

    Iterate through the array and select each element using pointers and assign to a GameTile variable the particular array element. Then invoke what ever method you want on that particular object instance.
  • hello,i'm also usin eclipse and i'm also a beginner.i tried what you did but i couldn't run it.why is this?plese explain.thanks
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!