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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
| package j2mill;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextBox;
// Referenced classes of package j2mill:
// j2mill_wall, j2mill_ball, data_engine
public class j2mill_canvas extends Canvas
implements Runnable
{
private Thread t;
public boolean sync;
public Object lock;
private j2mill_ball ball;
private j2mill_wall wall;
private data_engine Data_Engine;
private Form highscore;
private Form splash;
private Display display;
private TextBox textBox;
private Command contSplash;
private Image smiley;
private Image bar1;
private Image bar2;
private Image bar22;
private Image bar11;
// private Image wink;
private int backgroundcolor;
//rivate int wallcolor;
//private int ballcolor;
private int inkcolor;
private int wallwidth;
private int ballwidth;
private int ballheight;
private int ball23width;
private int ball23height;
private int cheight;
private static final int AHEIGHT = 2;
private static final int MAXBALL = 3;
private int ballserial;
private boolean running;
private static final int MAX_CPS = 50;
private static final int MS_PER_FRAME = 20;
private boolean waiting;
private int waittime;
private static final int MAXWAITTIME = 10;
private int state;
private static final int STATE_NULL = 0;
private static final int STATE_INIT = 1;
private static final int STATE_PRINT = 2;
private static final int STATE_WAIT = 4;
private static final int STATE_DRAW = 8;
private int logic_state;
private static final int LOGIC_NULL = 0;
private static final int LOGIC_WAIT = 1;
private static final int LOGIC_STEP = 2;
private static final int LOGIC_END = 4;
public j2mill_canvas(data_engine Data_Engine, Form highscore, TextBox textBox, Form splash, Command contSplash, Display display)
{
t = new Thread(this);
sync = false;
lock = new Object();
backgroundcolor = 150;
inkcolor = 0;
wallwidth = 12;
ballwidth = 18;
ballheight = 19;
ball23width = 10;
ball23height = 10;
running = true;
ballserial = 1;
waiting = true;
waittime = 0;
wall = new j2mill_wall();
state = 7;
logic_state = 1;
this.Data_Engine = Data_Engine;
this.highscore = highscore;
this.textBox = textBox;
this.display = display;
this.splash = splash;
this.contSplash = contSplash;
try
{
smiley = Image.createImage("/icons/smiley.PNG");
}
catch(Exception e)
{
System.out.println("Probleme with smiley");
}
try
{
bar1 = Image.createImage("/icons/bar1.PNG");
}
catch(Exception e)
{
System.out.println("Probleme with bar1");
}
try
{
bar2= Image.createImage("/icons/bar2.PNG");
}
catch(Exception e)
{
System.out.println("Probleme with bar1");
}
try
{
bar11= Image.createImage("/icons2/bar11.PNG");
}
catch(Exception e)
{
System.out.println("Probleme with bar11");
}
try
{
bar22= Image.createImage("/icons2/bar22.PNG");
}
catch(Exception e)
{
System.out.println("Probleme with bar22");
}
t.start();
}
public void run()
{
do
{
if(!running)
{
break;
}
long cycleStartTime = System.currentTimeMillis();
logic();
if(state != 0)
{
repaint();
}
long timeSinceStart = cycleStartTime - System.currentTimeMillis();
if(timeSinceStart < 20L)
{
try
{
Thread.sleep(20L - timeSinceStart);
}
catch(InterruptedException e) { }
}
try
{
if(sync)
{
synchronized(lock)
{
lock.wait();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
} while(true);
}
public void processResume()
{
sync = false;
synchronized(lock)
{
lock.notifyAll();
}
}
public void processPause()
{
sync = true;
}
public void splashtogame()
{
state |= 2;
if(logic_state == 1)
{
state |= 4;
}
}
public void clearewall()
{
wall.clearDir();
}
public void paint(Graphics g)
{
if((state & 1) != 0)
{
state &= -2;
g.setFont(Font.getDefaultFont());
cheight = g.getFont().getHeight() + 2;
}
if((state & 2) != 0)
{
state &= -3;
g.setGrayScale(backgroundcolor);
g.fillRect(0, getHeight() - cheight, getWidth(), cheight);
g.setGrayScale(inkcolor);
g.drawLine(0, getHeight() - cheight, getWidth(), getHeight() - cheight);
g.drawString( " Total score"+Data_Engine.get_point(), 1, (getHeight() - cheight) + 1, 20);
}
if((state & 4) != 0)
{
state &= -5;
g.setGrayScale(backgroundcolor);
g.fillRect(0, 0, getWidth(), getHeight() - cheight);
g.setGrayScale(inkcolor);
g.drawString("jouer", getWidth() / 2, getHeight() / 2 + cheight / 2, 17);
}
if((state & 8) != 0)
{
state &= -9;
g.setGrayScale(backgroundcolor);
g.fillRect(0, 0, getWidth(), getHeight() - cheight);
if(ball != null)
{
g.drawImage(ball.get_bounce() ? smiley : smiley, ball.get_ballX(), ball.get_ballY(), 20);
}
g.setColor(0,150,0);
j2mill_wall _tmp = wall;
if(wall.getDir(2))
{
g.fillRect(0, 0, wallwidth, getHeight() - cheight);
g.setColor (0, 255,0);
}
j2mill_wall _tmp1 = wall;
if(wall.getDir(1))
{
g.fillRect(getWidth() - wallwidth, 0, wallwidth, getHeight() - cheight);
}
j2mill_wall _tmp2 = wall;
if(wall.getDir(4))
{
g.fillRect(0, getHeight() - wallwidth - cheight, getWidth(), wallwidth);
g.setColor (255,255,0);
}
j2mill_wall _tmp3 = wall;
if(wall.getDir(8))
{
g.fillRect(0, 0, getWidth(), wallwidth);
g.setColor (0, 0, 255);
}
}
}
private void logic()
{
if(logic_state == 1)
{
if(waittime != 0)
{
waittime--;
}
if(!waiting)
{
ball = null;
ball = new j2mill_ball(getWidth(), getHeight() - cheight, wallwidth, ballwidth, ballheight, wall, 0L);
if(ballserial >= 2)
{
ball = new j2mill_ball(getWidth(), getHeight() - cheight, wallwidth, ballwidth, ballheight, wall, 0L);
}
logic_state = 2;
}
}
if(logic_state == 2)
{
if(ball != null && !ball.get_inside())
{
ball = null;
}
if(ball == null )
{
logic_state = 4;
} else
{
if(ball != null)
{
ball.mainmover();
}
if(ball != null && ball.get_newbounce())
{
Data_Engine.add_point();
state |= 2;
}
state |= 8;
}
}
if(logic_state == 4)
{
ballserial++;
if(ballserial >= 4)
{
logic_state = 0;
splash.removeCommand(contSplash);
processPause();
if(Data_Engine.hs_place() != -1)
{
display.setCurrent(textBox);
} else
{
StringItem hs_infok = null;
hs_infok = new StringItem("", Data_Engine.hs_list(false));
highscore.set(0, hs_infok);
display.setCurrent(highscore);
}
}
waiting = true;
waittime = 10;
state |= 6;
logic_state = 1;
}
}
protected void keyPressed(int keyCode)
{
int actionKey = getGameAction(keyCode);
if(actionKey == 5 || actionKey == 2)
{
if (wall.getDir(1));
wall.setDir(2);
if (wall.getDir(2));
wall.setDir(1);
}
if(waittime == 0)
{
waiting = false;
}
}
protected void keyReleased(int keyCode)
{
int actionKey = getGameAction(keyCode);
if(actionKey == 5)
{
j2mill_wall _tmp = wall;
wall.setDir(1);
}
if(actionKey == 2)
{
j2mill_wall _tmp1 = wall;
wall.setDir(2);
}
if(actionKey == 6)
{
j2mill_wall _tmp2 = wall;
wall.setDir(4);
}
if(actionKey == 1)
{
j2mill_wall _tmp3 = wall;
wall.setDir(8);
}
}
} |