public void ConvertToPostGrads() { while (attackingUnits >= 15) { attackingUnits -= 15; attackingSector.AddUnits(-15); attackingSector.AddPostgrads(1); } mode = 1; //After sorting out units and owners convpostgrads.SetActive(false); Renderer renderer = attackingSector.GetComponent <SpriteRenderer> (); Color color; color = renderer.material.color; //Update the transparency of the attacking sector to be semi-transparent color.a = 0.5f; renderer.material.color = color; gameInstructions.text = "Pick a sector to attack with..."; //Update instructions to show user next step }
/* The field 'GameObject Sector' has been refactored to 'Section sector' */ void SelectSector(Section sector) { switch (mode) { case 1: //If this is the first sector that has been picked attackingSector = sector; //store the gameobject in attacking sector mode = 2; //update the mode to 2...where users should enter number of units they intend to move/attack with inputFieldObject.SetActive(true); //Enable (and show) the input field goButton.SetActive(true); //submit button backButton.SetActive(true); //and undo button break; case 3: //If this is the second sector that has been picked /* For clarity, the variable 'ValidOp' was renamed to * 'sectorIsAdjacentToAttackingSector' */ bool sectorIsAdjacentToAttackingSector = false; //Check if the second sector clicked is neighbouring the first sector clicked foreach (Section G in sectorsAdjacentToAttackingSector) { if (sector == G) { sectorIsAdjacentToAttackingSector = true; } } if (sectorIsAdjacentToAttackingSector) //If it is { defendingSector = sector; //update defending sector to the second sector clicked if (defendingPlayer != attackingPlayer) //check if it is a friendly sector { if (attackingUnits < (defendingUnits * 0.66)) //check if attacking units are less than 2/3 of the defending (unfriendly) units and if they are { riskyMovePopup.BroadcastMessage("SetAttackingUnits", attackingUnits); //send details to a popup checking this is the move users meant to make riskyMovePopup.BroadcastMessage("SetDefendingUnits", defendingUnits); riskyMovePopup.BroadcastMessage("Open"); //and open the popup } else //If the attacking units are more than 2/3 of the defending units { ResolveConflict(); //call the function to resolve the conflict } } else { ResolveConflict(); //Friendly section to friendly section movement } } else //If the second sector is not a neighbour of the first { attackingSector.Flash(); //make the neighbouring sectors of the first sector flash, to remind the users where they can move units to } break; case 4: sectorIsAdjacentToAttackingSector = false; //Check if the second sector clicked is neighbouring the first sector clicked foreach (Section G in sectorsAdjacentToAttackingSector) { if (sector == G) { sectorIsAdjacentToAttackingSector = true; } } if (sectorIsAdjacentToAttackingSector) //If it is { defendingSector = sector; //update defending sector to the second sector clicked if (defendingPlayer != attackingPlayer) //check if it is a friendly sector { while ((nextPostgrads > 0) & (movingPostgrads > 0)) { attackingSector.AddPostgrads(-1); defendingSector.AddPostgrads(-1); nextPostgrads -= 1; movingPostgrads -= 1; } } else { attackingSector.AddPostgrads(-movingPostgrads); defendingSector.AddPostgrads(+movingPostgrads); } } else //If the second sector is not a neighbour of the first { attackingSector.Flash(); //make the neighbouring sectors of the first sector flash, to remind the users where they can move units to } mode = 1; //After sorting out units and owners convpostgrads.SetActive(false); Renderer renderer = attackingSector.GetComponent <SpriteRenderer> (); Color color; color = renderer.material.color; //Update the transparency of the attacking sector to be semi-transparent color.a = 0.5f; renderer.material.color = color; gameInstructions.text = "Pick a sector to attack with..."; //Update instructions to show user next step break; default: break; } }