import java.awt.*; import java.util.Random; public class Hid extends java.applet.Applet { int niS = 0; //ニケ状態 int niX = 5; //ニケX座標 int niAni = 0; //ニケアニメパターン int niDi = 0; //ニケ移動方向 int niDo = 0; //ニケ仕事中 int niW = 0; //隠れる時のウェイト int nista = 0; //スタート時 int zenka = 3; //前科(笑) int nitask = 7; //仕事時間 int find = 0; //見つかった?! int cleS = 0; //振り向き中か? int LvH = 60; //レベル int speed = 100; //スピード String Lb,Rb; //言葉 int time = 0; //タイム int score = 0; //総得点 int stage = 1; //面数 int Room = 190; //部屋のR色 Graphics OffG; //オフスクリーン Image OffImg; AnimPanel Anim; public void init () { setLayout (null); OffImg = createImage (200,200); //オフスクリーン OffG = OffImg.getGraphics (); Anim = new AnimPanel (); //アニメパネル add (Anim); Anim.setBounds (0,0,200,200); Lb = "アッチ村1件目!"; //ラベル Rb = ""; } class AnimPanel extends Canvas implements Runnable { Image nike[]; //ニケ画像 Image clean[]; //家人 Image tan,exit; int cleani = 0; //家人パターン Random clR; //家人ランダム int R = 0; //ランダム変数 Random clRta; //振り向いている時間 int Rta = 0; //ランダム変数 Thread Moving; public AnimPanel () { super (); MediaTracker mk = new MediaTracker(this); nike = new Image[5]; //ニケ画像数 clean = new Image[6]; //家人画像数 Moving = new Thread (this); Moving.start (); tan = getImage (getDocumentBase (),"tan.gif"); mk.addImage(tan,0); exit = getImage (getDocumentBase (),"exit.gif"); mk.addImage(exit,0); for (int i = 0;i <= 4;i ++) { //ニケ画像取り込み nike[i] = getImage (getDocumentBase (),"nike" + i + ".gif"); mk.addImage(nike[i],0); } for (int i = 0;i <= 5;i ++) { //家人画像取り込み clean[i] = getImage (getDocumentBase (),"clean" + i + ".gif"); mk.addImage(clean[i],0); } try{ mk.waitForID(0); }catch(InterruptedException e){ return; } } public void run () { while (true) { time ++; //時間測定 if (cleS != 2 && cleani < 5) { //掃除 cleani ++; } if (cleS == 2) { //振り向き戻り cleani = cleani - 1; } if (cleS == 2 && cleani == 0) { //振り向き終わり cleS = 0; } if (cleani == 2 && cleS == 0) { //家人動き cleani = 0; } if (cleS == 0) { clR =new Random (); //振り向くかどうか R = Math.abs (clR.nextInt () % LvH); if (R <= 2) { //振り向く事決定 cleS = 1; } } clRta =new Random (); //振り直るかどうか Rta = Math.abs (clRta.nextInt () % 13); if (cleani == 5 && Rta <= 3) { //振り向ききった cleS = 2; } if (niS == 2) { //ニケ仕事中 niAni ++; niDo ++; if (niAni >= 4) { niAni = 2; } if (niDo == nitask) { //ニケ仕事完了 niS = 0; niAni = 0; niDo = 0; niDi = 1; } } if (niS != 2) { //隠れる niW ++; if (niW == 2) { niAni = 4; niW = 0; } } if (niS == 1) { //ニケ移動 niAni ++; if (niAni >= 2) { niAni = 0; niS = 0; } } if (niS == 2 && cleani == 5 && find ==0) { //見つかったー!! find = 1; //見つかったフラグ Lb = "あ!何してるんだ!"; zenka = zenka - 1; //残数減少 if (zenka == 0) { over (); } repaint (); Moving.suspend (); //ストップ niDi = 0; //右向き niX = 5; niS = 0; cleani = 0; } if (nista == 0) { //開始直後移動前 niAni = 0; } repaint (); try { Moving.sleep (speed); //ウェイト }catch (InterruptedException e) {} } } public boolean keyDown (Event evt,int key) { if (niDi == 0 && niS != 2 && key == 32 && find == 0) { //右移動 niX = niX + 4; niS = 1; nista = 1; } if (niDi == 1 && niS != 2 && key == 32 && find == 0) { //左移動 niX = niX - 4; niS = 1; } if (niX >= 150) { //仕事開始 niS = 2; } if (niX < 3 && niDi == 1 && find == 0 && key == 32) { //面クリア Moving.suspend (); //runストップ find = 1; //停止処理 score = score + time; //総得点加算 niDi = 0; //右向き niX = 5; //初期位置 stage ++; Room = Room - 5; LvH = LvH / 8 * 7; //レベル設定 if (LvH <= 14) { speed = speed / 6 * 5; LvH = 50; } getitem (); //アイテム拾得 } if (key == 32 && cleani == 5 && find == 0) { //見つかったー!! Moving.suspend (); find = 1; Lb = "あ!何してるんだ!"; zenka = zenka -1; if (zenka == 0) { over (); } } if (find == 1 && key == 9) { //リプレイ cleS = 0; //家人状態 cleani = 0; //家人パターン find = 0; //見つかってない time = 0; //点数 niX = 5; //ニケX座標 niDi = 0; //右向き nista = 0; //構え Lb = "アッチ村" + stage + "件目"; if (stage >= 10) { Lb = "シュギ村" + stage + "件目"; } Moving.resume (); } repaint (); return true; } public void over () { //ゲームオーバー Lb = "GAME OVER"; zenka = 3; score = 0; stage = 1; LvH = 60; speed = 100; nitask = 7; Room = 190; } public void getitem () { //アイテム Random Item; Item = new Random (); int GetI = 0; GetI = Math.abs (Item.nextInt () % 50); if (GetI <28) { Lb = "やったー!薬草を発見!"; } if (GetI ==29 || GetI == 28) { Lb = "盗賊のレベルが上がった!!"; nitask = nitask - 2; } if (GetI == 30) { Lb = "呪われた村長の像だ!"; speed = speed / 3 * 2; } if (GetI >30 && GetI < 40) { Lb = "おお!聖水だ!"; LvH = LvH + 1; } if (GetI >=40 && GetI < 45) { Lb = "魔除けのポプリいただき!"; speed = speed / 15 * 17 + 3; } if (GetI ==45) { Lb = "青とうがらし・・!うにょらーー!!"; speed = speed / 17 * 13 + 3; } if (GetI >=46) { Lb = "黒スグリの実だ!"; LvH = LvH + 2; } } public void update (Graphics g) { paint (g); } public void paint (Graphics g) { Color Roomco; //部屋の色 Roomco = new Color (Room,70,70); OffG.setColor (Roomco); OffG.fillRect (0,0,200,160); OffG.setColor (Color.black); //部屋 OffG.drawLine (100,30,200,30); OffG.drawLine (100,30,0,55); OffG.drawLine (100,30,100,0); OffG.setColor (Color.darkGray); //言葉 OffG.fillRect (0,160,200,200); OffG.setColor (Color.white); OffG.drawString (Lb,0,180); //上 OffG.drawString ("総得点:" + score + " 時間:" + time + " 残り" + zenka + "回",0,194); //下 OffG.drawImage (tan,168,20,this); OffG.drawImage (exit,0,20,this); OffG.drawImage (clean[cleani],82,128,this); OffG.drawImage (nike[niAni],niX,20,this); g.drawImage (OffImg,0,0,this); } } }