Advertisement
leomovskii

TicTacToeCell

Oct 13th, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class TicTacToeCell : MonoBehaviour {
  4.  
  5.     public SpriteRenderer sprite;
  6.     public Color redPlayerColor = Color.red;
  7.     public Color greenPlayerColor = Color.green;
  8.  
  9.     private int playerNumber;
  10.     private TicTacToe game;
  11.     private int x;
  12.     private int y;
  13.  
  14.     public void Init(TicTacToe controller, int xCoord, int yCoord) {
  15.         game = controller;
  16.         x = xCoord;
  17.         y = yCoord;
  18.     }
  19.  
  20.     public int GetNumber() {
  21.         return playerNumber;
  22.     }
  23.  
  24.     public void Claim(bool isRedPlayer) {
  25.         if (isRedPlayer) {
  26.             playerNumber = 1;
  27.             sprite.color = redPlayerColor;
  28.         } else {
  29.             playerNumber = -1;
  30.             sprite.color = greenPlayerColor;
  31.         }
  32.     }
  33.  
  34.     public void Restart() {
  35.         playerNumber = 0;
  36.         sprite.color = Color.white;
  37.     }
  38.  
  39.     private void OnMouseDown() {
  40.         if (playerNumber == 0) {
  41.             game.CellPressed(x, y);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement