import jp.ac.tuis.basic.*; public class InvaderServerLite{ public static void main(String[] args){ //変数初期化 int WIDTH=40; int HEIGHT=20; BasicGraphics g = new BasicGraphics(WIDTH,HEIGHT,20); int x=WIDTH/2+1; int y=HEIGHT-2; int remotex=WIDTH/2-1; int remotey=HEIGHT-2; int[] alien_x={4,2,0}; int[] alien_y={1,1,1}; int[] alien_dir={1,1,1}; boolean game_over=false; char key=0; char remotekey=0; boolean fired_missile=false; int missile_x=0; int missile_y=0; boolean remotefired_missile=false; int remotemissile_x=0; int remotemissile_y=0; long SLEEP=30; int POINT=10; int score = 0; int remotescore = 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.println("Starting server."); g.print("Enter server port number."); String portstring = g.input(); int port = Integer.parseInt(portstring); g.println(); g.println("Waiting for client connection..."); g.connect(null, port); //ゲーム画面用意 g.color(g.WHITE, g.BLACK); g.cls(); g.locate(0,0); g.color(g.WHITE, g.BLACK); g.print("SCORE : 0"); g.locate(WIDTH/2,0); g.color(g.WHITE, g.BLACK); g.print("OPPONENT : 0"); g.color(g.WHITE, g.GREEN); g.locate(0,y+1); g.print(" "); g.locate(x,y); g.color(g.CYAN, g.BLACK); g.print("A"); g.locate(remotex,remotey); g.color(g.BLUE, g.BLACK); g.print("A"); //g.beep(); g.receiveint(); //インベーダ描画 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]++; if(alien_y[j] >= y){ game_over = true; } } 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.play("galzaga.wav"); 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 if(alien_x[j] == remotemissile_x && alien_y[j] == remotemissile_y){ //インベーダにミサイル命中 g.locate(alien_x[j],alien_y[j]); g.color(g.RED, g.BLACK); g.print("@"); remotescore = remotescore + POINT; g.locate((WIDTH/2) + 11,0); g.color(g.WHITE, g.BLACK); g.print(remotescore); 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("M"); } if(game_over){ break; //leave for loop } }//end for(j=0; j 0){ g.locate(x,y); g.color(g.WHITE, g.BLACK); g.print((char)0); x--; g.locate(x,y); g.color(g.CYAN, g.BLACK); g.print("A"); } if((key == 'd' || key == 'l') && x < WIDTH-1){ g.locate(x,y); g.color(g.WHITE, g.BLACK); g.print((char)0); x++; g.locate(x,y); g.color(g.CYAN, g.BLACK); g.print("A"); } if(key == ' ' && fired_missile == false){ fired_missile = true; missile_x = x; missile_y = y-1; g.locate(missile_x, missile_y); g.color(g.YELLOW, g.BLACK); g.print("i"); //g.play("013.wav"); }else if(fired_missile == true){ g.locate(missile_x, missile_y); g.color(g.WHITE, g.BLACK); g.print((char)0); missile_y = missile_y-1; if(missile_y < 1){ fired_missile = false; }else{ //else1 int hit_alien = -1; for(int j=0; j=0){ //ミサイル命中 g.locate(missile_x, missile_y); g.color(g.RED, g.BLACK); g.print("@"); //g.play("galzaga.wav"); 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("i"); } //end else2 }//end else1 }//end else if(fired_missile == true) //対戦プレーヤーの操作 if((remotekey == 'a' || remotekey == 'j') && remotex > 0){ g.locate(remotex,remotey); g.color(g.WHITE, g.BLACK); g.print((char)0); remotex--; g.locate(remotex,remotey); g.color(g.BLUE, g.BLACK); g.print("A"); } if((remotekey == 'd' || remotekey == 'l') && remotex < WIDTH-1){ g.locate(remotex,remotey); g.color(g.WHITE, g.BLACK); g.print((char)0); remotex++; g.locate(remotex,remotey); g.color(g.BLUE, g.BLACK); g.print("A"); } if(remotekey == ' ' && remotefired_missile == false){ remotefired_missile = true; remotemissile_x = remotex; remotemissile_y = remotey-1; g.locate(remotemissile_x, remotemissile_y); g.color(g.WHITE, g.BLACK); g.print("i"); //g.play("013.wav"); }else if(remotefired_missile == true){ g.locate(remotemissile_x, remotemissile_y); g.color(g.WHITE, g.BLACK); g.print((char)0); remotemissile_y = remotemissile_y-1; if(remotemissile_y < 1){ remotefired_missile = false; }else{ //else1 int hit_alien = -1; for(int j=0; j=0){ //ミサイル命中 g.locate(remotemissile_x, remotemissile_y); g.color(g.RED, g.BLACK); g.print("@"); //g.play("galzaga.wav"); remotescore = remotescore + POINT; g.locate((WIDTH/2) + 11,0); g.color(g.WHITE, g.BLACK); g.print(remotescore); 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(remotemissile_x, remotemissile_y); g.color(g.WHITE, g.BLACK); g.print("i"); } //end else2 }//end else1 }//end else if(remotefired_missile == true) }//end while(!game_over) g.locate((WIDTH-9)/2, HEIGHT/2); g.color(g.WHITE, g.BLACK); g.print("GAME OVER"); }//end main }//end class InvaderServer