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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import javax.swing.*; import java.util.Arrays; /** * Write a description of class Square here. * * @author (your name) * @version (a version number or a date) */ public class Square extends Actor { int index = 0 ; static int [] squareValue = new int [ 81 ]; /** * Act - do whatever the Square wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { placeNum(); newGame(); //checkNum(); //getWorld().showText(index + " ", getX(), getY()); } public void placeNum(){ if (Greenfoot.mouseClicked( this )){ JFrame num; num= new JFrame(); do { squareValue[index] = Integer.parseInt(JOptionPane.showInputDialog(num, "What number?(1-9)" )); } while (squareValue[index] < 1 || squareValue[index] > 9 ); getWorld().showText(squareValue[index] + "" , getX(), getY()); } } public void checkNum(){ } public void newGame(){ Button button = getWorld().getObjects(Button. class ).get( 0 ); int difficulty = 0 ; if (Greenfoot.mouseClicked(button)){ JFrame diff; diff= new JFrame(); boolean diffSet = false ; if (diffSet == false ){ diffSet = true ; do { difficulty = Integer.parseInt(JOptionPane.showInputDialog(diff, "What Difficulty? (1-3)" )); if (difficulty < 1 || difficulty > 3 ){ break ; } break ; } while ( true ); } if (difficulty == 1 ){ int easy = Greenfoot.getRandomNumber( 10 ); if (easy == 1 ){ getWorld().showText( "7" , getX(), getY()); } else if (easy == 2 ){ getWorld().showText( "2 works" , 20 , 20 ); } else if (easy == 3 ){ getWorld().showText( "3 works" , 20 , 20 ); } else if (easy == 4 ){ getWorld().showText( "4 works" , 20 , 20 ); } else if (easy == 5 ){ getWorld().showText( "5 works" , 20 , 20 ); } else if (easy == 6 ){ getWorld().showText( "6 works" , 20 , 20 ); } else if (easy == 7 ){ getWorld().showText( "7 works" , 20 , 20 ); } else if (easy == 8 ){ getWorld().showText( "8 works" , 20 , 20 ); } else if (easy == 9 ){ getWorld().showText( "9 works" , 20 , 20 ); } else if (easy == 10 ){ getWorld().showText( "10 works" , 20 , 20 ); } } else if (difficulty == 2 ){ int med = Greenfoot.getRandomNumber( 10 ); if (med == 1 ){ } else if (med == 2 ){ } else if (med == 3 ){ } else if (med == 4 ){ } else if (med == 5 ){ } else if (med == 6 ){ } else if (med == 7 ){ } else if (med == 8 ){ } else if (med == 9 ){ } else if (med == 10 ){ } } else if (difficulty == 3 ){ int hard = Greenfoot.getRandomNumber( 10 ); if (hard == 1 ){ } else if (hard == 2 ){ } else if (hard == 3 ){ } else if (hard == 4 ){ } else if (hard == 5 ){ } else if (hard == 6 ){ } else if (hard == 7 ){ } else if (hard == 8 ){ } else if (hard == 9 ){ } else if (hard == 10 ){ } } } } } |

