import java.awt.*; import java.awt.event.*; public class C extends java.applet.Applet { int natax,natay; //xy座標 int speedx,speedy; //鉈スピード int nataMove; //ナタONOFF int kuku; //ククリ int kukus; //ククリ状態 int kukuw; //ウェイトタイム int kukuz; //ククリ座標 int kukuani; //アニメ用 int time; //ウェイト用 int kidouy = 0; //起動時使用 int mwait = 50; //例外処理用 int back = 0; int Qx = 25; int Qy = 120; int zanx[],zanstay[],zaneny[]; //切り口座標 int kizyun; //基準線 int zansuu; //切る回数 int zzz; //現在切った数 int nowzan; //多重斬防止 int seigen = 0; //重斬制限 int stage = 1; //面数 Graphics OffG; //オフスクリーン Image OffImg; Button Btn,BtnS,BtnU; //ボタン AnimPanel Anim; //アニメパネル String str,strS,strU,strM; //ボタンの文字 int scmax = 200; //ハイスコア int mysc = 0; //合計得点 public void init () { setLayout (null); natax = 5; //なたの初期設定 natay = 90; speedx = 4; speedy = 0; nowzan = 0; nataMove = 0; //ナタOFF kuku = 0; //ククリ初期設定 kukus = 0; //状態 kukuw = 0; //ウェイトタイム kukuz = 15; //位置 kukuani = 0; time = 50; zansuu = stage + 2; zzz = 0; zanx = new int[100]; zanstay = new int[100]; zaneny = new int[100]; kizyun = 125 / (zansuu - 1); for (int i = 0;i <= 99;i ++) { //切り口座標 zanx[i] = 300; zanstay[i] = 300; zaneny[i] = 300; } str = "タブキーでスタート"; strS = "1面:3回"; strU = "最高得点" + scmax + ":得点" + mysc; strM = ""; OffImg = createImage (200,200); //オフスクリーン OffG = OffImg.getGraphics (); Anim = new AnimPanel (); //アニメパネル add (Anim); Anim.setBounds (0,20,200,160); Btn = new Button (str); //ボタン設置(点) add (Btn); Btn.setBounds (60,180,140,20); BtnS = new Button (strS); //ボタン設置(面) add (BtnS); BtnS.setBounds (0,180,60,20); BtnU = new Button (strU); //ボタン設置(上部) add (BtnU); BtnU.setBounds (0,0,200,20); } class AnimPanel extends Canvas implements Runnable { //カンバス Image Qri,Nata; //画像 Image kukuri[]; //ククリ Thread Moving; //スレッド public AnimPanel () { //アニメパネル super (); MediaTracker mk = new MediaTracker(this); kukuri = new Image[30]; //ククリ Moving = new Thread (this); Moving.start (); //スレッド開始 Qri = getImage (getDocumentBase (),"Q.gif"); //画像取り込み mk.addImage(Qri,0); Nata = getImage (getDocumentBase (),"nata.gif"); mk.addImage(Nata,0); for (int i = 0;i <= 29;i ++) { kukuri[i] = getImage (getDocumentBase (),"ku" + i + ".gif"); mk.addImage(kukuri[i],0); } try { mk.waitForID(0); } catch (InterruptedException e) {return;} } public void run () { //ラン構文 while (true) { kukuw ++; if (kukus == 0 && kukuw >= 5) { //ノーマルククリ kuku ++; kukuw = 0; if (kuku >= 4) { kuku = 0; } } if (kukus == 1 && kukuw >= 7) { //クリアーククリ kuku ++; kukuw = 0; if (kuku >= 6) { kuku = 4; } } if (kukus == 2 && kukuw >= 3) { //アウトククリ kuku ++; kukuw = 0; if (kuku >= 8) { kuku = 6; } } if (kukus == 3 && kukuw >= 3) { //エンディングククリ kuku ++; if (kuku == 12 && kukuani <= 6) { mwait = 70; kuku = 8; kukuani ++; } if (kuku == 15 && kukuani <= 13) { kuku = 13; kukuani ++; } mwait = 120; if (kuku == 27 && kukuani <= 17) { kuku = 26; kukuani ++; mwait = 78; } } if (nataMove == 1) { natax = natax + speedx; //ナタを動かす natay = natay + speedy; zaneny[zzz] = zaneny[zzz] + speedy; seigen = seigen + speedx; } if (natax >= 177) { //終了 if (zzz <= 2 || zzz < zansuu) { str = "真面目にやってなーい!"; Btn.setLabel (str); stage = 1; zansuu= 3; natax = 5; nataMove = 0; kukus = 2; kuku = 6; kizyun = 125 / (zansuu - 1); for (int i = 0;i <= 99;i ++) { zanx[i] = 300; zanstay[i] = 300; zaneny[i] = 300; } zzz = 0; mysc = 0; repaint (); } else { keisan (); } } if (natay >= 120) { //なたを振り終わった play(getCodeBase(),"ton.au"); speedy = -4; zzz ++; } if (natay <= 90) { //x方向移動再開 speedy = 0; speedx = 3; nowzan = 0; } repaint (); try { Moving.sleep (mwait); //例外処理 } catch (InterruptedException e) {} } } public boolean keyDown (Event evt,int key) { //キー操作 if (nataMove == 0 && key == 9 && kukus < 3) { //スタート! nataMove = 1; kukus = 0; kuku = 0; str = "スペースで切る!"; Btn.setLabel (str); } //斬斬斬 if (nataMove == 1 && zzz < zansuu && seigen >= speedx && nowzan == 0 && natax >=25 && natax <=170 && key == 32) { speedx = 0; speedy = 3; nowzan = 1; seigen = 0; zanx[zzz] = natax + 2; zanstay[zzz] = natay + 30; zaneny[zzz] = natay + 30; } if (kukus == 3 && kukuani >= 10 && key == 32) { //再スタート kukus =0; kuku = 0; kukuani = 0; Anim.setBounds (0,20,200,160); kukuz = 10; mwait = 50; mysc = 0; stage = 1; zansuu = 3; kizyun = 125 / (zansuu - 1); strS = stage + "面:" + zansuu + "回"; BtnS.setLabel (strS); str = "タブキーでスタート"; Btn.setLabel (str); } repaint (); return true; } public void update (Graphics g) { paint (g); } public void paint (Graphics g) { if (kukus < 3) { OffG.setColor (Color.cyan); OffG.fillRect (back,back,200,160); //バック OffG.drawImage (Qri,Qx,Qy,this); //キューリ OffG.setColor (Color.blue); //基準線 for (int i = 0;i <= zansuu-1;i ++) { int op = 35 + kizyun * i; OffG.drawLine (op,120,op,150); } OffG.setColor (Color.black); //線 for (int i = 0;i <= 99;i ++) { OffG.drawLine (zanx[i],zanstay[i],zanx[i],zaneny[i]); } OffG.drawImage (Nata,natax,natay,this); //包丁 } else { OffG.clearRect (0,0,200,200); } OffG.drawImage (kukuri[kuku],kukuz,kukuz,this); //ククリ g.drawImage (OffImg,0,0,this); } public void keisan () { int bb,sc,scr,score,average,death; int simple[]; simple = new int[zansuu]; for (int i = 0;i <= zzz-1;i ++) { simple[i] = 0; } bb = 0; average = 0; sc = 0; scr = 0; score = 0; natax = 5; death = 0; bb = 145 / (zanx[zzz-1] - zanx[0]); //相対値算出 for (int i = 1;i <=zzz-1;i ++) { //平均値算出 simple[i] = (zanx[i] - zanx[i-1])*bb; //単体算出 } average = 145 / (zzz - 1); //平均値算出 for (int i = 1;i <=zzz-1;i ++) { sc = average - simple[i]; //誤差算出 sc = Math.abs(sc); //絶対化 scr = scr + sc; } score = 100 - scr; if (score < 0) { score = 0; } mysc = mysc + score; if (mysc > scmax) { scmax = mysc; } if (score >= 70) { //クリアー判定 stage ++; zansuu ++; strM = "クリアー!"; kukus = 1; kuku = 4; } else { strM = "残念!"; stage = 1; zansuu = 3; death = 1; kukus = 2; kuku = 6; } str = "採点・・" + score + "点だよ!"; Btn.setLabel (str); strS = stage + "面:" + zansuu + "回"; BtnS.setLabel (strS); strU = "最高得点" + scmax + ":得点" + mysc + ":" + strM; BtnU.setLabel (strU); if (death == 1) { mysc = 0; death = 0; } kizyun = 125 / (zansuu - 1); zzz = 0; for (int i = 0;i <= 99;i ++) { zanx[i] = 300; zanstay[i] = 300; zaneny[i] = 300; } nataMove = 0; if (stage == 7) { //クリアへ Anim.setBounds (0,0,200,200); kukus = 3; kuku = 8; kukuz =0; } repaint (); } } }