JAVA: creating a pipe game but stuck

Discussion in 'Web Design & Coding' started by CHiLLaXen, Dec 8, 2004.

  1. CHiLLaXen

    CHiLLaXen hypnotika

    Messages:
    107
    Location:
    Minnesota
    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
     

    Attached Files: