import jp.ac.tuis.basic.*; public class Chase { public static void main(String[] args) { //画面サイズ 40x20 フォントサイズ20 BasicGraphics g = new BasicGraphics(40,20,20); g.console(false); //自動スクロールOFF(false) //変数宣言 int x, y, dir; //プレイヤー x座標,y座標,移動方向 boolean trail; //壁を残すかどうか byte color; //壁の色 char key; //入力キー long SLEEP=200;//速度調整 int COM=4; //COM側の数 int[] comx = new int[COM]; //COM x座標 int[] comy = new int[COM]; //COM y座標 int[] comdir = new int[COM]; //COM 移動方向 int[] comstate = new int[COM]; //COM状態 //画面アイテム char[] items = {' ','◆','Д','Ω','▲','╋','●','■'}; //マップ初期化 byte[][] map = new byte[40][20]; for(int j=0; j<40; j++){ map[j][0]=7; //一番上の列 map[j][1]=(byte)((Math.random()*10+1)/10); map[j][18]=(byte)((Math.random()*10+1)/10); map[j][19]=7;//一番下の列 } map[0][1]=map[39][1]=map[0][18]=map[39][18]=7; for(int i=2; i<18; i++){ map[0][i]=7;//一番左の列 map[1][i]=(byte)((Math.random()*10+1)/10); for(int j=2; j<38; j++){ map[j][i]=0; } map[38][i]=(byte)((Math.random()*10+1)/10); map[39][i]=7;//一番右の列 } for(int i=0; i7){ color=1; } } } if(key=='1') color=1; //色・アイテム選択 if(key=='2') color=2; if(key=='3') color=3; if(key=='4') color=4; if(key=='5') color=5; if(key=='6') color=6; if(key=='7') color=7; if(key=='↑'){ //上移動開始 dir=1; } if(key=='→'){ //右移動開始 dir=2; } if(key=='↓'){ //下移動開始 dir=3; } if(key=='←'){ //左移動開始 dir=4; } if(dir!=0){ //現在の位置の描画を処理 if(trail==true){ map[x][y]=color; //マップに記憶しておく } g.locate(x,y); g.color(map[x][y]);//色を設定 g.print(items[map[x][y]]);//アイテム描画 } if(dir==4){ //左移動の場合 x--; g.locate(x,y); g.color(g.BLUE); g.print("<");//左向き機体 } if(dir==2){ //右移動の場合 x++; g.locate(x,y); g.color(g.BLUE); g.print(">");//右向き機体 } if(dir==1){ //上移動の場合 y--; g.locate(x,y); g.color(g.BLUE); g.print("∧");//上向き機体 } if(dir==3){ //↓移動の場合 y++; g.locate(x,y); g.color(g.BLUE); g.print("∨");//下向き機体 } if(map[x][y]!=0){ //壁に触ったら g.color(g.RED); //色設定 g.locate(x,y); g.print("★"); //死ぬ g.playM("N8"); //爆発音 break;//whileから抜ける } //あたり判定 int count=0; for(int i=0; i