public void TryMove(int x1, int y1, int x2, int y2) { startDrag = new Vector2(x1, y1); endDrag = new Vector2(x2, y2); selectedSoldierCard = cards [x1, y1]; //MoveSoldier (selectedSoldier, x2, y2); //if out of bounds if (x2 < 0 || x2 >= cards.Length || y2 < 0 || y2 >= cards.Length) { if (selectedSoldierCard != null) { MoveSoldier(selectedSoldierCard, x1, y1); } startDrag = Vector2.zero; selectedSoldierCard = null; return; } if (selectedSoldierCard != null) { //soldier not moved if (endDrag == startDrag) { MoveSoldier(selectedSoldierCard, x1, y1); startDrag = Vector2.zero; selectedSoldierCard = null; return; } if (selectedSoldierCard.moving == false) { MoveSoldier(selectedSoldierCard, x1, y1); startDrag = Vector2.zero; selectedSoldierCard = null; return; } //check if valid move if (selectedSoldierCard.ValidMove(cards, x1, y1, x2, y2) && selectedSoldierCard.moving == true) { cards[x2, y2] = selectedSoldierCard; cards[x1, y1] = null; MoveSoldier(selectedSoldierCard, x2, y2); selectedSoldierCard.moving = false; } else if (selectedSoldierCard.attacking == true) { if (selectedSoldierCard.GetComponent <attack>() == null) { selectedSoldierCard.gameObject.AddComponent <attack>(); } if (selectedSoldierCard.GetComponent <OneSoldierManager>().isBlue) { //Networking action msg = "CATK|"; msg += x1 + "|"; msg += y1.ToString() + "|"; msg += x2.ToString() + "|"; msg += y2.ToString(); client.Send(msg); //End networking action selectedSoldierCard.GetComponent <attack>().doAttack(playerBlue, cards, x1, y1, x2, y2); } else if (selectedSoldierCard.GetComponent <OneSoldierManager>().isRed) { selectedSoldierCard.GetComponent <attack>().doAttack(playerRed, cards, x1, y1, x2, y2); } selectedSoldierCard.moving = false; selectedSoldierCard.attacking = false; } } }
public void TryAttack(int x1, int y1, int x2, int y2) { selectedSoldierCard = cards[x1, y1]; selectedSoldierCard.GetComponent <attack>().doAttack(playerRed, cards, x1, y1, x2, y2); selectedSoldierCard.GetComponent <attack>().doAttack(playerBlue, cards, x1, y1, x2, y2); }