I am trying to make coordinates for 25 objects, however i want them to be randomized each time.
Here is my current code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.*; /** * Write a description of class CircutBuildAndDisplay here. * * @author (your name) * @version (a version number or a date) */ public class CircutBuildAndDisplay extends Actor { //public int one = rand(30) - rand(4) + rand(100); public World whichworld; public boolean dothisonce = false ; int [] ints; int [] ints2; World cw = (CircutWorld) getWorld(); public CircutBuildAndDisplay(World world) { whichworld = world; } public CircutBuildAndDisplay() { } /** * Act - do whatever the CircutBuildAndDisplay wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (getWorld() instanceof CircutWorld) { cw = (CircutWorld) getWorld(); if (!dothisonce) { ints = new int [ 25 ]; for ( int l = 0 ; l < 24 ; l++) { ints[l] = (rand( 5 ) + 2 ); } ints2 = new int [ 25 ]; for ( int l = 0 ; l < 24 ; l++) { ints2[l] = (rand( 5 ) + 2 ); } for ( int l = 0 ; l< 24 ; l++) { if (l < 2 ) { cw.addObject( new Light(),ints[l]* 64 ,ints2[l]* 64 ); } else if (l < 8 ) { cw.addObject( new Wire(),ints[l]* 64 ,ints2[l]* 64 ); } else if (l < 12 ) { cw.addObject( new Resistor(),ints[l]* 64 ,ints2[l]* 64 ); } else if (l < 15 ) { cw.addObject( new Diode(),ints[l]* 64 ,ints2[l]* 64 ); } else if (l < ( 24 - (CircutWorld.level/ 2 ))) { cw.addObject( new EmptyCircuitArea(),ints[l]* 64 ,ints2[l]* 64 ); } } dothisonce = true ; } } } public int rand( int i) { int i2 = Greenfoot.getRandomNumber(i); return i2; } } |