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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | public class Red extends Actor { int y; int g = 2 ; int didTouch1 = 1 ; int didTouch2 = 1 ; int didTouch3 = 1 ; int didTouch4 = 1 ; int touch1 = 0 ; int touch2 = 0 ; int touch3 = 0 ; int touch4 = 0 ; int mouseClick = 0 ; public void act() { fallingCheck(); clickCheck(); } public void fallingCheck() { if (isTouching(Red. class ) || isTouching(Yellow. class ) || isTouching(StopChecker. class )){ //nothing } else { gravity(); } } public void clickCheck() { if (Greenfoot.mouseClicked( null )) { mouseClick = mouseClick + 1 ; touchCheck(); } } public void gravity() { g = g + 1 ; y = getY() + g; setLocation(getX(), y); } public void touchCheck() { if (didTouch1 == 1 ) { touchCheck1(); } else if (didTouch2 == 0 ) { touchCheck2(); } else if (didTouch3 == 0 ) { touchCheck3(); } else if (didTouch4 == 0 ) { touchCheck4(); } else { winCheck(); } } public void touchCheck1() { if (isTouching(Red. class ) && didTouch1 == 1 ) { touch1 = touch1 + 1 ; didTouch1 = 0 ; didTouch2 = 0 ; } } public void touchCheck2() { if (isTouching(Red. class ) && didTouch2 == 0 ) { touch2 = touch2 + 1 ; didTouch2 = 1 ; didTouch3 = 0 ; } } public void touchCheck3() { if (isTouching(Red. class ) && didTouch3 == 0 ) { touch3 = touch3 + 1 ; didTouch3 = 1 ; didTouch4 = 0 ; } } public void touchCheck4() { if (isTouching(Red. class ) && didTouch4 == 0 ) { touch4 = touch4 + 1 ; didTouch4 = 1 ; } } public void winCheck() { if (touch1 >= 1 && touch2 >= 1 && touch3 >= 1 && touch4 >= 1 ) { getWorld().addObject( new Reset(), 600 , - 800 ); } } } |

