Skip to content

Instantly share code, notes, and snippets.

@daleth90
Last active Apr 1, 2018
Embed
What would you like to do?
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