/* * OnMouseDown(): called when the sector is clicked. * It handles the logic behind selecting which action to be taken (Attack, Movement or sector Highlighting) * depending on if another sector is selected, whether the turn is on an Attacking or Movement phase, * and the ownership of the current sector compared to the original. */ void OnMouseDown() { if (Input.GetMouseButtonDown(0)) { MapClass map = GameObject.Find("Map").GetComponent <MapClass> (); GameObject originalSector = map.getSelectedSector(); if (originalSector != null) { if (this.adjacent_sectors.Contains(originalSector)) { Sector originalSectorClass = originalSector.GetComponent <Sector> (); if (this.owner == originalSectorClass.Owner && GameClass.GameState == GameClass.MOVEMENT) { //Move Gang members from originalSector to currentSector (this). print("Move gang members from " + originalSector.name + " to " + name); map.deselectAll(); } else if (this.owner != originalSectorClass.Owner && GameClass.GameState == GameClass.ATTACK) { //Attack from originalSector to currentSector (this). print("Attack " + name + " from " + originalSector.name); map.Combat(originalSector, this.gameObject); map.deselectAll(); } } } else { if (this.owner == GameClass.CurrentPlayer) { int sectorsHighlighted = 0; foreach (GameObject adjSect in adjacent_sectors) { if (GameClass.GameState == GameClass.MOVEMENT) { if (adjSect.GetComponent <Sector> ().Owner == this.owner) { adjSect.GetComponent <SpriteRenderer> ().color = new Color(1, 1, 1, 1); sectorsHighlighted++; } } else { if (adjSect.GetComponent <Sector> ().Owner != this.owner) { adjSect.GetComponent <SpriteRenderer> ().color = new Color(1, 0, 0, 1); sectorsHighlighted++; } } } if (sectorsHighlighted > 0) { SpriteRenderer sprite = GetComponent <SpriteRenderer> (); sprite.color = new Color(0, 0, 0, 1); this.selected = true; } else { // No valid moves from clicked sector //print("No valid moves from clicked sector"); } } } } }