Android 모바일 게임 2048 핵심 기능

20603 단어
  1 private void swipeUp(){ //      
  3         for (int x = 0; x < 4; x++) { //     
  4             for (int y = 0; y < 4; y++) { //     
  5                 for (int y1 = y+1; y1 < 4; y1++) { //            
  6                     if (Matrix[x][y1].getNum()>0) { //            (    ),     
  7                         if (Matrix[x][y].getNum()<=0) { //         ,                 
  9                             int yoy =y1 - y; //      
 10                             ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,0, 
 11                                     Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,-yoy); //-yoy   ,    0, y        yoy     
 12                             ta.setDuration(100); //      
 13                             Matrix[x][y1].startAnimation(ta); //    
 15                             Matrix[x][y].setNum(Matrix[x][y1].getNum()); //       ,    
 16                             Matrix[x][y1].setNum(0); //          ,    
 17                             y--; //break                  ,                                           
break; //break , 20 }else if (Matrix[x][y].equals(Matrix[x][y1])) { // 22 int yoy =y1 - y; // 23 ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,0, 24 Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,-yoy); //-yoy , 0, y yoy 25 ta.setDuration(100); // 26 Matrix[x][y1].startAnimation(ta); // 28 Matrix[x][y].setNum(Matrix[x][y1].getNum()*2); // , 29 Matrix[x][y1].setNum(0); // ,
break; // , 33 }else { 34 break; // , 35 } 36 } 37 } 38 } 39 } 41 } 42 43 private void swipeDown(){ // 45 for (int x = 0; x < 4; x++) { 46 for (int y = 3; y >= 0; y--) { 47 for (int y1 = y-1; y1 >= 0; y1--) { 48 if (Matrix[x][y1].getNum()>0) { 49 if (Matrix[x][y].getNum()<=0) { 51 int yoy =y1 - y; 52 ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,0, 53 Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,-yoy); 54 ta.setDuration(100); 55 Matrix[x][y1].startAnimation(ta); 57 Matrix[x][y].setNum(Matrix[x][y1].getNum()); 58 Matrix[x][y1].setNum(0); 59 y++;
break; 62 }else if (Matrix[x][y].equals(Matrix[x][y1])) { 64 int yoy =y1 - y; 65 ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,0, 66 Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,-yoy); 67 ta.setDuration(100); 68 Matrix[x][y1].startAnimation(ta); 70 Matrix[x][y].setNum(Matrix[x][y1].getNum()*2); 71 Matrix[x][y1].setNum(0);
break; 75 }else { 76 break; 77 } 78 } 79 } 80 } 81 } 83 } 84 85 private void swipeLeft(){ // 87 for (int y = 0; y < 4; y++) { 88 for (int x = 0; x < 4; x++) { 89 for (int x1 = x+1; x1 < 4; x1++) { 90 if (Matrix[x1][y].getNum()>0) { 91 if (Matrix[x][y].getNum()<=0) { 93 int xox =x1 - x; 94 ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,-xox, 95 Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,0); 96 ta.setDuration(100); 97 Matrix[x1][y].startAnimation(ta); 99 Matrix[x][y].setNum(Matrix[x1][y].getNum()); 100 Matrix[x1][y].setNum(0); 101 x--;
break; 104 }else if (Matrix[x][y].equals(Matrix[x1][y])) { 106 int xox =x1 - x; 107 ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,-xox, 108 Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,0); 109 ta.setDuration(100); 110 Matrix[x1][y].startAnimation(ta); 112 Matrix[x][y].setNum(Matrix[x1][y].getNum()*2); 113 Matrix[x1][y].setNum(0);
break; 117 }else { 118 break; 119 } 120 } 121 } 122 } 123 } 125 } 126 127 private void swipeRight(){ // 129 for (int y = 0; y < 4; y++) { 130 for (int x = 3; x >= 0; x--) { 131 for (int x1 = x-1; x1 >= 0; x1--) { 132 if (Matrix[x1][y].getNum()>0) { 133 if (Matrix[x][y].getNum()<=0) { 135 int xox =x1 - x; 136 ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,-xox, 137 Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,0); 138 ta.setDuration(100); 139 Matrix[x1][y].startAnimation(ta); 141 Matrix[x][y].setNum(Matrix[x1][y].getNum()); 142 Matrix[x1][y].setNum(0); 143 x++;
break; 146 }else if (Matrix[x][y].equals(Matrix[x1][y])) { 148 int xox =x1 - x; 149 ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,-xox, 150 Animation.RELATIVE_TO_SELF,0, Animation.RELATIVE_TO_SELF,0); 151 ta.setDuration(100); 152 Matrix[x1][y].startAnimation(ta); 154 Matrix[x][y].setNum(Matrix[x1][y].getNum()*2); 155 Matrix[x1][y].setNum(0);
break; 159 }else { 160 break; 161 } 162 } 163 } 164 } 165 } 167 }

좋은 웹페이지 즐겨찾기