Android Open Source - 2048GameAndroid Utils






From Project

Back to project page 2048GameAndroid.

License

The source code is released under:

Apache License

If you think the Android project 2048GameAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package zhengxiao.myapplication.game;
//from   www  . j a  va  2 s.  c om
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhengxiao on 12/16/14.
 */
public class Utils {

    public static int[][] makeMatrixFrom(int[] array, int rowCount){
        int[][] out = new int[rowCount][rowCount];
        for (int i = 0; i < array.length; i++) {
            out[i / rowCount][i % rowCount] = array[i];
        }
        return out;
    }

    public static int[] makeBoardFrom(int[][] a, int rowCount){
        int[] out = new int[rowCount * rowCount];
        for (int i = 0; i < out.length; i++) {
            out[i] = a[i /rowCount][i % rowCount];
        }
        return out;
    }

    public static void rotateMatrix(int[][] a) {
        int m = 0;
        for (int i = 0; i < a.length; ++i) {
            for (int j = m; j < a[0].length; ++j) {
                int tmp = a[i][j];
                a[i][j] = a[j][i];
                a[j][i] = tmp;
            }
            m++;
        }

        for (int i = 0; i < a.length; ++i) {
            int end = a.length - 1;
            for (int j = 0; j < a[0].length; j++) {
                if (j >= end)
                    break;
                int tmp = a[i][j];
                a[i][j] = a[i][end];
                a[i][end] = tmp;
                end--;
            }
        }
    }

    public static int[] toArray(List<Integer> list) {
        int[] array = new int[list.size()];
        for (int i = 0; i< list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    }

    public static List<Integer> toList(int[] array){
        List<Integer> list = new ArrayList<>(array.length);
        for (int anArray : array) {
            list.add(anArray);
        }
        return list;
    }
}




Java Source Code List

zhengxiao.myapplication.ApplicationTest.java
zhengxiao.myapplication.GameActivity.java
zhengxiao.myapplication.MainActivity.java
zhengxiao.myapplication.game.BoardTest.java
zhengxiao.myapplication.game.Board.java
zhengxiao.myapplication.game.Direction.java
zhengxiao.myapplication.game.GameTest.java
zhengxiao.myapplication.game.Game.java
zhengxiao.myapplication.game.Position.java
zhengxiao.myapplication.game.Utils.java
zhengxiao.myapplication.utils.OnGestureListenerAdapter.java