public void handleInput() { if (okayButton != null) { inputHandler.update(Keyboard.GetState()); okayButton.handleInput(inputHandler); return; } if (actionMenu != null) { inputHandler.update(Keyboard.GetState()); actionMenu.handleInput(inputHandler); if (selectingForAttack != 0 || selectingForRecruitment || selectingForTroopTransfer != 0) { return; } } if (beginningMenu != null) { inputHandler.update(Keyboard.GetState()); beginningMenu.handleInput(inputHandler); return; } MouseState currentMouseState = Mouse.GetState(); inputHandler.updateMouse(currentMouseState); if (inputHandler.allowSingleClick()) { List<County> selectedCounties = new List<County>(); foreach (County c in counties) { if (c.mapRectangle.Contains(currentMouseState.Position)) { selectedCounties.Add(c); } } if (selectedCounties.Count > 0) { County closestCenter = selectedCounties[0]; for (int x = 1; x < selectedCounties.Count; x++) { if (Sprite.getRectangleDistance(selectedCounties[x].mapRectangle.Center, currentMouseState.Position) < Sprite.getRectangleDistance(closestCenter.mapRectangle.Center, currentMouseState.Position)) { closestCenter = selectedCounties[x]; } } individualCounty = closestCenter; icTextWindow = new TextWindow(new string[] { individualCounty.name.ToUpper() + " COUNTY\\n" + "REVENUE: " + individualCounty.revenue + "\\n" + "STATIONED TROOPS: " + individualCounty.troops + "\\n" + "OWNER: " + individualCounty.getOwner() }, Content, new Vector2(350,630), new Vector2(400, 115)); if (beginning) { beginningTextWindow.advanceLine(); beginningTextWindow = new TextWindow( new string[] { "SELECT " + individualCounty.name.ToUpper() }, Content, new Vector2(25, 25), new Vector2(300, 25)); beginningMenu = new Menu( new Vector2(100, 100), new string[] { "YES", "NO" }, new Menu.menuAction[] { selectStartingCounty, cancelStartingCounty }, 2, 1, "test-semifont.png", Content); } else if (selectingForAttack == 1) { targetCounty = individualCounty; selectingForAttack = 2; gpWindow = new TextWindow(new string[] { "SELECT INVADING COUNTY" }, Content, new Vector2(25, 25), new Vector2(360, 25)); } else if (selectingForAttack == 2) { sourceCounty = individualCounty; bool adjacent = false; for (int x = 0; x < sourceCounty.edges.Length; x++) { if (targetCounty == counties[sourceCounty.edges[x]]) { adjacent = true; break; } } int playerFunds = funds; if (playerNumber == 2) playerFunds = unionFunds; if (sourceCounty.occupied != playerNumber) { gpWindow = new TextWindow(new String[] { "SOURCE COUNTY IS NOT YOURS" }, Content, new Vector2(25, 25), new Vector2(500, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelAttack }, 1, 1, "test-semifont.png", Content); return; } else if (targetCounty.occupied == playerNumber) { gpWindow = new TextWindow(new String[] { "TARGET COUNTY IS ALREADY YOURS" }, Content, new Vector2(25, 25), new Vector2(500, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelAttack }, 1, 1, "test-semifont.png", Content); return; } else if (!adjacent) { gpWindow = new TextWindow(new String[] { "TARGET COUNTY TOO FAR AWAY" }, Content, new Vector2(25, 25), new Vector2(500, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelAttack }, 1, 1, "test-semifont.png", Content); return; } else if (playerFunds - (sourceCounty.troops / 2) < 0) { gpWindow = new TextWindow(new String[] { "NOT ENOUGH FUNDS REQUIRED: " + (sourceCounty.troops / 2) }, Content, new Vector2(25, 25), new Vector2(650, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelAttack }, 1, 1, "test-semifont.png", Content); return; } selectingForAttack = 3; int cost = sourceCounty.troops / 2; gpWindow = new TextWindow(new string[] { "ATTACK " + targetCounty.name.ToUpper() + " FROM " + sourceCounty.name.ToUpper() + "\\nCOST: " + cost }, Content, new Vector2(25, 25), new Vector2(650, 50)); actionMenu = new Menu( new Vector2(100, 100), new string[] { "YES", "NO" }, new Menu.menuAction[] { attackCounty, cancelAttack }, 2, 1, "test-semifont.png", Content); } else if (selectingForTroopTransfer == 1) { targetCounty = individualCounty; selectingForTroopTransfer = 2; gpWindow = new TextWindow(new string[] { "SELECT DONOR" }, Content, new Vector2(25, 25), new Vector2(360, 25)); } else if (selectingForTroopTransfer == 2) { sourceCounty = individualCounty; int playerFunds = funds; if (playerNumber == 2) playerFunds = unionFunds; bool connected = false; List<County> visited = new List<County>(); Stack<County> DFSstack = new Stack<County>(); DFSstack.Push(sourceCounty); while (DFSstack.Count != 0) { County chk = DFSstack.Pop(); if (chk == targetCounty && chk.occupied == playerNumber) { connected = true; break; } else if (visited.Contains(chk)) { continue; } for (int x = 0; x < chk.edges.Length; x++) { if (counties[chk.edges[x]].occupied == playerNumber) DFSstack.Push(counties[chk.edges[x]]); } visited.Add(chk); } if (sourceCounty.occupied != playerNumber) { gpWindow = new TextWindow(new String[] { "SOURCE COUNTY NOT YOURS" }, Content, new Vector2(25, 25), new Vector2(500, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelTroopMove }, 1, 1, "test-semifont.png", Content); return; } else if (targetCounty.occupied != playerNumber) { gpWindow = new TextWindow(new String[] { "RECIPIENT COUNTY NOT YOURS" }, Content, new Vector2(25, 25), new Vector2(500, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelTroopMove }, 1, 1, "test-semifont.png", Content); return; } else if (targetCounty == sourceCounty) { gpWindow = new TextWindow(new String[] { "THAT IS POINTLESS" }, Content, new Vector2(25, 25), new Vector2(500, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelTroopMove }, 1, 1, "test-semifont.png", Content); return; } else if (!connected) { gpWindow = new TextWindow(new String[] { "NO ROUTE FROM SOURCE TO RECIPIENT" }, Content, new Vector2(25, 25), new Vector2(500, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelTroopMove }, 1, 1, "test-semifont.png", Content); return; } else if (playerFunds - 90 < 0) { gpWindow = new TextWindow(new String[] { "NOT ENOUGH FUNDS REQUIRED: 90" }, Content, new Vector2(25, 25), new Vector2(650, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelTroopMove }, 1, 1, "test-semifont.png", Content); return; } selectingForTroopTransfer = 3; gpWindow = new TextWindow(new string[] { "MOVE " + (sourceCounty.troops/3) + " FROM " + sourceCounty.name.ToUpper() + " TO " + targetCounty.name.ToUpper() + "\\n" + "COST: 90"}, Content, new Vector2(25, 25), new Vector2(650, 50)); actionMenu = new Menu( new Vector2(100, 100), new string[] { "YES", "NO" }, new Menu.menuAction[] { moveTroops, cancelTroopMove }, 2, 1, "test-semifont.png", Content); } else if (selectingForRecruitment) { sourceCounty = individualCounty; int playerFunds = funds; if (playerNumber == 2) playerFunds = unionFunds; if (sourceCounty.occupied != playerNumber) { gpWindow = new TextWindow(new String[] { "COUNTY NOT YOURS" }, Content, new Vector2(25, 25), new Vector2(500, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelRecruit }, 1, 1, "test-semifont.png", Content); return; } else if (playerFunds - 30 < 0) { gpWindow = new TextWindow(new String[] { "NOT ENOUGH FUNDS REQUIRED: 30" }, Content, new Vector2(25, 25), new Vector2(650, 25)); okayButton = new Menu(new Vector2(700, 25), new string[] { "OK" }, new Menu.menuAction[] { cancelRecruit }, 1, 1, "test-semifont.png", Content); return; } int cost = 30; gpWindow = new TextWindow(new string[] { "RECRUIT TROOPS IN " + sourceCounty.name.ToUpper() + "\\nCOST: " + cost }, Content, new Vector2(25, 25), new Vector2(500, 50)); actionMenu = new Menu( new Vector2(100, 100), new string[] { "YES", "NO" }, new Menu.menuAction[] { recruitTroops, cancelRecruit }, 2, 1, "test-semifont.png", Content); } } } }