public override void Attack(GameObject target) { if (/*gameObject.tag == "Queen" &&*/ CanMove(initPos, target.transform.position) && Distance(gameObject.transform.position, target.transform.position) == 1) { target.GetComponent <Piece>().hp -= attack; base.Attack(target); } else { MovePiece.DeselectPiece(); } }
public override void Attack(GameObject target) { Debug.Log(Distance(initPos, target.transform.position)); if (CanMove(initPos, gameObject.transform.position) && Distance(initPos, target.transform.position) <= speed) { target.GetComponent <Piece>().hp -= attack; base.Attack(target); } else { MovePiece.DeselectPiece(); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && atk) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction); if (hit.transform.parent.CompareTag("White") || hit.transform.parent.CompareTag("Black")) { Attack(hit.transform.gameObject); if (hp <= 0) { knightAtk = false; atk = false; MovePiece.EndTurn(); Debug.Log(knightAtk + " " + atk + " " + Board.whiteTurn); Kill(); } } else if (hit.transform.CompareTag("Empty")) { //MovePiece.EndTurn(); int currX = (int)gameObject.transform.position.x; int currY = (int)gameObject.transform.position.y; if ((Math.Abs(currX - hit.transform.position.x) == 2 && Math.Abs(currY - hit.transform.position.y) == 1) || (Math.Abs(currX - hit.transform.position.x) == 1 && Math.Abs(currY - hit.transform.position.y) == 2)) { MoveTo(hit.transform.position); hasMoved = false; atk = false; knightAtk = false; MovePiece.EndTurn(); } else { knightAtk = false; atk = false; MovePiece.DeselectPiece(); } } else { atk = false; knightAtk = false; attacking = false; } } }
public override void Attack(GameObject target) { int currX = (int)gameObject.transform.position.x; int currY = (int)gameObject.transform.position.y; // Debug.Log() if ((Math.Abs(currX - target.transform.position.x) == 2 && Math.Abs(currY - target.transform.position.y) == 1) || (Math.Abs(currX - target.transform.position.x) == 1 && Math.Abs(currY - target.transform.position.y) == 2)) { MoveTo(target.transform.position); GameObject[] g = GameObject.FindGameObjectsWithTag("MoveOption"); for (int i = 0; i < g.Length; ++i) { Destroy(g[i]); } GameObject.FindGameObjectWithTag("MainCamera").GetComponent <MovePiece>().ShowMoves(); hasMoved = true; target.GetComponent <Piece>().hp -= attack; if (target.transform.parent.tag != gameObject.transform.parent.tag) { hp--; RefreshDisplay(); } if (target.GetComponent <Piece>().hp <= 0) { target.GetComponent <Piece>().Kill(); } else { target.GetComponent <Piece>().RefreshDisplay(); } } else if (target != gameObject) { knightAtk = false; atk = false; MovePiece.DeselectPiece(); } }
public override void Attack(GameObject target) { int currX = (int)gameObject.transform.position.x; int currY = (int)gameObject.transform.position.y; int startPosY = Math.Min(currY, (int)target.transform.position.y) + 1; int endPosY = Math.Max(currY, (int)target.transform.position.y); int startPosX = Math.Min(currX, (int)target.transform.position.x) + 1; int endPosX = Math.Max(currX, (int)target.transform.position.x); bool blocked = false; if (currX - currY == target.transform.position.x - target.transform.position.y) { int j = startPosX; for (int i = startPosY; i < endPosY; ++i) { Debug.Log(i + " " + j + Board.full[i, j]); if (Board.full[i, j]) { blocked = true; } ++j; } if (!blocked) { Debug.Log(gameObject.GetComponent <Piece>().hp); target.GetComponent <Piece>().hp -= attack; Debug.Log(gameObject.GetComponent <Piece>().hp); base.Attack(target); } else { Debug.Log("Else"); MovePiece.DeselectPiece(); } } else if (currX + currY == target.transform.position.x + target.transform.position.y) { int j = endPosX - 1; for (int i = startPosY; i < endPosY; ++i) { Debug.Log(i + " " + j); if (Board.full[i, j]) { blocked = true; } --j; } if (!blocked) { Debug.Log("If"); Debug.Log(gameObject.GetComponent <Piece>().hp); target.GetComponent <Piece>().hp -= attack; Debug.Log(gameObject.GetComponent <Piece>().hp); base.Attack(target); } else { MovePiece.DeselectPiece(); Debug.Log("Else"); } } else { MovePiece.DeselectPiece(); } }