/OthelloBoardView.cs Secret
Last active
April 1, 2018 15:53
Star
You must be signed in to star a gist
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; | |
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