bool OccupationCheck(int x, int y, bool straight = false) { if ((x == 0 || x == 32) && y == 3) { return(false); } else if (x < 0 || x > 32 || y < 0 || (x % 2 == 0 && y > 6) || (x % 2 == 1 && y > 5)) { return(false); } int len = system.selectedInfo.len; int k = (system.selectedInfo.team == 0) ? -2 : 2; foreach (GameObject s in system.ships_TOP) { shipInfo info = s.GetComponent <shipInfo>(); for (int i = 0; i < info.len; i++) { if (x == info.xPos - i * 2 && y == info.yPos) { return(false); } } if (!straight) { for (int i = 0; i < len; i++) { if (x + i * k == info.xPos && y == info.yPos) { return(false); } } } } foreach (GameObject s in system.ships_BOTTOM) { shipInfo info = s.GetComponent <shipInfo>(); for (int i = 0; i < info.len; i++) { if (x == info.xPos + i * 2 && y == info.yPos) { return(false); } } if (!straight) { for (int i = 0; i < len; i++) { if (x + i * k == info.xPos && y == info.yPos) { return(false); } } } } return(true); }
public void UpdateMenu(GameObject s) { QuitWindowClose(); selectedInfo = s.GetComponent <shipInfo>(); selectedInfo.selected = true; switch (selectedInfo.type) { case 0: selectedType.text = "CORVETTE"; SFXList[0].Play(); break; case 1: selectedType.text = "FRIGATE"; SFXList[0].Play(); break; case 2: selectedType.text = "DESTROYER"; SFXList[1].Play(); break; case 3: selectedType.text = "CRUISER"; SFXList[1].Play(); break; default: selectedType.text = "BATTLESHIP"; SFXList[1].Play(); break; } selectedAP.text = selectedInfo.AP.ToString(); attackable.Clear(); movable.Clear(); mode_attack = false; mode_move = false; calc.attackRangeCalculation(); calc.moveRangeCalculation(); if (attackable.Count == 0 || selectedInfo.AP == 0 || selectedInfo.attackCount > 0) { attack_available.SetActive(false); attack_unable.SetActive(true); } else { attack_available.SetActive(true); attack_unable.SetActive(false); if (selectedInfo.type == 2 || selectedInfo.type == 4) { foreach (GameObject ship in attackable) { ship.GetComponent <shipInfo>().attackable = true; } mode_attack = true; } } if (movable.Count == 0 || selectedInfo.AP == 0) { move_available.SetActive(false); move_unable.SetActive(true); } else { move_available.SetActive(true); move_unable.SetActive(false); } attack_pending.SetActive(false); move_pending.SetActive(false); }
public void transferInfo(shipInfo s) { type = s.type; team = s.team; if (team == 0) { xPos = s.xPos; if (s.xPos % 2 == 0) { yPos = 6 - s.yPos; } else { yPos = 5 - s.yPos; } } else { xPos = 32 - s.xPos; yPos = s.yPos; } Relocate(); }
public void attackRangeCalculation() { List <GameObject> enemies = (system.selectedInfo.team == 0) ? system.ships_BOTTOM : system.ships_TOP; int k = (system.selectedInfo.team == 0) ? 2 : -2; bool even = system.selectedInfo.xPos % 2 == 0; switch (system.selectedInfo.type) { case 0: foreach (GameObject e in enemies) { bool withinRange = false; shipInfo enemyInfo = e.GetComponent <shipInfo>(); int y = enemyInfo.yPos; int y_gap = y - system.selectedInfo.yPos; for (int i = 0; i < enemyInfo.len; i++) { int x = enemyInfo.xPos + k * i; int x_gap = x - system.selectedInfo.xPos; switch (y_gap) { case 0: if (Mathf.Abs(x_gap) <= 6) { withinRange = true; } break; case -1: if (even && Mathf.Abs(x_gap) <= 5) { withinRange = true; } else if (!even && Mathf.Abs(x_gap) <= 4) { withinRange = true; } break; case 1: if (even && Mathf.Abs(x_gap) <= 4) { withinRange = true; } else if (!even && Mathf.Abs(x_gap) <= 5) { withinRange = true; } break; default: if (even && y_gap != -2) { continue; } else if (!even && y_gap != 2) { continue; } else if (Mathf.Abs(x_gap) == 1 || Mathf.Abs(x_gap) == 3) { withinRange = true; } break; } if (withinRange) { system.attackable.Add(e); break; } } } break; case 1: foreach (GameObject e in enemies) { shipInfo enemyInfo = e.GetComponent <shipInfo>(); int x_gap = enemyInfo.xPos - system.selectedInfo.xPos; int y_gap = Mathf.Abs(enemyInfo.yPos - system.selectedInfo.yPos); int k_1 = (system.selectedInfo.team == 0) ? 1 : -1; if (y_gap != 0) { continue; } else if (x_gap * k_1 == 2 || x_gap * k_1 == 4 || x_gap * k_1 == 6) { system.attackable.Add(e); } } break; case 2: List <GameObject> temp_2; for (int i = 0; i < 2; i++) { int k_2 = (i == 0) ? -2 : 2; temp_2 = (i == 0) ? system.ships_TOP : system.ships_BOTTOM; foreach (GameObject e in temp_2) { if (GameObject.ReferenceEquals(system.selectedInfo.gameObject, e)) { continue; } bool withinRange = false; shipInfo targetInfo = e.GetComponent <shipInfo>(); int y = targetInfo.yPos; int y_gap = y - system.selectedInfo.yPos; for (int j = 0; j < targetInfo.len; j++) { int x = targetInfo.xPos + k_2 * j; int x_gap = (x - system.selectedInfo.xPos) * (-k) / 2; switch (y_gap) { case 0: if (-4 <= x_gap && x_gap <= 6) { withinRange = true; } break; case -1: if (even && -3 <= x_gap && x_gap <= 5) { withinRange = true; } else if (!even && (x_gap == 0 || Mathf.Abs(x_gap) == 2 || x_gap == 4)) { withinRange = true; } break; default: if (even && y_gap == 1 && (x_gap == 0 || Mathf.Abs(x_gap) == 2 || x_gap == 4)) { withinRange = true; } else if (!even && y_gap == 1 && -3 <= x_gap && x_gap <= 5) { withinRange = true; } break; } if (withinRange) { system.attackable.Add(e); break; } } } } break; case 3: foreach (GameObject e in enemies) { shipInfo enemyInfo = e.GetComponent <shipInfo>(); int y = enemyInfo.yPos; int y_gap = y - system.selectedInfo.yPos; for (int i = 0; i < enemyInfo.len; i++) { int x = enemyInfo.xPos + k * i; int x_gap = Mathf.Abs(x - system.selectedInfo.xPos); if (even && (y_gap == x_gap / 2 || y_gap == -((x_gap - 1) / 2) - 1) && x_gap <= 7) { system.attackable.Add(e); break; } else if (!even && (y_gap == -(x_gap / 2) || y_gap == (x_gap + 1) / 2) && x_gap <= 7) { system.attackable.Add(e); break; } } } break; default: List <GameObject> temp_4; for (int i = 0; i < 2; i++) { int k_4 = (i == 0) ? -2 : 2; temp_4 = (i == 0) ? system.ships_TOP : system.ships_BOTTOM; foreach (GameObject e in temp_4) { if (GameObject.ReferenceEquals(system.selectedInfo.gameObject, e)) { continue; } bool withinRange = false; shipInfo targetInfo = e.GetComponent <shipInfo>(); int y = targetInfo.yPos; int y_gap = y - system.selectedInfo.yPos; for (int j = 0; j < targetInfo.len; j++) { int x = targetInfo.xPos + k_4 * j; int x_gap = (x - system.selectedInfo.xPos) * (-k) / 2; switch (y_gap) { case 0: if (-1 <= x_gap && x_gap <= 4) { withinRange = true; } break; case -1: if (even && -2 <= x_gap && x_gap <= 3) { withinRange = true; } else if (!even && -3 <= x_gap && x_gap <= 2) { withinRange = true; } break; case 1: if (even && -3 <= x_gap && x_gap <= 2) { withinRange = true; } else if (!even && -2 <= x_gap && x_gap <= 3) { withinRange = true; } break; default: if (even && y_gap != -2) { continue; } else if (!even && y_gap != 2) { continue; } else if (system.selectedInfo.team == 0 && (x_gap == -1 || x_gap == 1 || x_gap == 3)) { withinRange = true; } else if (system.selectedInfo.team == 1 && (x_gap == -3 || x_gap == -1 || x_gap == 1)) { withinRange = true; } break; } if (withinRange) { system.attackable.Add(e); break; } } } } break; } }