This site requires JavaScript, please enable it in your browser!
Greenfoot back
freeij8949
freeij8949 wrote ...

2013/4/10

sort grid i need help

freeij8949 freeij8949

2013/4/10

#
the order of the two numbers (1 and 2) that we put in the array is fixed. Please think of a way to randomize such order after class. This is my problem.. i can not do that. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Sets up the SortGrid world. This includes creating all nodes * and numbers, connecting the nodes up and placing them in the world. * * @author Joseph Lenton */ public class SortGrid extends World { private static final int WIDTH = 400; private static final int HEIGHT = 600; private static final int NUMBER_Y = 50; private static final int NUMBER_PADDING = 100; private static final int NUMBER_X = 150; private static final int NUM_POSITIONS = 2; /** * Creates and sets up the SortGrid world ready to be run. */ public SortGrid() { super( WIDTH, HEIGHT, 1 ); // create the network node Node first = new Node();final int leftX = WIDTH/2; addObject( first , leftX, 300 ); // end nodes End ends = new End; for ( int i = 0; i < ends.length; i++ ) { End end = new End(); ends = end; addObject( end, NUMBER_X + NUMBER_PADDING*i, HEIGHT-NUMBER_Y ); } // create the connections first.setDestinations( ends, ends ); final int randomNums = {1, 2}; final Number numbers = new Number; // make the numbers for ( int i = 0; i < NUM_POSITIONS; i++ ) { final Number number = new Number( randomNums ); final int x = NUMBER_X + NUMBER_PADDING*i; final int y = NUMBER_Y; numbers = number; addObject( number, x, y ); addObject( new Start(), x, y ); } // set the number destinations numbers.setDestination( first ); numbers.setDestination( first ); // paint ordering setPaintOrder( Number.class, Node.class, Position.class, Start.class ); } } this is my code
You need to login to post a reply.