Skip to content

Instantly share code, notes, and snippets.

@daleth90
Last active April 29, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daleth90/4b9aab2dbca5555bedd7fec796ed8666 to your computer and use it in GitHub Desktop.
Save daleth90/4b9aab2dbca5555bedd7fec796ed8666 to your computer and use it in GitHub Desktop.
modified for request
using System;
using Zenject;
public class OthelloGame : IInitializable {
private readonly OthelloBoardModel othelloBoard;
public OthelloGame( OthelloBoardModel othelloBoard ) {
this.othelloBoard = othelloBoard;
}
public void Initialize() {
StartNewGame();
}
public void StartNewGame() {
othelloBoard.SetSide( Disk.DARK );
othelloBoard.PlaceDisk( 4, 5 );
othelloBoard.PlaceDisk( 5, 4 );
othelloBoard.SetSide( Disk.LIGHT );
othelloBoard.PlaceDisk( 4, 4 );
othelloBoard.PlaceDisk( 5, 5 );
othelloBoard.SetSide( Disk.DARK );
othelloBoard.OnRequestDisk += ValidatePlacement;
}
private void ValidatePlacement( int x, int y, Disk disk ) {
othelloBoard.PlaceDisk( x, y );
if ( disk == Disk.DARK ) {
othelloBoard.SetSide( Disk.LIGHT );
}
else if ( disk == Disk.LIGHT ) {
othelloBoard.SetSide( Disk.DARK );
}
else {
throw new ArgumentException( "Place \"None\" disk which is impossible in the game" );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment