Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class TicTacToeCell : MonoBehaviour {
- public SpriteRenderer sprite;
- public Color redPlayerColor = Color.red;
- public Color greenPlayerColor = Color.green;
- private int playerNumber;
- private TicTacToe game;
- private int x;
- private int y;
- public void Init(TicTacToe controller, int xCoord, int yCoord) {
- game = controller;
- x = xCoord;
- y = yCoord;
- }
- public int GetNumber() {
- return playerNumber;
- }
- public void Claim(bool isRedPlayer) {
- if (isRedPlayer) {
- playerNumber = 1;
- sprite.color = redPlayerColor;
- } else {
- playerNumber = -1;
- sprite.color = greenPlayerColor;
- }
- }
- public void Restart() {
- playerNumber = 0;
- sprite.color = Color.white;
- }
- private void OnMouseDown() {
- if (playerNumber == 0) {
- game.CellPressed(x, y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement