import java.util.Random; import java.util.Vector; public class DinoStone extends Thread{ public int totalx = 8; public int totaly = 10; public boolean isCheckingAI = false; public boolean isComputer = false; public int[][] layout = null; public int[][] c_layout = null; public int colortotal = 3; public final int BLACKBLOCK = 99; //for test public final int BLACKBLOCK2 = 98; public final int UPBLACKSTONEH = 2; public int leastclearBlock = 3; //for test public final int DOWN = 0; public final int LEFT = 1; public final int RIGHT = 2; public static Random randomobj = new Random(); public int[] nextcolors = new int[colortotal]; public int nextposition = 0; public int[] currentcolors = new int[colortotal]; public int currentposition = 0; public int currentx = 0; public int currenty = 0; public DinoStone opponent = null; public int STEP_TIME = 500;//DSpuzzleDis.RUN_STEP_TIME; public static boolean pause = false; public int clearnumber = 0; public int clearcombo = 0; public Vector combocolor = new Vector(); public int couplenumber = 0; public boolean enemydrop = true; protected boolean enemyinited = false; public boolean enemyturn = false; public int[][] blackstone = null; public long roundstarttime = 0; public DinoStone(int totalx, int totaly, int color, DinoStone opponent) { this.totalx = totalx; this.totaly = totaly+2; layout = new int[this.totalx][this.totaly]; c_layout = new int[this.totalx][this.totaly]; //t_layout = new int[this.totalx][this.totaly]; this.opponent = opponent; //this.isComputer = false; this.colortotal = color; gameover = false; } //CLEAR THE BACKGROUND // public void initLayout(boolean ispuzzle) { // // for (int i=0; i0; i--) { for (int j=totaly; j>0; j--) { if (!checkCollision(i-1, j-1)&& layout[i-1][j-1]!=BLACKBLOCK2) { // System.out.println((i-1)+" "+(j-1)); layout[i-1][j]=layout[i-1][j-1]; layout[i-1][j-1] = 0; if (!isCheckingAI) { c_layout[i-1][j]=-c_layout[i-1][j-1]; c_layout[i-1][j-1] = 0; } matchfinished = false; } } } } public void resetc_layout() { for (int i=0; ileastclearBlock-1) { roundfinish = false; int[] tmp = null; boolean checkcolor = true; for (int i=0; ileastclearBlock-1) { roundfinish = false; int[] tmp = null; boolean checkcolor = true; for (int i=0; i=leastclearBlock) { int length = clearlist.size(); for (int t=0; t=leastclearBlock)) { int length = clearlist.size(); for (int t=0; t0){ couplenumber = couplenumber+clearlist.size()-1; // System.out.println("couple: "+couplenumber); // System.out.println("size: "+clearlist.size()); } clearlist = new Vector(); } return clearlist; } public Vector checkenemyclear(Vector list, int index) { int[] temp = (int[])list.elementAt(index); if (temp[0]>0) { // System.out.println("test1"); if (layout[temp[0]-1][temp[1]] == BLACKBLOCK || layout[temp[0]-1][temp[1]] == BLACKBLOCK2) { // System.out.println("test1-1"); list.addElement(new int[]{temp[0]-1, temp[1]}); } } if (temp[0]2) { // System.out.println("test3"); if (layout[temp[0]][temp[1]-1] == BLACKBLOCK || layout[temp[0]][temp[1]-1] == BLACKBLOCK2) { // System.out.println("test3-1"); list.addElement(new int[]{temp[0], temp[1]-1}); } } if (temp[1]=leastclearBlock) { int length = clearlist.size(); for (int t=0; t=leastclearBlock)) { int length = clearlist.size(); for (int t=0; t0){ couplenumber = couplenumber+clearlist.size()-1; // System.out.println("couple: "+couplenumber); //System.out.println("size: "+clearlist.size()); } clearlist = new Vector(); } return clearlist; } public void enemydropDown() { dropfinished = false; boolean col = false; for (int i=0; itotaly-3-UPBLACKSTONEH) { blackstone[i][1] = blackstone[i][1] + 2; // System.out.println("check: "+(totaly - blackstone[i][1])); if((totaly - blackstone[i][1])>enemyh) { enemyh=totaly - blackstone[i][1]; } } } System.out.println("enemyh: "+enemyh); //int enemyh = blackstone.length/totalx +1; for (int i=0; i=totaly-enemyh) { layout[j][i] = BLACKBLOCK; }else { layout[j][i] = layout[j][i+enemyh]; } } } // } loadlayout(); } public void initCurrentBlock() { matchfinished = false; dropfinished = false; currentx = totalx / 2 - 1; currenty = 0; currentcolors = nextcolors; currentposition = nextposition; loadlayout(); } //ROTATE THE STONE FOR ONCE public void rotate() { if (!onclick) { onclick = true; if (!checkBlockCollision(DOWN)) { clearBlock(); currentposition++; if (currentposition>3) { currentposition = 0; } loadlayout(); } // if (checkBlockCollision(DOWN)) { // //}else { // currentposition--; // if (currentposition<0) { // currentposition = 3; // } // clearBlock(); // loadlayout(); // } onclick = false; } } public boolean onclick = false; public void move(int direction) { if (!onclick) { onclick = true; //if (!enemyinited) { // if (!checkBlockCollision(DOWN)) { switch(direction) { case LEFT: if (!checkBlockCollision(LEFT)) { clearBlock(); currentx--; // loadlayout(); } // if (checkBlockCollision(DOWN)) { // // currentx++; // clearBlock(); // } break; case RIGHT: if (!checkBlockCollision(RIGHT)) { clearBlock(); currentx++; // loadlayout(); } // if (checkBlockCollision(DOWN)) { // // currentx--; // clearBlock(); // } break; case DOWN: if (!checkBlockCollision(DOWN)) { clearBlock(); currenty++; // while(!dropfinished) { // dropDown(); // } // System.out.println("move down"); } break; } // } loadlayout(); // }else if (direction==DOWN){ // enemydropDown(); // } onclick = false; } } //boolean enemyturn = false; public void loadlayout() { //System.out.println("currenty: "+currenty); //System.out.println("currentp: "+currentposition); if (!isCheckingAI) { resetc_layout(); } //System.out.println("abc"); if (!enemyinited) { switch(currentposition) { case 0: layout[currentx][currenty] = currentcolors[0]; layout[currentx+1][currenty] = currentcolors[1]; layout[currentx+1][currenty+1] = currentcolors[2]; if (!isCheckingAI) { c_layout[currentx][currenty] = -currentcolors[0]; c_layout[currentx+1][currenty] = -currentcolors[1]; c_layout[currentx+1][currenty+1] = -currentcolors[2]; } break; case 1: layout[currentx+1][currenty] = currentcolors[0]; layout[currentx+1][currenty+1] = currentcolors[1]; layout[currentx][currenty+1] = currentcolors[2]; if (!isCheckingAI) { c_layout[currentx+1][currenty] = -currentcolors[0]; c_layout[currentx+1][currenty+1] = -currentcolors[1]; c_layout[currentx][currenty+1] = -currentcolors[2]; } break; case 2: layout[currentx+1][currenty+1] = currentcolors[0]; layout[currentx][currenty+1] = currentcolors[1]; layout[currentx][currenty] = currentcolors[2]; if (!isCheckingAI) { c_layout[currentx+1][currenty+1] = -currentcolors[0]; c_layout[currentx][currenty+1] = -currentcolors[1]; c_layout[currentx][currenty] = -currentcolors[2]; } break; case 3: layout[currentx][currenty+1] = currentcolors[0]; layout[currentx][currenty] = currentcolors[1]; layout[currentx+1][currenty] = currentcolors[2]; if (!isCheckingAI) { c_layout[currentx][currenty+1] = -currentcolors[0]; c_layout[currentx][currenty] = -currentcolors[1]; c_layout[currentx+1][currenty] = -currentcolors[2]; } break; } // System.out.println("layout "+layout[currentx][currenty]); } else { // System.out.println("check3"); for (int i=0; i 0) { try { DinoStone.sleep(sleeptime); } catch (Exception e) { } } } } gameover = true; } public void doAction() { if (!dropfinished) { clearcombo = -1; clearnumber = 0; combocolor = new Vector(); // System.out.println("onclick: "+onclick); if (enemyinited) { for (int i=0; i<3; i++) { enemydropDown(); if (dropfinished) break; } } else { // if (!onclick) dropDown(); } } else if (!matchfinished){ //System.out.println("matching"); domatch(); } if (matchfinished) { doclear(); } } }