-
-
Save daleth90/08c038b52c056f3854c1f1d64a22ab58 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
public enum Disk { NONE, DARK, LIGHT } | |
public class OthelloBoardModel : IOthelloBoardModel { | |
public event Action<int, int, Disk> OnPlaceDisk = delegate { }; | |
public event Action<int, int> OnFlipDisk = delegate { }; | |
private readonly Disk[][] board; | |
// TODO: Need SetCurrentSide() | |
private Disk currentSide = Disk.DARK; | |
public OthelloBoardModel() { | |
board = new Disk[ 8 ][]; | |
for ( int i = 0; i < 8; ++i ) { | |
board[ i ] = new Disk[ 8 ]; | |
} | |
} | |
public void TryPlaceDisk( int x, int y ) { | |
if ( x < 1 || x > 8 || y < 1 || y > 8 ) { | |
return; | |
} | |
if ( board[ x - 1 ][ y - 1 ] != Disk.NONE ) { | |
return; | |
} | |
board[ x - 1 ][ y - 1 ] = currentSide; | |
OnPlaceDisk.Invoke( x, y, currentSide ); | |
} | |
public void FlipDisk( int x, int y ) { | |
if ( x < 1 || x > 8 || y < 1 || y > 8 ) { | |
return; | |
} | |
if ( board[ x - 1 ][ y - 1 ] == Disk.NONE ) { | |
return; | |
} | |
if ( board[ x - 1 ][ y - 1 ] == Disk.DARK ) { | |
board[ x - 1 ][ y - 1 ] = Disk.LIGHT; | |
} | |
else if ( board[ x - 1 ][ y - 1 ] == Disk.LIGHT ) { | |
board[ x - 1 ][ y - 1 ] = Disk.DARK; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment