// Lotowin V1.1 by N's LAB Copyright (C) 2002 by Nobumichi Kozawa import com.nttdocomo.ui.*; import com.nttdocomo.io.*; import com.nttdocomo.util.*; import java.util.*; import java.io.*; import javax.microedition.io.*; public class Lotowin extends IApplication implements SoftKeyListener, TimerListener { Panel takarabune; Label ebisushin1, ebisushin2, ebisushin3, ebisushin4, ebisushin5, ebisushin6; Label nlab, lotowin; ImageLabel daruma; Timer daikokuten; Random benzaiten; int kagami; int bishamonten[]; int lucky; int win = 0; public void start() { kagami = -1; try { InputStream fuji = Connector.openInputStream("scratchpad:///0"); win = fuji.read(); fuji.close(); } catch (IOException e) { win = 0; } takarabune = new Panel(); takarabune.setSoftLabel(Frame.SOFT_KEY_1,"終了"); takarabune.setSoftLabel(Frame.SOFT_KEY_2,"神頼"); takarabune.setSoftKeyListener(this); benzaiten = new Random(); lucky = Math.abs(benzaiten.nextInt()) % 10; // choose set-balls bishamonten = new int[6]; daikokuten = new Timer(); daikokuten.setTime(100); daikokuten.setRepeat(true); daikokuten.setListener(this); daikokuten.start(); nlab = new Label("N's LAB 謹製"); nlab.setSize(takarabune.getWidth(), nlab.getHeight()); nlab.setAlignment(Label.CENTER); nlab.setForeground(Graphics.getColorOfName(Graphics.NAVY)); lotowin = new Label("Lotowin V1.1"); lotowin.setAlignment(Label.CENTER); lotowin.setSize(takarabune.getWidth(), lotowin.getHeight()); lotowin.setForeground(Graphics.getColorOfName(Graphics.WHITE)); lotowin.setBackground(Graphics.getColorOfName(Graphics.NAVY)); takarabune.add(nlab); takarabune.add(lotowin); ebisushin1 = new Label(" "); takarabune.add(ebisushin1); ebisushin2 = new Label(" "); takarabune.add(ebisushin2); ebisushin3 = new Label(" "); takarabune.add(ebisushin3); ebisushin4 = new Label(" "); takarabune.add(ebisushin4); ebisushin5 = new Label(" "); takarabune.add(ebisushin5); ebisushin6 = new Label(" "); takarabune.add(ebisushin6); daruma = new ImageLabel(darumadaishi()); daruma.setSize(daruma.getWidth(), daruma.getHeight() + 5); takarabune.add(daruma); Display.setCurrent(takarabune); } public Image darumadaishi() { String taka; if (7 == win) taka = "2"; else taka = ""; MediaImage magatama = MediaManager.getImage("resource:///daruma"+taka+".gif"); try { magatama.use(); } catch (ConnectionException ce){ } return magatama.getImage(); } public void resume() { daikokuten = new Timer(); daikokuten.setTime(100); daikokuten.setRepeat(true); daikokuten.setListener(this); daikokuten.start(); } public void timerExpired(Timer daikokuten) { int magatama; StringBuffer ebisushin = new StringBuffer("0"); if (0 <= kagami) { magatama: while (true) { magatama = Math.abs(benzaiten.nextInt()) % 43 + 1; for (int tsurugi = 0; tsurugi < 6; tsurugi++) { if (bishamonten[tsurugi] < 0) break; if (bishamonten[tsurugi] == magatama) continue magatama; } break; } if (6 == kagami % 7) { for (int tsurugi = 0; tsurugi < 6; tsurugi++) { if (bishamonten[tsurugi] < 0) { bishamonten[tsurugi] = magatama; break; } } } ebisushin.append(magatama); switch (kagami / 7) { case 0 : ebisushin1.setText(ebisushin.toString().substring(ebisushin.length() - 2)); ebisushin1.setForeground(fukurokujyu(magatama)); ebisushin1.setBackground(hoteioshou(magatama)); break; case 1 : ebisushin2.setText(ebisushin.toString().substring(ebisushin.length() - 2)); ebisushin2.setForeground(fukurokujyu(magatama)); ebisushin2.setBackground(hoteioshou(magatama)); break; case 2 : ebisushin3.setText(ebisushin.toString().substring(ebisushin.length() - 2)); ebisushin3.setForeground(fukurokujyu(magatama)); ebisushin3.setBackground(hoteioshou(magatama)); break; case 3 : ebisushin4.setText(ebisushin.toString().substring(ebisushin.length() - 2)); ebisushin4.setForeground(fukurokujyu(magatama)); ebisushin4.setBackground(hoteioshou(magatama)); break; case 4 : ebisushin5.setText(ebisushin.toString().substring(ebisushin.length() - 2)); ebisushin5.setForeground(fukurokujyu(magatama)); ebisushin5.setBackground(hoteioshou(magatama)); break; case 5 : ebisushin6.setText(ebisushin.toString().substring(ebisushin.length() - 2)); ebisushin6.setForeground(fukurokujyu(magatama)); ebisushin6.setBackground(hoteioshou(magatama)); break; } kagami++; if (kagami > 41) kagami = -1; } } public void softKeyPressed(int softKey) { if(softKey == Frame.SOFT_KEY_1) { terminate(); } else if (softKey == Frame.SOFT_KEY_2) { jyuroujin(); } } public void softKeyReleased(int softKey) { if (kagami < 0) { AudioPresenter fuji = null; MediaSound nasu = null; if (7 != win) { try { nasu = MediaManager.getSound("resource:///fan30xg.mid"); nasu.use(); fuji = AudioPresenter.getAudioPresenter(); fuji.setSound(nasu); fuji.play(); Dialog taka = new Dialog(Dialog.BUTTON_OK, "Congratulations!"); taka.setText("お聴きの曲はヤマハ(株)から提供されたものです。"); taka.show(); taka.setText("Copyright(C) YAMAHA CORPORATION. All rights reserved."); taka.show(); } catch (Exception e) { nasu = null; } nlab.setText("祈願達成"); lotowin.setText("Congratulations !"); } win = (7 == win) ? 0 : 7; try { OutputStream tsurugi = Connector.openOutputStream("scratchpad:///0"); tsurugi.write(win); tsurugi.close(); } catch (IOException e) { } daruma.setImage(darumadaishi()); } } public void jyuroujin() { int bg = Graphics.getColorOfRGB(0xff,0xff,0xff); kagami = 0; for (int magatama = 0; magatama < 6; magatama++) bishamonten[magatama] = -1; ebisushin1.setBackground(bg); ebisushin1.setText(" "); ebisushin2.setBackground(bg); ebisushin2.setText(" "); ebisushin3.setBackground(bg); ebisushin3.setText(" "); ebisushin4.setBackground(bg); ebisushin4.setText(" "); ebisushin5.setBackground(bg); ebisushin5.setText(" "); ebisushin6.setBackground(bg); ebisushin6.setText(" "); } public int hoteioshou(int tsurugi) { if (lucky < 5) { switch((lucky + tsurugi) % 7) { case 1 : return Graphics.getColorOfRGB(0xff,0,0); // RED case 2 : return Graphics.getColorOfRGB(0xff,0xff,0); // YELLOW case 3 : return Graphics.getColorOfRGB(0xff,0xe4,0xc4); // BISQUE case 4 : return Graphics.getColorOfRGB(0,0x80,0); // GREEN case 5 : return Graphics.getColorOfRGB(0,0,0xff); // BLUE case 6 : return Graphics.getColorOfRGB(0,0,0x80); // NAVY } return Graphics.getColorOfRGB(0x80,0,0x80); // PURPLE } else if (5 == lucky) { switch(tsurugi % 7) { case 1 : return Graphics.getColorOfRGB(0x80,0,0x80); // PURPLE case 2 : return Graphics.getColorOfRGB(0,0,0xff); // BLUE case 3 : return Graphics.getColorOfRGB(0,0,0x80); // NAVY case 4 : return Graphics.getColorOfRGB(0,0x80,0); // GREEN case 5 : return Graphics.getColorOfRGB(0xff,0,0); // RED case 6 : return Graphics.getColorOfRGB(0xff,0xff,0); // YELLOW } return Graphics.getColorOfRGB(0xff,0xe4,0xc4); // BISQUE } else { switch((lucky + tsurugi - 6) % 7) { case 1 : return Graphics.getColorOfRGB(0,0,0x80); // NAVY case 2 : return Graphics.getColorOfRGB(0,0,0xff); // BLUE case 3 : return Graphics.getColorOfRGB(0,0x80,0); // GREEN case 4 : return Graphics.getColorOfRGB(0xff,0xe4,0xc4); // BISQUE case 5 : return Graphics.getColorOfRGB(0xff,0xff,0); // YELLOW case 6 : return Graphics.getColorOfRGB(0xff,0,0); // RED } } return Graphics.getColorOfRGB(0x80,0,0x80); // 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 Graphics.getColorOfRGB(0xff,0xff,0xff); case 2 : if (lucky < 5) return Graphics.getColorOfRGB(0,0,0); else return Graphics.getColorOfRGB(0xff,0xff,0xff); case 3 : if (lucky < 5) return Graphics.getColorOfRGB(0,0,0); else return Graphics.getColorOfRGB(0xff,0xff,0xff); case 4 : if (lucky > 5) return Graphics.getColorOfRGB(0,0,0); else return Graphics.getColorOfRGB(0xff,0xff,0xff); case 5 : if (lucky > 5) return Graphics.getColorOfRGB(0,0,0); else return Graphics.getColorOfRGB(0xff,0xff,0xff); case 6 : if (lucky == 5) return Graphics.getColorOfRGB(0,0,0); else return Graphics.getColorOfRGB(0xff,0xff,0xff); } if (lucky == 5) return Graphics.getColorOfRGB(0,0,0); else return Graphics.getColorOfRGB(0xff,0xff,0xff); } }