• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

JAVA: creating a pipe game but stuck

private void initGrid() {
	for(int i = 0; i < num_rows; ++i) {
		for(int j = 0; j < num_cols; ++j) {
			dataGrid[i][j] = EMPTY;
	Random gen = new Random();
	int x1, y1, x2, y2;
	x1 = gen.nextInt(num_rows-2)+1;
	x2 = gen.nextInt(num_rows-2)+1;
	y1 = gen.nextInt(num_rows-2)+1;
	y2 = gen.nextInt(num_rows-2)+1;

        // for debuging purposes
	System.out.println("" + y1 + x1 + "   " + y2 + x2);

	dataGrid[y1-1][x1-1] = START;
	dataGrid[y2-1][x2-1] = END;
This is parrt of the code for the Pipe game. It's the one where you place pipes that connect the start and end points and it fill it with water after you complete the connection or the time runs out. But anyway, its on a 10x10 grid. Once I set the START and END points, they cascade down the rest of the dataGrid.

the dataGrid is a 10x10 array (dataGrid = new int[10][10])

why is it filling in where I set the START/END and the rest of the array. It should just fill in the area the "Random gen" sets it to.
Attached is the PipeGame.java file. It goes with this project:


Members online

No members online now.

Latest posts

Latest profile posts

Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
What a long strange trip it's been. =)

Forum statistics

Latest member