Newbie Game Experiment - looking for feedback/advice
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.
Game premise:
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.
Questions for the experts:
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;
}
}
}