import jp.ac.tuis.basic.*; public class Galaxian{ public static void main(String[] args){ //変数初期化 int WIDTH=40; int HEIGHT=20; BasicGraphics g = new BasicGraphics(WIDTH,HEIGHT,20); int x=WIDTH/2; int y=HEIGHT-2; int[] alien_x={WIDTH-1,WIDTH/2,0}; int[] alien_y={1,1,1}; int[] alien_dir={1,1,1}; char key=0; boolean fired_missile=false; int missile_x=0; int missile_y=0; long SLEEP=100; int POINT=10; int score = 0; int level = 1; int MAXLEVEL = 20; int sublevel = 0; int MAXSUBLEVEL = 2; int ALIEN_COUNT = 3; //画面の初期化 g.console(false); g.color(g.WHITE, g.BLACK); g.cls(); g.locate(0,0); g.color(g.WHITE, g.BLACK); g.print("SCORE : 0"); g.locate(x,y); g.color(g.CYAN, g.BLACK); g.print("▲"); //インベーダ描画 for(int j=0; j WIDTH-1 || alien_x[j] < 0){ alien_dir[j] = -alien_dir[j]; alien_x[j] = alien_x[j] + alien_dir[j]; } alien_y[j] = alien_y[j] + 1; if(alien_y[j] > HEIGHT-1){ alien_y[j] = 1; } if(alien_x[j] == x && alien_y[j] == y){ g.locate(alien_x[j],alien_y[j]); g.color(g.RED, g.BLACK); g.print("★"); g.playM("N"); break mainloop; } if(alien_x[j] == missile_x && alien_y[j] == missile_y){ //インベーダにミサイル命中 g.locate(alien_x[j],alien_y[j]); g.color(g.RED, g.BLACK); g.print("●"); //g.playM("16N"); score = score + POINT; g.locate(8,0); g.color(g.WHITE, g.BLACK); g.print(score); alien_x[j] = 0; alien_y[j] = 1; alien_dir[j]=1; sublevel++; if(sublevel > MAXSUBLEVEL){ sublevel = 0; level++; if(level > MAXLEVEL) level = MAXLEVEL; } }else{ //インベーダ再描画 g.locate(alien_x[j],alien_y[j]); g.color(g.MAGENTA, g.BLACK); g.print("Ж"); } }//end for(j=0; j 0){ g.locate(x,y); g.color(g.WHITE, g.BLACK); g.print(" "); x--; g.locate(x,y); g.color(g.CYAN, g.BLACK); g.print("▲"); } if((key == 'd' || key == 'l') && x < WIDTH-1){ g.locate(x,y); g.color(g.WHITE, g.BLACK); g.print(" "); x++; g.locate(x,y); g.color(g.CYAN, g.BLACK); g.print("▲"); } if((key == 'w' || key == 'i') && y > 2){ g.locate(x,y); g.color(g.WHITE, g.BLACK); g.print(" "); y--; g.locate(x,y); g.color(g.CYAN, g.BLACK); g.print("▲"); } if((key == 's' || key == 'k') && y < HEIGHT-1){ g.locate(x,y); g.color(g.WHITE, g.BLACK); g.print(" "); y++; g.locate(x,y); g.color(g.CYAN, g.BLACK); g.print("▲"); } for(int j=0; j=0){ //ミサイル命中 g.locate(missile_x, missile_y); g.color(g.RED, g.BLACK); g.print("●"); //g.playM("16N"); score = score + POINT; g.locate(8,0); g.color(g.WHITE, g.BLACK); g.print(score); alien_x[hit_alien] = 0; alien_y[hit_alien] = 1; alien_dir[hit_alien] = 1; sublevel++; if(sublevel > MAXSUBLEVEL){ sublevel = 0; level++; if(level > MAXLEVEL) level = MAXLEVEL; } }else{ //else2 g.locate(missile_x, missile_y); g.color(g.YELLOW, g.BLACK); g.print("!"); } //end else2 }//end else1 } }//end while(true) g.locate((WIDTH-9)/2, HEIGHT/2); g.color(g.WHITE, g.BLACK); g.print("GAME OVER"); }//end main }//end class Galaxian