Skip to content

Commit

Permalink
Atualizando regra para vitoria
Browse files Browse the repository at this point in the history
  • Loading branch information
Horácio Dias committed Apr 1, 2014
1 parent 0a156b9 commit 5a3fc8d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 41 deletions.
34 changes: 17 additions & 17 deletions .cproject
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1125265447">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1125265447" moduleId="org.eclipse.cdt.core.settings" name="Default">
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.619598920">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.619598920" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration buildProperties="" id="cdt.managedbuild.toolchain.gnu.base.1125265447" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.1125265447.769596826" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1692134558" name="cdt.managedbuild.toolchain.gnu.base" superClass="cdt.managedbuild.toolchain.gnu.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.449213970" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
<builder id="cdt.managedbuild.target.gnu.builder.base.1577194031" managedBuildOn="false" name="Gnu Make Builder.Default" superClass="cdt.managedbuild.target.gnu.builder.base"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1170520424" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1887065588" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"/>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1820147869" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"/>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.342744390" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1700698774" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.assembler.base.1253322162" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"/>
<configuration buildProperties="" id="cdt.managedbuild.toolchain.gnu.base.619598920" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.619598920.1761807313" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1909561670" name="cdt.managedbuild.toolchain.gnu.base" superClass="cdt.managedbuild.toolchain.gnu.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.93859697" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
<builder id="cdt.managedbuild.target.gnu.builder.base.2012480055" managedBuildOn="false" name="Gnu Make Builder.Default" superClass="cdt.managedbuild.target.gnu.builder.base"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.263751506" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1388448643" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"/>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1155203049" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"/>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1116720142" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1480118271" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.assembler.base.1357004509" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"/>
</toolChain>
</folderInfo>
</configuration>
Expand All @@ -48,7 +48,7 @@
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="2048.null.1083724022" name="2048"/>
<project id="2048.null.594534179" name="2048"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>
Binary file modified src/2048
Binary file not shown.
55 changes: 31 additions & 24 deletions src/2048.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void printNumero(int numero);
void debug();

int acrescentarEspaco(int x);
int somarPontos(int x) {
void somarPontos(int x) {
pontos += x;
}
int getRandom();
Expand All @@ -46,14 +46,14 @@ void desenhaMatriz();

void loopJogo();

bool moveEsquerda();
bool moveDireita();
bool moveCima();
bool moveBaixo();
bool moveEsquerda(bool *vitoria);
bool moveDireita(bool *vitoria);
bool moveCima(bool *vitoria);
bool moveBaixo(bool *vitoria);

void novoNumero();
bool perdeu();
bool venceu();
bool venceu(int &x, int &y );

int main() {
inicializandoTela();
Expand Down Expand Up @@ -150,17 +150,18 @@ void loopJogo() {
printw(" ");
attron(COLOR_PAIR(2));
refresh();
bool vitoria = false;
if (tecla == 'w' || tecla == 'W') {
movimento = moveCima();
movimento = moveCima(&vitoria);
} else if (tecla == 's' || tecla == 'S') {
movimento = moveBaixo();
movimento = moveBaixo(&vitoria);
} else if (tecla == 'd' || tecla == 'D') {
movimento = moveDireita();
movimento = moveDireita(&vitoria);
} else if (tecla == 'a' || tecla == 'A') {
movimento = moveEsquerda();
movimento = moveEsquerda(&vitoria);
}
bool derrota = perdeu();
bool vitoria = venceu();

if(movimento && !derrota && !vitoria){
novoNumero();
}
Expand Down Expand Up @@ -223,9 +224,10 @@ int getNumero() {
int getRandom() {
srand(time( NULL));
int r = rand() % QUATRO;
return r;
}

bool moveDireita() {
bool moveDireita(bool *vitoria) {
bool fezMovimento = false;
for (int linha = ZERO; linha < QUATRO; linha++) {
for (int coluna = ZERO; coluna <= TRES; coluna++) {
Expand All @@ -252,6 +254,9 @@ bool moveDireita() {
int colunaAtual = TRES;
for (int coluna = colunaAtual; coluna >= ZERO; coluna--) {
if(matriz[linha][coluna] != ZERO){
if(!*vitoria){
*vitoria = venceu(linha,coluna);
}
colunaAtual--;
continue;
}
Expand All @@ -270,7 +275,7 @@ bool moveDireita() {
return fezMovimento;
}

bool moveEsquerda() {
bool moveEsquerda(bool *vitoria) {
bool fezMovimento = false;
for (int linha = ZERO; linha < QUATRO; linha++) {
for (int coluna = TRES; coluna > ZERO; coluna--) {
Expand Down Expand Up @@ -298,6 +303,9 @@ bool moveEsquerda() {
int colunaAtual = ZERO;
for (int coluna = colunaAtual; coluna < QUATRO; coluna++) {
if(matriz[linha][coluna] != ZERO){
if(!*vitoria){
*vitoria = venceu(linha,coluna);
}
colunaAtual++;
continue;
}
Expand All @@ -315,7 +323,7 @@ bool moveEsquerda() {
return fezMovimento;
}

bool moveBaixo() {
bool moveBaixo(bool *vitoria) {
bool fezMovimento = false;
for (int coluna = ZERO; coluna < QUATRO; coluna++) {
for (int linha = ZERO; linha < TRES; linha++) {
Expand Down Expand Up @@ -343,6 +351,9 @@ bool moveBaixo() {
int linhaAtual = TRES;
for (int linha = linhaAtual; linha >= ZERO; linha--) {
if(matriz[linha][coluna] != ZERO){
if(!*vitoria){
*vitoria = venceu(linha,coluna);
}
linhaAtual--;
continue;
}
Expand All @@ -361,7 +372,7 @@ bool moveBaixo() {
return fezMovimento;
}

bool moveCima() {
bool moveCima(bool *vitoria) {
bool fezMovimento = false;
for (int coluna = ZERO; coluna < QUATRO; coluna++) {
for (int linha = TRES; linha > ZERO; linha--) {
Expand Down Expand Up @@ -389,6 +400,9 @@ bool moveCima() {
int linhaAtual = ZERO;
for (int linha = linhaAtual; linha < QUATRO; linha++) {
if(matriz[linha][coluna] != ZERO){
if(!*vitoria){
*vitoria = venceu(linha,coluna);
}
linhaAtual++;
continue;
}
Expand Down Expand Up @@ -443,15 +457,8 @@ bool perdeu(){
return perdeu;
}

bool venceu(){
for(int i = ZERO; i< QUATRO;i++){
for(int j = ZERO; j< QUATRO;j++){
if(valorVitoria = matriz[i][j]){
return true;
}
}
}
return false;
bool venceu(int &x, int &y ){
return (valorVitoria == matriz[x][y]);
}


0 comments on commit 5a3fc8d

Please sign in to comment.