Game like Bejeweld

Hey guys i’m new in this forum, and i would like some help with a game i have to developed in console.

I’m creating a game like bejeweld when 3 pieces are equal they disapear. When the game starts the line 1 and 2 are already fill with random letters.

So i have this code:
http://pastebin.java-gaming.org/54a6b6d84

and in other class i got a random number generating and pass to ‘a’ ‘v’ or ‘u’ like this:

 int i = random.nextInt(3);
public String converterLetra() {
        if (i == 1) {
            return "u";
        } else if (i == 2) {
            return "a";
        } else {
            return "u";
        }//converterLetra1,2,3 and 4 is the same methods with another var.
    }

My Question is how can i pass the letters that appear on top of the board to inside of the board and if you can give me some recommendations on how i can make the code so that the 3 letters are equals they dessapear i apreciate it

Thanks :wink:

I was confused at first but I then realized you were developing for the console. However, I’d still say you’re going the wrong OO way about this.

You should have the basic game flow down Ie.


Init();

loop {
 update();
 render();
}

Make a class to represent a “letter” or whatever they are called to represent the things you want to pair.

Then add these objects to a map of some sorts. (Like an array).

in the update method, check of keys have been pressed and if the “letters” line up and remove them.

And in the render print them out to the console.

fex.

class Tile {
 String box = "[ ]";
 public Tile(String box) {
  this.box = box;
 }
}

class Map {
 int w, h;
 Tile[][] map;

 public Map( w, h ) {
  this.w = w;
  this.h = h;
  map = new Tile[w][h];
 }

  public void update() {
   for (int y = 0; y < h-2; y++) {
    for (int x = 0; x < w-2; x++) {
     if (map[x][y].box == map[x+1][y].box == map[x+2][y].box) {
      map[x][y].box = map[x+1][y].box ==map[x+2][y].box = "[ ]";
     }
     if (map[x][y].box == map[x][y+1].box == map[x][y+2].box) {
      map[x][y].box == map[x][y+1].box == map[x][y+2].box = "[ ]";
     }
      if (map[x][y].box == map[x+1][y+1].box == map[x+2][y+2].box) {
      map[x][y].box == map[x+1][y+1].box == map[x+2][y+2].box = "[ ]";
     }
    }
   }
  }

  public void render() {
   for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
     System.out.print( map[x][y].box );
    }
    System.out.println();
   }
  }

  public static void main(String[] args) {
   Map game = new Map(10,10);
   while( true ) {
    game.update();
    game.render();
   }
  }
}

Or basically you could do it any way you want. I suggest you read the java tutorials ( if you already haven’t, you should ).

This is exactly same with what I asked one year ago and Kev replied the answer

Hey, about your code…

if (map[x][y].box.length() = map[x+1][y].box.length() = map[x+2][y].box.length()) {
      map[x][y].box = map[x+1][y].box ==map[x+2][y].box = "[ ]";
     }
     if (map[x][y].box == map[x][y+1].box == map[x][y+2].box) {
      map[x][y].box == map[x][y+1].box == map[x][y+2].box = "[ ]";
     }
      if (map[x][y].box == map[x+1][y+1].box == map[x+2][y+2].box) {
      map[x][y].box == map[x+1][y+1].box == map[x+2][y+2].box = "[ ]";

It shows me an error that requires an variable and founds a value