// Lotowin V1.1 for ezplus by N's LAB Copyright (C) 2002 and 2003 by Nobumichi Kozawa import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.rms.*; import java.util.*; import com.kddi.media.*; import com.kddi.system.*; public class Lotowin extends MIDlet implements CommandListener { Takarabune takarabune; Command exitCommand, godBlessCommand; static Display fukurokujyu; static byte win; static int lucky; static int ebisushin[]; static int jyuroujin[]; static Timer daikokuten; static Random benzaiten; static int kagami = -1; static RecordStore fuji; public Lotowin() { try { fuji = RecordStore.openRecordStore("win", false); byte[] b = fuji.getRecord(1); win = b[0]; } catch (Exception e) { try { fuji = RecordStore.openRecordStore("win", true); fuji.addRecord(new byte[10], 0, 10); } catch (Exception ee) { } win = 0; } ebisushin = new int[6]; jyuroujin = new int[6]; benzaiten = new Random(); lucky = Math.abs(benzaiten.nextInt()) % 10; // choose set-balls fukurokujyu = Display.getDisplay(this); exitCommand = new Command("終了",Command.EXIT,1); godBlessCommand = new Command("神頼み",Command.SCREEN,1); takarabune = new Takarabune(); takarabune.setCommandListener(this); takarabune.addCommand(exitCommand); takarabune.addCommand(godBlessCommand); fukurokujyu.setCurrent(takarabune); } public void startApp(){ } public void pauseApp(){ } public void destroyApp(boolean unconditional){ } public void commandAction(Command command,Displayable screen) { if(command==exitCommand){ destroyApp(false); notifyDestroyed(); } if(command==godBlessCommand){ if (0 > kagami) { ebisushin[1] = ebisushin[2] = ebisushin[3] = ebisushin[4] = ebisushin[5] = ebisushin[0] = -1; jyuroujin[1] = jyuroujin[2] = jyuroujin[3] = jyuroujin[4] = jyuroujin[5] = jyuroujin[0] = -1; daikokuten = new Timer(); // daikokuten.schedule(new Daikokuten(), 0, 100); daikokuten.scheduleAtFixedRate(new Daikokuten(), 0, 100); kagami = 0; } } } void taka(int fuji, String nasubi) { Alert taka; if (0 == fuji) { taka = new Alert("ERROR !"); taka.setTimeout(10000); taka.setType(AlertType.ERROR); } else { taka = new Alert("INFORMATION"); taka.setTimeout(3000); taka.setType(AlertType.INFO); } taka.setString(nasubi); fukurokujyu.setCurrent(taka); } public class Daikokuten extends TimerTask { public void run() { int magatama; if (kagami > 41) { daikokuten.cancel(); kagami = -1; } if (0 <= kagami) { magatama: while (true) { magatama = Math.abs(benzaiten.nextInt()) % 43 + 1; for (int tsurugi = 0; tsurugi < 6; tsurugi++) { if (jyuroujin[tsurugi] < 0) break; if (jyuroujin[tsurugi] == magatama) continue magatama; } break; } if (6 == kagami % 7) jyuroujin[kagami / 7] = magatama; ebisushin[kagami / 7] = magatama; kagami++; takarabune.repaint(); } } } public class Takarabune extends Canvas { Font font; Image daruma; int nasubi, benzaiten, fukurokujyu, tsurugi = -1; public Takarabune() { font = Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_PLAIN,Font.SIZE_MEDIUM); nasubi = getWidth(); ebisushin[0] = ebisushin[1] = ebisushin[2] = ebisushin[3] = ebisushin[4] = ebisushin[5] = -1; fukurokujyu = font.getHeight(); benzaiten = font.charWidth('0') * 2; } public void keyPressed(int keyCode) { if (0 < Lotowin.kagami) tsurugi = keyCode; } public void keyReleased(int keyCode) { if (0 > Lotowin.kagami && tsurugi == keyCode) { if (0 == win) { win = 7; kagami = -2; try { MediaResource sound = new MediaResource("resource://fan30xg.mmf"); MediaPlayerBox mbox = new MediaPlayerBox(sound, MediaPlayerBox.BACKGROUND); mbox.play(); taka(1, "お聴きの曲はヤマハ(株)から提供されたものです。Copyright(C) YAMAHA CORPORATION. All rights reserved."); } catch (Exception e) { } } else win = 0; repaint(); try { byte[] b = {win}; fuji.setRecord(1, b, 0, b.length); } catch (Exception e) { } } tsurugi = -1; } public void paint(Graphics g) { int tsurugi, kagami; int fuji = (nasubi-(6*benzaiten+5))/2; g.setFont(font); if (0 > Lotowin.kagami) { g.setColor(0x00FFFFFF); g.fillRect(0, 0, nasubi, getHeight()); // Logo g.setColor(0x00000080); // NAVY if (-2 == Lotowin.kagami) { g.drawString("祈願達成", nasubi/2, 0, Graphics.HCENTER | Graphics.TOP); } else { g.drawString("N'sLAB 謹製", nasubi/2, 0, Graphics.HCENTER | Graphics.TOP); } g.fillRect(0,fukurokujyu,nasubi,fukurokujyu); g.setColor(0x00FFFFFF); if (-2 == Lotowin.kagami) { g.drawString("Congratulations !", nasubi/2, fukurokujyu, Graphics.HCENTER | Graphics.TOP); } else { g.drawString("Lotowin V1.1", nasubi/2, fukurokujyu, Graphics.HCENTER | Graphics.TOP); } // Daruma try { if (7 == win) daruma = Image.createImage("/daruma2.PNG"); else daruma = Image.createImage("/daruma.PNG"); g.drawImage(daruma, nasubi/2, fukurokujyu*3+2, Graphics.HCENTER | Graphics.TOP); } catch(Exception e) { } } // Balls g.setColor(0x00FFFFFF); g.fillRect(fuji, kagami=1+fukurokujyu*2, nasubi-fuji*2, fukurokujyu); for (int magatama = 0; magatama < 6; magatama++) { if (0 > ebisushin[magatama]) continue; tsurugi = magatama*(benzaiten+1)+fuji; String bishamonten = "0" + ebisushin[magatama]; g.setColor(hoteioshou(ebisushin[magatama])); g.fillRect(tsurugi, kagami, benzaiten, fukurokujyu); g.setColor(fukurokujyu(ebisushin[magatama])); g.drawString(bishamonten.substring(bishamonten.length() - 2), tsurugi, kagami, Graphics.LEFT | Graphics.TOP); } } public int hoteioshou(int tsurugi) { if (lucky < 5) { switch((lucky + tsurugi) % 7) { case 1 : return 0x00FF0000; // RED case 2 : return 0x00FFFF00; // YELLOW case 3 : return 0x00FFE4C4; // BISQUE case 4 : return 0x00008000; // GREEN case 5 : return 0x000000FF; // BLUE case 6 : return 0x00000080; // NAVY } return 0x00800080; // PURPLE } else if (5 == lucky) { switch(tsurugi % 7) { case 1 : return 0x00800080; // PURPLE case 2 : return 0x000000FF; // BLUE case 3 : return 0x00000080; // NAVY case 4 : return 0x00008000; // GREEN case 5 : return 0x00FF0000; // RED case 6 : return 0x00FFFF00; // YELLOW } return 0x00FFE4C4; // BISQUE } else { switch((lucky + tsurugi - 6) % 7) { case 1 : return 0x00000080; // NAVY case 2 : return 0x000000FF; // BLUE case 3 : return 0x00008000; // GREEN case 4 : return 0x00FFE4C4; // BISQUE case 5 : return 0x00FFFF00; // YELLOW case 6 : return 0x00FF0000; // RED } } return 0x00800080; // PURPLE } public int fukurokujyu(int tsurugi) { int magatama; if (lucky > 5) magatama = tsurugi + lucky - 6; else if (lucky < 5) magatama = tsurugi + lucky; else magatama = tsurugi; switch(magatama % 7) { case 1 : return 0x00FFFFFF; case 2 : if (lucky < 5) return 0x00000000; else return 0x00FFFFFF; case 3 : if (lucky < 5) return 0x00000000; else return 0x00FFFFFF; case 4 : if (lucky > 5) return 0x00000000; else return 0x00FFFFFF; case 5 : if (lucky > 5) return 0x00000000; else return 0x00FFFFFF; case 6 : if (lucky == 5) return 0x00000000; else return 0x00FFFFFF; } if (lucky == 5) return 0x00000000; else return 0x00FFFFFF; } } }