Skip to content

Commit

Permalink
switching x and y due to the way the memory was allocated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Monteiro committed May 10, 2015
1 parent 0182c1d commit 1880c8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions SonarMinefield/.classpath
Expand Up @@ -3,7 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
46 changes: 23 additions & 23 deletions SonarMinefield/src/br/odb/sonarminefield/GameSession.java
Expand Up @@ -69,10 +69,10 @@ public void placeRandomMines( int n ) {
x = random.nextInt( WIDTH - 2 ) + 1;
y = random.nextInt( HEIGHT - 2 ) + 1;

if ( map[ x ][ y ] != POSITION_MINE ) {
if ( map[ y ][ x ] != POSITION_MINE ) {

--n;
map[ x ][ y ] = POSITION_MINE;
map[ y ][ x ] = POSITION_MINE;
}
}

Expand All @@ -83,7 +83,7 @@ public void placeRandomMines( int n ) {
private void placeNumbersOnBoard() {
for ( int x = 1; x < getWidth() - 1; ++x ) {
for ( int y = 1; y < getHeight() - 1; ++y ) {
if ( map[ x ][ y ] == POSITION_MINE ) {
if ( map[ y ][ x ] == POSITION_MINE ) {

if ( map[ x - 1 ][ y - 1 ] != POSITION_MINE)
++map[ x - 1 ][ y - 1 ];
Expand Down Expand Up @@ -118,7 +118,7 @@ public boolean isCoveredAt( int x, int y ) {
if ( x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT )
return true;

return covered[ x ][ y ];
return covered[ y ][ x ];
}

public int getWidth() {
Expand All @@ -136,7 +136,7 @@ public int getPos(int x, int y) {
if ( x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT )
return POSITION_BLANK;

return map[ x ][ y ];
return map[ y ][ x ];
}

public void poke(int x, int y) {
Expand All @@ -146,31 +146,31 @@ public void poke(int x, int y) {

if ( flagged[ x][ y ] ) {

flagged[ x ][ y ] = false;
flagged[ y ][ x ] = false;
return;
}


switch ( map[ x ][ y ] ) {
switch ( map[ y ][ x ] ) {
case POSITION_MINE:

map[ x ][ y ] = GameSession.POSITION_MINE_POKED;
map[ y ][ x ] = GameSession.POSITION_MINE_POKED;
gameState = GameSession.GAMESTATE_GAMEOVER;
return;

case POSITION_BLANK:
floodUncover( x, y );

if ( covered[ x ][ y ] && !flagged[ x ][ y ] )
if ( covered[ y ][ x ] && !flagged[ y ][ x ] )
this.remainingTilesToClear--;

covered[ x ][ y ] = false;
covered[ y ][ x ] = false;
default:

if ( covered[ x ][ y ] )
if ( covered[ y ][ x ] )
this.remainingTilesToClear--;

covered[ x ][ y ] = false;
covered[ y ][ x ] = false;
}

if ( this.remainingTilesToClear == mines )
Expand All @@ -181,14 +181,14 @@ public void poke(int x, int y) {


private void floodUncover(int x, int y) {
if ( covered[ x ][ y ] && !flagged[ x ][ y ] ) {
if ( covered[ y ][ x ] && !flagged[ y ][ x ] ) {

if ( map[ x ][ y ] == POSITION_BLANK ) {
if ( map[ y ][ x ] == POSITION_BLANK ) {

if ( covered[ x ][ y ] )
if ( covered[ y ][ x ] )
this.remainingTilesToClear--;

covered[ x ][ y ] = false;
covered[ y ][ x ] = false;

if ( x > 0)
floodUncover( x - 1, y );
Expand All @@ -215,12 +215,12 @@ private void floodUncover(int x, int y) {
floodUncover( x - 1, y + 1);


} if ( map[ x ][ y ] != POSITION_MINE ) {
} if ( map[ y ][ x ] != POSITION_MINE ) {

if ( covered[ x ][ y ] )
if ( covered[ y ][ x ] )
this.remainingTilesToClear--;

covered[ x ][ y ] = false;
covered[ y ][ x ] = false;
}
}
}
Expand All @@ -238,21 +238,21 @@ public boolean isVictory() {
public void uncoverAt(int x, int y) {

if ( isValid( x, y ) ) {
covered[ x ][ y ] = false;
flagged[ x ][ y ] = false;
covered[ y ][ x ] = false;
flagged[ y ][ x ] = false;
}
}

public void flag(int x, int y) {

if ( isValid( x, y ) )
flagged[ x ][ y ] = !flagged[ x ][ y ];
flagged[ y ][ x ] = !flagged[ y ][ x ];
}

public boolean isFlaggedAt(int x, int y) {

if ( isValid( x, y ) )
return flagged[ x ][ y ];
return flagged[ y ][ x ];
else
return false;
}
Expand Down

0 comments on commit 1880c8e

Please sign in to comment.