/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package xunome.graphics;
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
*
* @author Sem iNick
*/
public class EndGame extends Canvas implements Runnable {
private boolean show = true;
private boolean type;
private Thread effect;
private boolean running = false;
public EndGame(boolean winner) {
super();
setFullScreenMode(true);
type = winner;
effect = new Thread(this);
}
public void paint(Graphics g) {
g.fillRect(0, 0, getWidth(), getHeight());
if ((getWidth() >= 220) && (getHeight() >= 300)) {
try {
//Draw Title
Image title = Image.createImage("/res/title.png");
g.drawImage(title, getWidth()/2, 60, Graphics.HCENTER|Graphics.TOP);
//Draw "You"
Image you = Image.createImage("/res/you.png");
g.drawImage(you, getWidth()/2-50, 130, Graphics.HCENTER|Graphics.TOP);
//Tests if it's to show the frame
if(show) {
String file = (type)?"win":"lose";
Image typeImg = Image.createImage("/res/"+file+".png");
g.drawImage(typeImg, getWidth()/2, 130, Graphics.LEFT|Graphics.TOP);
}
} catch(IOException io) {
//#ifdef DEBUG
System.out.println("Error in render EndGame.");
//#endif
}
} else {
String msg = "xUNO ME - You ";
if (show) {
msg += ((type)?"win":"lose") + " =P";
}
g.setColor(255, 0, 0);
g.drawString(msg, getWidth() / 2, getHeight() / 2,
Graphics.HCENTER | Graphics.BASELINE);
}
show = !show;
}
public void run() {
while(running) {
repaint();
try {
Thread.sleep(1000L);
} catch(InterruptedException ie) {
//#ifdef DEBUG
System.out.println("Error in effect.");
//#endif
}
}
}
public void startEffect() {
running = true;
effect.start();
}
public void stopEffect() {
running = false;
}
}