import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.util.*; import java.applet.AudioClip; //------------------------------------------------------------------------------- // Puyoクラス //------------------------------------------------------------------------------- public class puyo extends Applet { public int set; public int SoundFlag; public int PuyoFlag; public int SkipFlag = 0; public int sss = 1; public int ef1 = 0; public int ef2 = 0; public int many = 0; public String state = ""; //public String state = "test"; //オブジェクト public int objnum; //プレイ人数 public myGame[] G; //オブジェクト //スレッド public myThread1[] r1; public myThread2[] r2; public Thread[] t1; public Thread[] t2; //画像と音楽 Image ofscr; Graphics ofscr_g; Image myWallImg; Image myFieldImg; Image myNextImg; Image[] myImg; public int ofscr_width; public int ofscr_height; public AudioClip[] clip; //共通変数 public int puyo_size; //ぷよの幅 public int left_pos; //ぷよの落ちてくる位置(0〜5)※0or5だと自動モードに不具合発生 public int height; //フィールドの縦幅 public int width; //フィールドの横幅 public int StartFlag; //ゲームがスタートしたか判定 public int StopFlag; //一時停止・スタート判定 public int rank_n; //順位 //共通配列 public int[] EneOjaCount; ////おじゃま数カウント public int[] GameFlag; //ゲーム中か判定する配列 public int[] rank; //順位用配列 public String[] color = {"gray","red","yellow","blue","green","purple"}; //色 public int[] puyolist; //---------------初期化--------------- public void myInit() { //変数を初期化 puyo_size = 16; left_pos = 2; height = 14; width = 6; StartFlag = 0; StopFlag = 0; rank_n = objnum; for (int i=0; i= 1) { ofscr_g.drawString(G[n].mes+"!",135+G[n].width_c,130+G[n].height_c); ofscr_g.drawString("("+G[n].chain_count+"連鎖)",135+G[n].width_c,145+G[n].height_c); } //今ぷよ if ((G[n].WeitFlag == 0 || StopFlag == 1) && GameFlag[n] == 1) { if (G[n].pos[0][0] > 1) { ofscr_g.drawImage( myImg[G[n].puyo1], (G[n].pos[0][1]+1)*puyo_size+G[n].width_c, (G[n].pos[0][0])*puyo_size+G[n].height_c, this ); } if (G[n].pos[1][0] > 1) { ofscr_g.drawImage( myImg[G[n].puyo2], (G[n].pos[1][1]+1)*puyo_size+G[n].width_c, (G[n].pos[1][0])*puyo_size+G[n].height_c, this ); } } //NEXTぷよ ofscr_g.drawImage(myNextImg,138+G[n].width_c,47+G[n].height_c,this); ofscr_g.drawImage(myImg[G[n].npuyo1],143+G[n].width_c,51+G[n].height_c,this); ofscr_g.drawImage(myImg[G[n].npuyo2],143+G[n].width_c,67+G[n].height_c,this); ofscr_g.drawImage(myImg[G[n].nnpuyo1],159+G[n].width_c,59+G[n].height_c,this); ofscr_g.drawImage(myImg[G[n].nnpuyo2],159+G[n].width_c,75+G[n].height_c,this); //テスト用 if (state.equals("test")) { ofscr_g.setColor(new Color(0,0,0)); //文字 ofscr_g.drawString(G[n].x,10+G[n].width_c,260+G[n].height_c); //"Chain="+G[n].max_chain_num+", "+ //配列 for (int i=0; i 1) { ofscr_g.setColor(new Color(255,0,0)); } else if (G[n].last_ignition_lab2[i][j] == 1) { ofscr_g.setColor(new Color(0,0,255)); } else { ofscr_g.setColor(new Color(0,0,0)); } ofscr_g.drawString(""+G[n].last_chain_lab[i][j],11*j+150+G[n].width_c,11*i+100+G[n].height_c); } } } } //一括表示 g.drawImage(ofscr,0,0,null); } //------------------------------------------------------------------------------- // myAutoFallを他のスレッドとは独立に呼び出すためのスレッド //------------------------------------------------------------------------------- class myThread1 implements Runnable { private int id; //コンストラクタ public myThread1(int i) { id = i; } //run public void run() { G[id].FallThreadCount++; if (G[id].FallThreadCount == 1) { try { t1[id].sleep(G[id].FallSpeed); } catch(InterruptedException e) {} G[id].FallThreadCount--; if (G[id].WeitFlag == 0) { G[id].myAutoFall(); } } else { G[id].FallThreadCount--; } } } //------------------------------------------------------------------------------- // myAutoFall以外を呼び出すためのスレッド //------------------------------------------------------------------------------- class myThread2 implements Runnable { private int id; //コンストラクタ public myThread2(int i) { id = i; } //run public void run() { //止める try { t2[id].sleep(G[id].sleepTime); } catch(InterruptedException e) {} if (GameFlag[id] == 1) { //連鎖終了後処理 if (G[id].sleepMode.equals("AutoFall")) { G[id].myMakePuyo2(); //ぷよ生成 G[id].WeitFlag = 0; //ボタン入力受付開始 if (G[id].FallThreadCount == 0) { G[id].myAutoFall(); } //落とす try { t2[id].sleep(300); } catch(InterruptedException e) {} if (GameFlag[id] == 1 && G[id].AutoFlag == 1) { G[id].myAutoMove(); } //オートモード起動 } //他 else if (G[id].sleepMode.equals("AutoMove")) { G[id].myAutoMove(); } //オートモード(ゲームスタート時のみ) else if (G[id].sleepMode.equals("Stack")) { G[id].myStack(); } //ぷよ積み上げ else if (G[id].sleepMode.equals("Chain")) { G[id].myChain(); } //連鎖判定 else if (G[id].sleepMode.equals("Fall")) { G[id].Grid.myFall(); } //連鎖時落下 else if (G[id].sleepMode.equals("Right")) { G[id].myAutoMoveR(); } //右自動移動 else if (G[id].sleepMode.equals("Left")) { G[id].myAutoMoveL(); } //左自動移動 else if (G[id].sleepMode.equals("Stop")) { G[id].WeitFlag = 0; } //ストップ else if (G[id].sleepMode.equals("Over")) { G[id].myGameOver(); } //ゲームオーバー //オートモード回転 else if (G[id].sleepMode.equals("Rotate")) { //止める try { t2[id].sleep(G[id].sleepTime); } catch(InterruptedException e) {} if (GameFlag[id] == 1) { //そのまま if (G[id].auto_r == 0) { if (sss == 1) { G[id].myMoveS(); } } //他 else { //とりあえず回転 G[id].myRota(G[id].rd); repaint(); //2回転の場合 if (G[id].auto_r == 3) { try { t2[id].sleep(G[id].sleepTime); } catch(InterruptedException e) {} if (GameFlag[id] == 1) { G[id].myRota(G[id].rd); repaint(); } } //止める try { t2[id].sleep(G[id].sleepTime); } catch(InterruptedException e) {} //落とす if (GameFlag[id] == 1 && sss == 1) { G[id].myMoveS(); } } } } } } } //------------------------------------------------------------------------------- // Gameクラス //------------------------------------------------------------------------------- class myGame { ///////////////各種変数/////////////// public int id; public myGrid Grid; public int puyolist_num; //動作テスト用 public String x; public int[] cc = new int[5]; public int cc_sum; //オートモード関連 public int mtime; public int rd; //オートモードでの回転方向 public int auto_r; //オートモードでの回転の仕方 public int auto_j; //オートモードでの列番号 //いろいろ1 public int puyo1, puyo2, npuyo1, npuyo2, nnpuyo1, nnpuyo2; //ぷよナンバー public int width_c, height_c, Rnd_Oja_pos, code; //他 public int FallThreadCount; //スレッドカウント public int erase_num; //いろいろ2 public int count; //連結数 public int rot_pos; //回転ラベル public String over_mes; public String sleepMode; //スリープ後実行処理 public int sleepTime; //スリープ用時間 //連鎖関連 public int chain_count; //連鎖数 public int ignition_chain_count; //発火ぷよ発火による連鎖数 public int max_chain_count; //それまでの最大連鎖数を保持 public String mes; //連鎖メッセージ public int folder; //連鎖の声のフォルダ //ぷよ関連のスピード public int FallSpeed = 1500; //落下 public int MoveSpeed = 50; //左右移動 public int RotaSpeed = 100; //回転 //判定するための public int WeitFlag; //待ってるか判定 public int ChainFlag; //連鎖する可能性があるか判定 public int NotBuryFlag; //埋まるかどうか判定 public int Connect3Flag; //連結数が3以上の箇所が見つかったか判定 public int TearFlag; //ちぎったか判定 public int AutoFlag; //オートモードか判定 public int JudgeFlag; //オートモードで判定中か判定 public int IgnitionJudgeFlag; //オートモードで発火ぷよ判定中か判定 //おじゃま public int OjaCount; public int TempOjaCount; public int DamOjaCount; public int OjaAmari; public int OjaRate; public int OjaFlag; public int OjaHeight; public int DamOjaHeight; public int OjaHeightAmari; //得点用A-B-C-D public int score; public int dscore; public int A; public int[] B = {0,4,20,24,32,48,96,160,240,320,480,600,700,800,900,999}; public int[] C = {0,2,3,4,5,6,7,10}; public int Cmax; public int[] D = {0,3,6,12,24}; public int Dsum; public int BCD; ///////////////各種配列/////////////// //マス目 public int[][] grid = new int[height][width]; //ダミーのマス目 public int[][] dummy_grid = new int[height][width]; //積んだ直後 public int[][] pre_dummy_grid = new int[height][width]; //連鎖終了後 //連鎖時ラベル用 public int[][] connect_lab = new int[height][width]; //どれくらい落ちたのか public int[][] fall_lab = new int[height][width]; //連鎖ラベル public int[][] chain_lab = new int[height][width]; public int[][] last_chain_lab = new int[height][width]; public int[][] pre_chain_lab = new int[height][width]; //発火ぷよラベル public int[][] ignition_lab2 = new int[height][width]; public int[][] last_ignition_lab2 = new int[height][width]; //列に色ぷよがあるか public int[][] colorlist = new int[width][color.length-1]; //連結数保存用 public int[][] connect_num = new int[height][width]; //落ちてきたぷよの座標 public int[][] pos = new int[2][2]; //それぞれの色ぷよの消した個数 public int[] erased_number = new int[color.length-1]; //連鎖回数保存用 public int[] chain_num = new int[5]; //色ごとに消しぷよ数を保存する用(一時的に) public int[] erpuyolist = new int[color.length-1]; //落下パターン優先順位 public int[] param = new int[20]; public int[] temp_param = new int[param.length]; public int[] param_lab = new int[param.length]; public String[] param_list = new String[param.length]; //連鎖メッセージ public String[] voice1 = {"いてっ","やったなー","げげげっ","大打撃っ","ふにゃぁ〜","いててててて","うわぁぁぁ〜"}; public String[] voice2 = {"えいっ","ファイヤー","アイスストーム","ダイアキュート","ブレインダムド","じゅげむ","ばよえ〜ん"}; public String[] voice; //---------------コンストラクタ--------------- public myGame(int did) { id = did; //プレイヤー if (id == 0) { voice = voice2; folder = 1; } //コンピューター else { voice = voice1; folder = 2; } //Gridオブジェクト生成 Grid = new myGrid(); //フィールド開始位置 width_c = (id%4)*((width+2)*puyo_size+100); height_c = (id-id%4)/4*(height*puyo_size+44); //初期化 myInit(); } //---------------初期化--------------- public void myInit() { //----------変数---------- if (id == 0) { AutoFlag = 0; } else { AutoFlag = 1; } //テスト用 x = ""; for (int i=0; i= 1) { chain_num[Math.min(chain_count,5)-1]++; } myConti(); } //消えた else { //連鎖 chain_count++; int cn = Math.min(chain_count,voice.length); mes = voice[cn-1]; if (SoundFlag == 1) { play(getDocumentBase(),"sound/chain/"+folder+"/"+cn+".au"); } if (max_chain_count < chain_count) { max_chain_count = chain_count; } //得点計算 myGetScore(); //落とす if (SkipFlag == 1) { mySleep(0,"Fall"); } else { if (SoundFlag == 1) { mySleep(500,"Fall"); } else { mySleep(300,"Fall"); } } repaint(); } } //---------------連鎖終了後処理--------------- int maxdef = 0; public void myConti() { //テスト表示 if (chain_count >= 1) { cc[Math.min(chain_count,5)-1]++; cc_sum++; } maxdef = Math.max(maxdef,cc[2]-cc[0]); //x = "mny="+many+",cc="+cc[0]+","+cc[1]+","+cc[2]+","+cc[3]+","+cc[4]+",md="+maxdef; repaint(); //リセット pos[0][0] = 0; pos[0][1] = left_pos; pos[1][0] = 1; pos[1][1] = left_pos; rot_pos = 0; chain_count = 0; mes = ""; //ゲームオーバー if (grid[2][2] != 0 && GameFlag[id] == 1) { if (OjaFlag == 1) { mySleep(1500,"Over"); } else { mySleep(500,"Over"); } } else { //おじゃま myOja(); //ゲームオーバー if (grid[2][2] != 0 && GameFlag[id] == 1) { if (OjaFlag == 1) { mySleep(1500,"Over"); } else { mySleep(500,"Over"); } } //落とす else { if (OjaFlag == 1) { mySleep(1000,"AutoFall"); } else { mySleep(300,"AutoFall"); } } } } //---------------connect_labをリセット--------------- public void myResetConnectLab() { for (int i=0; i EneOjaCount[id]) { OjaCount -= EneOjaCount[id]; for (int i=0; i 0) { OjaFlag = 1; //ストックのおじゃまが6個以上 if (EneOjaCount[id] >= 6) { while (EneOjaCount[id] > 30) { DamOjaCount++; EneOjaCount[id]--; } OjaHeight = (EneOjaCount[id]-EneOjaCount[id]%width)/width; OjaHeightAmari = EneOjaCount[id]%width; for (int j=0; j=0; i--) { if (grid[i][j] == 0 && DamOjaHeight > 0) { EneOjaCount[id]--; DamOjaHeight--; grid[i][j] = 1; if (DamOjaHeight == 0) { break; } } } if (DamOjaHeight > 0) { EneOjaCount[id] -= DamOjaHeight; } } } //ストックのおじゃまが6個未満 else { OjaHeightAmari = EneOjaCount[id]; } if (OjaHeightAmari > 0) { int[] Ojalist = new int[width]; for (int a=0; a 0) { Rnd_Oja_pos = (int)(Math.random()*width); if (Ojalist[Rnd_Oja_pos] == 1) { continue; } else { Ojalist[Rnd_Oja_pos] = 1; for (int i=height-1; i>=0; i--) { if (grid[i][Rnd_Oja_pos] == 0) { EneOjaCount[id]--; grid[i][Rnd_Oja_pos] = 1; break; } } } } } if (DamOjaCount > 0) { EneOjaCount[id] = DamOjaCount; DamOjaCount = 0; } repaint(); if (SoundFlag == 1) { clip[5].play(); } } } //---------------得点計算--------------- public void myGetScore() { //連鎖数補正(得点計算のため) if (chain_count > B.length-1) { chain_count = B.length-1; } //AとCとD for (int i=0; i C.length-1) { Cmax = C.length-1; } //同時消し色 if (erpuyolist[i] != 0) { Dsum++; } } //得点計算(A*10*(B+C+D) = 消しぷよ数*10*(連鎖+同時ぷよ+同時色)) if (B[chain_count]+C[Cmax]+D[Dsum-1] == 0) { BCD = 1; } else if (B[chain_count]+C[Cmax]+D[Dsum-1] > 999) { BCD = 999; } else { BCD = B[chain_count]+C[Cmax]+D[Dsum-1]; } dscore = A*10*BCD; score += dscore; //おじゃま TempOjaCount += ((dscore+OjaAmari)-(dscore+OjaAmari)%OjaRate)/OjaRate; OjaAmari = (OjaAmari+dscore)%OjaRate; //リセット A = 0; Cmax = 0; Dsum = 0; for (int i=0; i 0) { myPosChange(-1,-1,1); } else if (rot_pos == 3 && pos[0][0] > 0) { myPosChange(-1,1,1); } } //半時計回り else if (code == 2) { if (rot_pos == 0 && pos[0][1] > 0) { myPosChange(1,-1,-1); } else if (rot_pos == 3 && pos[0][0]+1 < height) { myPosChange(1,1,-1); } else if (rot_pos == 2 && pos[0][1]+1 < width) { myPosChange(-1,1,-1); } else if (rot_pos == 1 && pos[0][0] > 0) { myPosChange(-1,-1,-1); } } repaint(); } //---------------ぷよ回転の際の座標の推移--------------- public void myPosChange(int i,int j,int k) { if (grid[pos[0][0]+i][pos[0][1]+j] == 0) { if (SoundFlag == 1) { clip[3].play(); } pos[0][0] += i; pos[0][1] += j; rot_pos += k; if (rot_pos < 0) { rot_pos += 4; } rot_pos %= 4; } } //---------------ぷよ上移動--------------- public void myMoveU() { if (pos[0][0] > 1 && pos[1][0] > 1) { pos[0][0]--; pos[1][0]--; if (SoundFlag == 1) { clip[2].play(); } } repaint(); } //---------------ぷよ右移動--------------- public void myMoveR() { if (!( ((pos[0][1] == width-1) || (pos[0][1] < width-1 && grid[pos[0][0]][pos[0][1]+1] != 0)) || ((pos[1][1] == width-1) || (pos[1][1] < width-1 && grid[pos[1][0]][pos[1][1]+1] != 0)) )) { pos[0][1]++; pos[1][1]++; if (SoundFlag == 1) { clip[2].play(); } } repaint(); } //---------------ぷよ左移動--------------- public void myMoveL() { if (!( ((pos[0][1] == 0) || (pos[0][1]-1 >= 0 && grid[pos[0][0]][pos[0][1]-1] != 0)) || ((pos[1][1] == 0) || (pos[1][1]-1 >= 0 && grid[pos[1][0]][pos[1][1]-1] != 0)) )) { pos[0][1]--; pos[1][1]--; if (SoundFlag == 1) { clip[2].play(); } } repaint(); } //---------------ぷよ下移動--------------- public void myMoveD() { //下に移動する if (!( ((pos[0][0]+1 == height) || (pos[0][0]+1 < height && grid[pos[0][0]+1][pos[0][1]] != 0)) || ((pos[1][0]+1 == height) || (pos[1][0]+1 < height && grid[pos[1][0]+1][pos[1][1]] != 0)) )) { pos[0][0]++; pos[1][0]++; if (SoundFlag == 1) { clip[2].play(); } repaint(); } //下に移動できないので、積み上げる else { WeitFlag = 1; myStack(); } } //---------------ぷよ一気に下移動--------------- public void myMoveS() { //ぷよが横のとき if (pos[0][1] != pos[1][1]) { while (pos[0][0]+1 < height && grid[pos[0][0]+1][pos[0][1]] == 0) { pos[0][0]++; } while (pos[1][0]+1 < height && grid[pos[1][0]+1][pos[1][1]] == 0) { pos[1][0]++; } } //ぷよが縦のとき else { while ( pos[0][0]+1 < height && pos[1][0]+1 < height && grid[pos[0][0]+1][pos[0][1]] == 0 && grid[pos[1][0]+1][pos[1][1]] == 0 ) { for (int i=0; i<2; i++) { pos[i][0]++; } } } grid[pos[0][0]][pos[0][1]] = puyo1; grid[pos[1][0]][pos[1][1]] = puyo2; repaint(); WeitFlag = 1; myStack(); } //---------------ぷよ自動落下--------------- public void myAutoFall() { //下に移動できる if (!( ((pos[0][0]+1 == height) || (pos[0][0]+1 < height && grid[pos[0][0]+1][pos[0][1]] != 0)) || ((pos[1][0]+1 == height) || (pos[1][0]+1 < height && grid[pos[1][0]+1][pos[1][1]] != 0)) )) { pos[0][0]++; pos[1][0]++; repaint(); //スレッド ///* if (GameFlag[id] == 1) { t1[id] = null; t1[id] = new Thread(r1[id]); t1[id].start(); } //*/ } //下に移動できないので、積み上げる else if (WeitFlag == 0) { WeitFlag = 1; myStack(); } } //---------------ぷよ生成1(ロード直後のみ)--------------- public void myMakePuyo1() { //NEXTおよびNEXT2ぷよを生成 if (PuyoFlag == 1) { npuyo1 = myCopyPuyo(); npuyo2 = myCopyPuyo(); nnpuyo1 = myCopyPuyo(); nnpuyo2 = myCopyPuyo(); } else { npuyo1 = myRndPuyo(); npuyo2 = myRndPuyo(); nnpuyo1 = myRndPuyo(); nnpuyo2 = myRndPuyo(); } //初期化 if (set == 1) { //7連鎖 npuyo1 = 5; int[][] s_grid = { {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {3,0,0,0,0,0}, {2,0,0,0,0,0}, {5,0,0,0,0,0}, {5,0,0,0,0,0}, {5,4,5,6,2,0}, {2,3,4,5,6,2}, {2,3,4,5,6,2}, {2,3,4,5,6,2} }; //初期化 for (int i=0; i 36) { //(int)(width*height/3) ef1 = 1; ef2 = 1; many = 1; } else if (many == 0 || (many == 1 && puyon < 24)) { //ef1 = (int)(Math.random()*4);ef2 = 1; ef1 = 0;ef2 = 0; many = 0; } //パラメータ取得の順番を決定 if (many == 0) { param_list[2] = "ignition_sum"; //発火ぷよラベルの合計 param_list[3] = "ignition_count1"; //発火ぷよ(連結数が2以上)の個数 param_list[4] = "chain_sum"; //連鎖ラベルの合計 param_list[5] = "ignition_connect_sum"; //発火ぷよ(連結数が2以上)の連結数の合計 param_list[6] = "connect_increment1"; //発火後の連結数の増分の合計1 param_list[7] = "wall_count"; //壁の個数 param_list[8] = "connect_sum"; //最終状態の連結数 param_list[9] = "connect_increment2"; //発火後の連結数の増分の合計2 param_list[10] = "ignition_count2"; //発火ぷよ(連結数が1)の個数(連結数の合計) param_list[11] = "connect_bury_count"; //どれだけの連結数を大きくできそうな箇所が埋まっているか param_list[12] = "bury_count"; //どれだけのぷよが埋まっているか param_list[13] = "dist"; //同色ぷよまでの距離 param_list[14] = "h_point"; //低さ } else { param_list[2] = "wall_count"; //壁の個数 param_list[3] = "ignition_sum"; //発火ぷよラベルの合計 param_list[4] = "chain_sum"; //連鎖ラベルの合計 param_list[5] = "connect_sum"; //最終状態の連結数 param_list[6] = "ignition_count1"; //発火ぷよ(連結数が2以上)の個数 param_list[7] = "ignition_connect_sum"; //発火ぷよ(連結数が2以上)の連結数の合計 param_list[8] = "ignition_count2"; //発火ぷよ(連結数が1)の個数(連結数の合計) param_list[9] = "connect_increment1"; //発火後の連結数の増分の合計1 param_list[10] = "connect_increment2"; //発火後の連結数の増分の合計2 param_list[11] = "connect_bury_count"; //どれだけの連結数を大きくできそうな箇所が埋まっているか param_list[12] = "bury_count"; //どれだけのぷよが埋まっているか param_list[13] = "dist"; //同色ぷよまでの距離 param_list[14] = "h_point"; //低さ } //各々の列の高さを取得 int[] heightlist = Grid.myGetHeight(); //壁を取得 int left_wall = -1; int right_wall = width; /* for (int j=left_pos-1; j>=0; j--) { if (dummy_grid[2][j] != 0) { left_wall = j; break; } } for (int j=left_pos+1; j= 3) { //そのまま myJudgePart(heightlist[j]-1,j,puyo2,heightlist[j]-2,j,puyo1,0); //右回転 if (j+1 < right_wall && heightlist[j+1] >= 3) { myJudgePart(heightlist[j]-1,j,puyo2,heightlist[j+1]-1,j+1,puyo1,1); } //左回転 if (j-1 >= left_wall+1 && heightlist[j-1] >= 3) { myJudgePart(heightlist[j]-1,j,puyo2,heightlist[j-1]-1,j-1,puyo1,2); } //2回転 if (heightlist[j] >= 4) { myJudgePart(heightlist[j]-1,j,puyo1,heightlist[j]-2,j,puyo2,3); } } } //一番のポイントに落とす mtime = auto_j-left_pos; if (auto_r == 2 || (auto_r == 3 && mtime >= 0)) { rd = 2; } myAutoMove2(); //リセット JudgeFlag = 0; //テスト表示 x = ""; for (int i=0; i<15; i++) { x += param[i]+","; } repaint(); } //---------------移動判定--------------- public void myAutoMove2() { if (SkipFlag == 1) { if (mtime > 0) { mySleep(0,"Right"); } //右 else if (mtime < 0) { mySleep(0,"Left"); } //左 else { mySleep(0,"Rotate"); } //そのまま } else { if (mtime > 0) { mySleep(MoveSpeed,"Right"); } //右 else if (mtime < 0) { mySleep(MoveSpeed,"Left"); } //左 else { mySleep(RotaSpeed+MoveSpeed,"Rotate"); } //そのまま } } //---------------右移動--------------- public void myAutoMoveR() { myMoveR(); mtime--; if (SkipFlag == 1) { if (mtime > 0) { mySleep(0,"Right"); } else { mySleep(0,"Rotate"); } } else { if (mtime > 0) { mySleep(MoveSpeed,"Right"); } else { mySleep(RotaSpeed+MoveSpeed,"Rotate"); } } } //---------------左移動--------------- public void myAutoMoveL() { myMoveL(); mtime++; if (SkipFlag == 1) { if (mtime < 0) { mySleep(0,"Left"); } else { mySleep(0,"Rotate"); } } else { if (mtime < 0) { mySleep(MoveSpeed,"Left"); } else { mySleep(RotaSpeed+MoveSpeed,"Rotate"); } } } //---------------//落下パターン判定--------------- public void myJudgePart(int i,int j,int g,int i2,int j2,int g2,int r) { //フィールドにあるぷよと落とした組ぷよのコピーを残しておく&ラベルをリセット for (int k=0; k param[p]) { //残りのパラメータを求める for (int k=p+1; k 1 && connect_lab[i][j] != 1) { connect_lab[i][j] = 1; count++; if (i-1 >= 0 && dummy_grid[i][j] == dummy_grid[i-1][j]) { myGetConnect2(i-1,j); } if (i+1 <= height-1 && dummy_grid[i][j] == dummy_grid[i+1][j]) { myGetConnect2(i+1,j); } if (j-1 >= 0 && dummy_grid[i][j] == dummy_grid[i][j-1]) { myGetConnect2(i,j-1); } if (j+1 <= width-1 && dummy_grid[i][j] == dummy_grid[i][j+1]) { myGetConnect2(i,j+1); } } } //---------------積み上がっていたのを落とす--------------- public void myFall() { int di; for (int i=height-2; i>=0; i--) { for (int j=width-1; j>=0; j--) { if (dummy_grid[i][j] != 0) { di = i; while (di+1 < height && dummy_grid[di+1][j] == 0) { dummy_grid[di+1][j] = dummy_grid[di][j]; dummy_grid[di][j] = 0; di++; //オートモード判定中 if (IgnitionJudgeFlag == 1) { fall_lab[di][j] = fall_lab[di-1][j]+1; fall_lab[di-1][j] = 0; } } } } } //実際の場合 if (JudgeFlag == 0) { myCopy2(); repaint(); if (SkipFlag == 1) { mySleep(0,"Chain"); } else { if (SoundFlag == 1) { mySleep(500,"Chain"); } else { mySleep(300,"Chain"); } } } } //---------------連結数が4以上のぷよを消す--------------- public void myErase() { ChainFlag = 0; //全てのぷよの連結数を計算 for (int i=0; i= 4) { ChainFlag = 1; //実際に消す場合 if (JudgeFlag == 0) { erpuyolist[dummy_grid[i][j]-2]++; //色ごとに消しぷよ数を保存する用(一時的に) erased_number[dummy_grid[i][j]-2]++; //それぞれの色ぷよの消した個数をプラス } //オートモードで、発火ぷよ判定をしていない場合 else if (IgnitionJudgeFlag == 0) { erase_num++; } //消す dummy_grid[i][j] = 0; fall_lab[i][j] = 0; if (i > 0 && dummy_grid[i-1][j] == 1) { dummy_grid[i-1][j] = 0; fall_lab[i-1][j] = 0; } if (j+1 < width && dummy_grid[i][j+1] == 1) { dummy_grid[i][j+1] = 0; fall_lab[i][j+1] = 0; } if (i+1 < height && dummy_grid[i+1][j] == 1) { dummy_grid[i+1][j] = 0; fall_lab[i+1][j] = 0; } if (j > 0 && dummy_grid[i][j-1] == 1) { dummy_grid[i][j-1] = 0; fall_lab[i][j-1] = 0; } } } } } //---------------発火ぷよ判定--------------- public int[] myJudgeIgnition() { //変数初期化 IgnitionJudgeFlag = 1; //変数定義 int[] array = {0,0,0,0,0,0}; //全てのぷよについて判定 for (int i=0; i 1 && myJudgeIgnitionPlace(i,j) == 1) { //連鎖判定まだのぷよ if (pre_chain_lab[i][j] == 0) { //該当ぷよ、及びそれと連結したぷよを消して連鎖発動 myErase2(i,j,dummy_grid[i][j]); myFall(); ignition_chain_count = myChainCount()+1; //連鎖終了後の連結数の合計を算出 connect_sum2 = myGetConnectSum(); //連鎖に使ったぷよにラベルを付けて元の位置に戻す myRet(); //連鎖に使わなかったぷよの連鎖開始前の連結数の合計を算出 connect_sum1 = myGetConnectSum(); } //ぷよとfall_labを戻す for (int k=0; k= 2) { //連鎖ラベルを付ける myAttacheLab(i,j,ignition_chain_count-1,chain_lab[i][j]); myResetConnectLab(); //連結数が2以上の発火ぷよ if (connect > 1) { array[0] += connect*connect; //連結数の合計 array[1] += connect; //個数 } //連結数が1の発火ぷよ else { //array[0]++; //連結数の合計 array[2]++; //個数 } //連結数が増えていたなら、変数に値を代入 if (connect_sum2 > connect_sum1) { array[3] += (connect_sum2-connect_sum1)*connect; } } //連鎖してないぞ else { //連結数が増えていたなら、変数に値を代入 if (connect_sum2 > connect_sum1) { array[4] += connect_sum2-connect_sum1; } } } } } //発火ぷよラベルの合計を算出 for (int i=0; i 1) { array[5] += ignition_lab2[i][j]; } } } //ここまで IgnitionJudgeFlag = 0; return array; } //---------------ぷよに連鎖ラベルを付ける--------------- public void myAttacheLab(int i2,int j2,int l,int c) { int i = i2; int j = j2; if (dummy_grid[i][j] > 1 && connect_lab[i][j] != 1) { connect_lab[i][j] = 1; ignition_lab2[i][j] = l; chain_lab[i][j] = c; if (i-1 >= 0 && dummy_grid[i][j] == dummy_grid[i-1][j]) { myAttacheLab(i-1,j,l,c); } if (i+1 <= height-1 && dummy_grid[i][j] == dummy_grid[i+1][j]) { myAttacheLab(i+1,j,l,c); } if (j-1 >= 0 && dummy_grid[i][j] == dummy_grid[i][j-1]) { myAttacheLab(i,j-1,l,c); } if (j+1 <= width-1 && dummy_grid[i][j] == dummy_grid[i][j+1]) { myAttacheLab(i,j+1,l,c); } } } //---------------連鎖に使うぷよにラベルを付ける--------------- public void myRet() { //落ちたぷよを元の高さに戻す for (int i=0; i 0) { dummy_grid[i-fall_lab[i][j]][j] = dummy_grid[i][j]; dummy_grid[i][j] = 0; fall_lab[i][j] = 0; } } } //ラベル付け for (int i=0; i= 2) { chain_lab[i][j] += ignition_chain_count; } } } } //---------------発火点にぷよを置けるか判定(メイン)--------------- int rarara = 0; public int myJudgeIgnitionPlace(int i2,int j2) { int i = i2; int j = j2; rarara = 0; //if (i2+1 < height && dummy_grid[i2+1][j2] == 0) { rarara = 0; } myJudgeIgnitionPlace2(i,j); myResetConnectLab(); return rarara; } //---------------発火点にぷよを置けるか判定(再起呼び出し部)--------------- public void myJudgeIgnitionPlace2(int i,int j) { if (connect_lab[i][j] != 1) { connect_lab[i][j] = 1; rarara = myGetIgnitionPlaceLab(i,j); if (rarara == 0) { if (i-1 >= 0 && dummy_grid[i][j] == dummy_grid[i-1][j]) { myJudgeIgnitionPlace2(i-1,j); } //上 if (i+1 <= height-1 && dummy_grid[i][j] == dummy_grid[i+1][j]) { myJudgeIgnitionPlace2(i+1,j); } //下 if (j-1 >= 0 && dummy_grid[i][j] == dummy_grid[i][j-1]) { myJudgeIgnitionPlace2(i,j-1); } //左 if (j+1 <= width-1 && dummy_grid[i][j] == dummy_grid[i][j+1]) { myJudgeIgnitionPlace2(i,j+1); } //右 } } } //---------------発火点にぷよを置けるか判定(本体)--------------- public int myGetIgnitionPlaceLab(int i3, int j3) { int flag = 0; int i = i3; int j = j3; //上にぷよがない if (i-1 >= 0 && dummy_grid[i-1][j] == 0) { flag = 1; } //左にぷよがない else if ( (j-1 >= 0 && dummy_grid[i][j-1] == 0) && !(i+2 < height && dummy_grid[i+2][j-1] == 0) ) { flag = 1; } //右にぷよがない else if ( (j+1 < width && dummy_grid[i][j+1] == 0) && !(i+2 < height && dummy_grid[i+2][j+1] == 0) ) { flag = 1; } //返す return flag; } //---------------連結したぷよ群が埋まるっているか判定(メイン)--------------- public int myJudgeStack(int i2,int j2) { int i = i2; int j = j2; NotBuryFlag = 0; myJudgeStack2(i,j); myResetConnectLab(); return NotBuryFlag; } //---------------連結したぷよ群が埋まっているか判定(再起呼び出し部)--------------- public void myJudgeStack2(int i,int j) { if (connect_lab[i][j] != 1) { connect_lab[i][j] = 1; if (i-1 >= 0) { //上 if (dummy_grid[i][j] == dummy_grid[i-1][j]) { myJudgeStack2(i-1,j); } else if (dummy_grid[i-1][j] == 0) { NotBuryFlag = 1; } } if (i+1 <= height-1) { //下 if (dummy_grid[i][j] == dummy_grid[i+1][j]) { myJudgeStack2(i+1,j); } else if (dummy_grid[i+1][j] == 0) { NotBuryFlag = 1; } } if (j-1 >= 0) { //左 if (dummy_grid[i][j] == dummy_grid[i][j-1]) { myJudgeStack2(i,j-1); } else if (dummy_grid[i][j-1] == 0) { NotBuryFlag = 1; } } if (j+1 <= width-1) { //右 if (dummy_grid[i][j] == dummy_grid[i][j+1]) { myJudgeStack2(i,j+1); } else if (dummy_grid[i][j+1] == 0) { NotBuryFlag = 1; } } } } //---------------連結数を大きくできそうな箇所が他のぷよで埋まっているか判定(メイン)--------------- public int myJudgeEraseStack(int i,int j,int g) { int count = 0; int array[] = new int[color.length]; for (int k=0; k 1) { if (i+1 <= height-1 && dummy_grid[i+1][j] > 1) { array[dummy_grid[i+1][j]-2] += myJudgeEraseStack2(i+1,j,g); } //右 if (j-1 >= 0 && dummy_grid[i][j-1] > 1) { array[dummy_grid[i][j-1]-2] += myJudgeEraseStack2(i,j-1,g); } //左 if (j+1 <= width-1 && dummy_grid[i][j+1] > 1) { array[dummy_grid[i][j+1]-2] += myJudgeEraseStack2(i,j+1,g); } //下 } //数える for (int k=0; k= 2) { count++; } } //戻す return count; } //---------------連結数を大きくできそうな箇所が他のぷよで埋まっているか判定(再起呼び出し部)--------------- public int myJudgeEraseStack2(int i2,int j2,int g2) { int i = i2; int j = j2; int g = g2; int count = 0; if (dummy_grid[i][j] != 1 && dummy_grid[i][j] != g) { count++; } return count; } //---------------他の列にある同色ぷよまでの横の距離の最大値を算出--------------- public int myGetDistance() { int dist = 0; int dist1 = 0; int dist2 = 0; //代入 for (int j=0; j 1) { colorlist[j][dummy_grid[i][j]-2] = 1; } } } //やるぞ for (int i=0; i=0; l--) { if (colorlist[l][i] == 1) { dist1 = j-l; } } //右側 for (int l=j+1; l 0) { heightlist[j] = i; break; } } } return heightlist; } //---------------フィールドにあるぷよの個数を数える--------------- public int myGetPuyoNum() { int count = 0; for (int i=0; i 0) { count++; } } } return count; } //---------------連結数の合計を算出--------------- public int myGetConnectSum() { int connect_sum = 0; for (int i=0; i= 0 && dummy_grid[i-1][j] == g) { myErase2(i-1,j,g); } //上 if (i+1 <= height-1 && dummy_grid[i+1][j] == g) { myErase2(i+1,j,g); } //下 if (j-1 >= 0 && dummy_grid[i][j-1] == g) { myErase2(i,j-1,g); } //左 if (j+1 <= width-1 && dummy_grid[i][j+1] == g) { myErase2(i,j+1,g); } //右 } } //Gridクラス } //Gameクラス } //Puyoクラス