Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MovePlate : MonoBehaviour
- {
- public GameObject controller;
- GameObject reference = null;
- // Board position, not world position
- int matrixX;
- int matrixY;
- // false: movement, true: attack
- public bool attack = false;
- public void Start()
- {
- if (attack){
- // Change to red
- gameObject.GetComponent<SpriteRenderer>().color = new Color(1.0f, 0.0f, 0.0f, 1.0f);
- }
- }
- public void OnMouseUp()
- {
- controller = GameObject.FindGameObjectWithTag("GameController");
- if (attack)
- {
- GameObject cp = controller.GetComponent<Game>().GetPosition(matrixX, matrixY);
- if (cp.name == "white_king") controller.GetComponent<Game>().Winner("black");
- if (cp.name == "black_king") controller.GetComponent<Game>().Winner("white");
- Destroy(cp);
- }
- // Clear old postion after moving chess piece
- controller.GetComponent<Game>().SetPositionEmpty(reference.GetComponent<Chessman>().GetXBoard(), reference.GetComponent<Chessman>().GetYBoard());
- // Set new position for chess piece after moving
- reference.GetComponent<Chessman>().SetXBoard(matrixX);
- reference.GetComponent<Chessman>().SetYBoard(matrixY);
- reference.GetComponent<Chessman>().SetCoords();
- controller.GetComponent<Game>().SetPosition(reference);
- controller.GetComponent<Game>().NextTurn();
- // Destroy move plate
- reference.GetComponent<Chessman>().DestroyMovePlates();
- controller.GetComponent<Game>().UpdateBoardState();
- }
- public void SetCoords(int x, int y)
- {
- matrixX = x;
- matrixY = y;
- }
- // Setter and Getter
- public void SetReference(GameObject obj){
- reference = obj;
- }
- public GameObject GetReference(){
- return reference;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement