JAVA: creating a pipe game but stuck

CHiLLaXen

hypnotika
Joined
6 Jan 2004
Messages
107
Code:
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:
http://kaleidomania.com/csci/cs1203_10/gridGame.zip
 

Attachments

  • PipeGrid.zip
    864 bytes · Views: 84

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back