public static void HandleInput(InputHelper helper, KeyManager keys) { CurrentState?.HandleInput(helper, keys); EconomyGrid economyGrid = ((EconomyState)GetState("economy")).EconomyGrid; SaveGame sg = new SaveGame(economyGrid); int f1 = (int)Keys.F1; int f12 = (int)Keys.F12; for (int i = f1; i <= f12; ++i) { if (helper.KeyPressed((Keys)i) && (helper.IsKeyDown(Keys.LeftShift) || helper.IsKeyDown(Keys.RightShift))) { FileManager.SaveGame("savegametest-" + i, new byte[] { 0x42, 0x10, 0x28, 0x64, 0xFF, 0xEB }, sg); } else if (helper.KeyPressed((Keys)i)) { FileManager.LoadGame("savegametest-" + i, new byte[] { 0x42, 0x10, 0x28, 0x64, 0xFF, 0xEB }, sg); EconomyState ecoState = (EconomyState)GetState("economy"); ecoState.EconomyGrid = sg.EcoGrid; ecoState.Players = sg.EcoGrid.players; } } }
private void AddBuilderButton(EconomyGrid grid, GuiList listBuilderActions, string buildingName, Type buildingType) { // Create the label for the element StringBuilder label = new StringBuilder(); label.Append(Translations.GetTranslation(buildingName)).Append(" ("); label.Append(BuildingRegistry.GetCost(buildingName)).Append("G): "); // Create the element using the label, and add a BuildBuilding clickhandler listBuilderActions.addElement(ElementBuildButton.CreateBuildButton(listBuilderActions.Bounds.Location, label.ToString(), BuildBuilding(grid, buildingName, buildingType))); // Also add this buildingID-Type pair to the BuildingRegistry BuildingRegistry.buildingTypeById[buildingName] = buildingType; }
public override void Reset() { // Reset the players foreach (Player p in players) { p.Reset(); } // Initialize the field EconomyGrid = new EconomyGrid(GRID_WIDTH, GRID_HEIGHT, players); ecoGrid.InitField(); // Player 1 starts currentPlayer = 0; // Turn number starts at 1, so 0 and double TurnUpdate turnNum = 0; TurnUpdate(null); TurnUpdate(null); }
public void InitBuildingList(EconomyGrid grid) { // Create the list of building possibilities listBuilderActions = GuiList.createNewList(BuildingInfoPosition, 5, new List <GuiElement>(), 300); // Add all the corresponding elements to the building actions list AddBuilderButton(grid, listBuilderActions, "building.town", typeof(Town)); AddBuilderButton(grid, listBuilderActions, "building.mine", typeof(Mine)); AddBuilderButton(grid, listBuilderActions, "building.trainingGrounds", typeof(TrainingGrounds)); AddBuilderButton(grid, listBuilderActions, "building.academy", typeof(Academy)); // Also add the capital to the building registry, for saving and loading from files BuildingRegistry.buildingTypeById["building.capital"] = typeof(Capital); // Make sure the list knows how big it is and add it to the screen listBuilderActions.calculateElementPositions(); addElement(listBuilderActions); // Create the building actions list and add it to the screen listBuildingActions = GuiList.createNewList(BuildingInfoPosition, 5, new List <GuiElement>(), 300); addElement(listBuildingActions); }
private GuiButton.OnClickHandler BuildBuilding(EconomyGrid grid, string buildingName, Type buildingType) { // Return an on click handler return(() => { // That gets the tile the current builder is on Tile t = grid[currentBuilder.PositionInGrid] as Tile; // Then checks if we can build here, and if the player can afford the building if (!t.BuiltOn && currentBuilder.Owner.CanAfford(BuildingRegistry.GetCost(buildingName))) { Tile tile = currentBuilder.Parent as Tile; if (!tile.Terrain.IsMountain && buildingType.Equals(typeof(Mine))) { return; } else if (tile.Terrain != Terrain.Plains && buildingType.Equals(typeof(Town))) { return; } else if ((tile.Terrain == Terrain.Lake || tile.Terrain == Terrain.Mountain || tile.Terrain == Terrain.DesertMountain || tile.Terrain == Terrain.TundraMountain) && !buildingType.Equals(typeof(Mine))) { return; } // And remove the money if possible... currentBuilder.Owner.Buy(BuildingRegistry.GetCost(buildingName)); // ... and tell the grid to build a building here, based on the passed type. // Basically the same as new Building(currentBuilder.PositionInGrid, currentBuilder.Owner), except we don't need to know WHICH building grid.Build(currentBuilder, (Building)Activator.CreateInstance(buildingType, new object[] { currentBuilder.PositionInGrid, currentBuilder.Owner })); currentBuilder.Owner.CalculatePopulation(); currentBuilder.Owner.CalculateMoneyPerTurn(); } }); }
public void LoadFromFile(BinaryReader reader) { economyGrid = EconomyGrid.LoadFromFile(reader); }
public SaveGame(EconomyGrid economyGrid) { this.economyGrid = economyGrid; }