Created
February 14, 2017 01:34
-
-
Save LucasAlfare/2634fda4ffd4189b31116a117321e119 to your computer and use it in GitHub Desktop.
Nova classe do square...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.main; | |
import java.util.Arrays; | |
/** | |
* Created by Lucas Sousa on 13/02/17. | |
*/ | |
public class Square { | |
private int[] u_pecas = {0,1,1,0,1,1,0,1,1,0,1,1}; | |
private int[] d_pecas = {0,1,1,0,1,1,0,1,1,0,1,1}; | |
private int x, y; | |
public void U_D(int x, int y){ | |
U(x); /**/ D(y); | |
} | |
public void U(int movimento){ | |
for (int i = 0; i < 12 + movimento; i++){ | |
up(); | |
} | |
x = movimento; | |
} | |
public void D(int movimento){ | |
for (int i = 0; i < 12 + movimento; i++){ | |
down(); | |
} | |
y = movimento; | |
} | |
private void up(){ | |
int[] aux = new int[12]; | |
aux[0] = u_pecas[u_pecas.length - 1]; | |
System.arraycopy(u_pecas, 0, aux, 1, aux.length - 1); | |
u_pecas = aux; | |
} | |
private void down(){ | |
int[] aux = new int[12]; | |
aux[0] = d_pecas[d_pecas.length - 1]; | |
System.arraycopy(d_pecas, 0, aux, 1, aux.length - 1); | |
d_pecas = aux; | |
} | |
public void barra(){ | |
int[] u = Arrays.copyOfRange(u_pecas, 1, 7); | |
int[] d = Arrays.copyOfRange(d_pecas, 0, 6); | |
for (int i = 0; i < 6; i++){ | |
u_pecas[i+1] = d[i]; | |
d_pecas[i] = u[i]; | |
} | |
} | |
public boolean bloqueado(){ | |
return (u_pecas[0] == 1 && u_pecas[1] == 1) | |
|| (u_pecas[6] == 1 && u_pecas[7] == 1) | |
|| (d_pecas[11] == 1 && d_pecas[0] == 1) | |
|| (d_pecas[5] == 1 && d_pecas[6] == 1); | |
} | |
public boolean mesmoShape(Square x){ | |
boolean mesmoShape = false; | |
for (int i = 0; i < 12; i++){ | |
if ((x.getU_pecas()[i] == u_pecas[i]) && (x.getD_pecas()[i] == d_pecas[i])){ | |
mesmoShape = true; | |
} else { | |
mesmoShape = false; | |
break; | |
} | |
} | |
return mesmoShape; | |
} | |
public int[] getU_pecas() { | |
return u_pecas; | |
} | |
public int[] getD_pecas() { | |
return d_pecas; | |
} | |
@Override | |
public String toString() { | |
return "Topo: " + Arrays.toString(u_pecas) + "\n" + | |
"Base: " + Arrays.toString(d_pecas) + "\n\n" + | |
"Bloqueado: " + bloqueado(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment