Skip to content

Instantly share code, notes, and snippets.

@daleth90
Last active April 1, 2018 15:53
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/b264b4080c44f17740a2345c09051565 to your computer and use it in GitHub Desktop.
Save daleth90/b264b4080c44f17740a2345c09051565 to your computer and use it in GitHub Desktop.
using System;
using UnityEngine;
public class OthelloBoardView : MonoBehaviour, IOthelloBoardView {
[SerializeField]
private GameObject diskPrefab;
public event Action<int, int> OnClickTile = delegate { };
private GameObject[][] board;
private void Awake() {
transform.position = new Vector3( 4f, 4f, 0f );
Camera.main.transform.position = new Vector3( 4f, 4f, -10f );
board = new GameObject[ 8 ][];
for ( int i = 0; i < 8; ++i ) {
board[ i ] = new GameObject[ 8 ];
}
}
private void OnMouseUpAsButton() {
Vector3 worldPoint = Camera.main.ScreenToWorldPoint( Input.mousePosition );
OnClickTile( 9 - Mathf.CeilToInt( worldPoint.y ), Mathf.CeilToInt( worldPoint.x ) );
}
public void PlaceDisk( int x, int y, Disk disk ) {
if ( disk == Disk.DARK ) {
board[ x - 1 ][ y - 1 ] = Instantiate( diskPrefab, new Vector3( y - 0.5f, 8.5f - x, -0.6f ), Quaternion.Euler( 0f, 0f, 0f ) );
}
else {
board[ x - 1 ][ y - 1 ] = Instantiate( diskPrefab, new Vector3( y - 0.5f, 8.5f - x, -0.6f ), Quaternion.Euler( 180f, 0f, 0f ) );
}
}
// TODO
public void FlipDisk( int x, int y ) {
throw new NotImplementedException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment