private static void Print(OUTPUT_TYPE msgType, string msg, int indentation = 0) { if (indentation != 0) { string tabs = new String('\t', indentation); Console.WriteLine("{0}[{1}] {2}", tabs, (char)msgType, msg); } else { Console.WriteLine("[{0}] {1}", (char)msgType, msg); } }
private void AssertExpected(INPUT_TYPE input, OUTPUT_TYPE expected) { OUTPUT_TYPE actual = GetInstance().RenameThis(input); Assert.AreEqual(expected, actual, $"{Environment.NewLine}Expected:\t{expected.ToString()}{Environment.NewLine}Found:\t{actual.ToString()}"); }
private int GetPointsExcludingSelectedTypeAndLockedTypes(OUTPUT_TYPE type) { int points = 0; if (type != OUTPUT_TYPE.ENVIRONMENT && !EnvironmentLocked) { points += EnvironmentAmount; } if (type != OUTPUT_TYPE.RESEARCH && !ResearchLocked) { points += ResearchAmount; } if (type != OUTPUT_TYPE.CONSTRUCTION && !ConstructionLocked) { points += ConstructionAmount; } if (type != OUTPUT_TYPE.DEFENSE && !DefenseLocked) { points += DefenseAmount; } if (type != OUTPUT_TYPE.INFRASTRUCTURE && !InfrastructureLocked) { points += InfrastructureAmount; } return points; }
public void SetOutputAmount(OUTPUT_TYPE outputType, int amount, bool forceChange) { if (forceChange) { //First, try and change it without forcing it SetOutputAmount(outputType, amount, false); switch (outputType) { case OUTPUT_TYPE.CONSTRUCTION: { if (ConstructionAmount == amount) { //Success return; } } break; case OUTPUT_TYPE.DEFENSE: { if (DefenseAmount == amount) { //Success return; } } break; case OUTPUT_TYPE.ENVIRONMENT: { if (EnvironmentAmount == amount) { //Success return; } } break; case OUTPUT_TYPE.INFRASTRUCTURE: { if (InfrastructureAmount == amount) { //Success return; } } break; case OUTPUT_TYPE.RESEARCH: { if (ResearchAmount == amount) { //Success return; } } break; } } int remainingPercentile = 100; if (InfrastructureLocked && !forceChange) { remainingPercentile -= InfrastructureAmount; } if (EnvironmentLocked && !forceChange) { remainingPercentile -= EnvironmentAmount; } if (DefenseLocked && !forceChange) { remainingPercentile -= DefenseAmount; } if (ConstructionLocked && !forceChange) { remainingPercentile -= ConstructionAmount; } if (ResearchLocked && !forceChange) { remainingPercentile -= ResearchAmount; } //if the player set the slider to or beyond the allowed percentile, all other sliders are set to 0 if (amount >= remainingPercentile) { //set all sliders to 0, and change amount to remainingPercentile if (!InfrastructureLocked) { InfrastructureAmount = 0; } if (!EnvironmentLocked) { EnvironmentAmount = 0; } if (!DefenseLocked) { DefenseAmount = 0; } if (!ResearchLocked) { ResearchAmount = 0; } if (!ConstructionLocked) { ConstructionAmount = 0; } amount = remainingPercentile; } //Now scale int totalPointsExcludingSelectedType = GetPointsExcludingSelectedTypeAndLockedTypes(outputType); switch (outputType) { case OUTPUT_TYPE.INFRASTRUCTURE: { InfrastructureAmount = amount; remainingPercentile -= InfrastructureAmount; } break; case OUTPUT_TYPE.ENVIRONMENT: { EnvironmentAmount = amount; remainingPercentile -= EnvironmentAmount; } break; case OUTPUT_TYPE.DEFENSE: { DefenseAmount = amount; remainingPercentile -= DefenseAmount; } break; case OUTPUT_TYPE.CONSTRUCTION: { ConstructionAmount = amount; remainingPercentile -= ConstructionAmount; } break; case OUTPUT_TYPE.RESEARCH: { ResearchAmount = amount; remainingPercentile -= ResearchAmount; } break; } if (remainingPercentile < totalPointsExcludingSelectedType) { int amountToDeduct = totalPointsExcludingSelectedType - remainingPercentile; int prevValue; if ((!ResearchLocked || forceChange) && outputType != OUTPUT_TYPE.RESEARCH) { prevValue = ResearchAmount; ResearchAmount -= (ResearchAmount >= amountToDeduct ? amountToDeduct : ResearchAmount); amountToDeduct -= (prevValue - ResearchAmount); } if (amountToDeduct > 0) { if ((!ConstructionLocked || forceChange) && outputType != OUTPUT_TYPE.CONSTRUCTION) { prevValue = ConstructionAmount; ConstructionAmount -= (ConstructionAmount >= amountToDeduct ? amountToDeduct : ConstructionAmount); amountToDeduct -= (prevValue - ConstructionAmount); } } if (amountToDeduct > 0) { if ((!DefenseLocked || forceChange) && outputType != OUTPUT_TYPE.DEFENSE) { prevValue = DefenseAmount; DefenseAmount -= (DefenseAmount >= amountToDeduct ? amountToDeduct : DefenseAmount); amountToDeduct -= (prevValue - DefenseAmount); } } if (amountToDeduct > 0) { if ((!InfrastructureLocked || forceChange) && outputType != OUTPUT_TYPE.INFRASTRUCTURE) { prevValue = InfrastructureAmount; InfrastructureAmount -= (InfrastructureAmount >= amountToDeduct ? amountToDeduct : InfrastructureAmount); amountToDeduct -= (prevValue - InfrastructureAmount); } } if (amountToDeduct > 0) { if ((!EnvironmentLocked || forceChange) && outputType != OUTPUT_TYPE.ENVIRONMENT) { prevValue = EnvironmentAmount; EnvironmentAmount -= (EnvironmentAmount >= amountToDeduct ? amountToDeduct : EnvironmentAmount); amountToDeduct -= (prevValue - EnvironmentAmount); } } } if (remainingPercentile > totalPointsExcludingSelectedType) //excess points needed to allocate { int amountToAdd = remainingPercentile - totalPointsExcludingSelectedType; if (!InfrastructureLocked && outputType != OUTPUT_TYPE.INFRASTRUCTURE) { InfrastructureAmount += amountToAdd; amountToAdd = 0; } if (amountToAdd > 0) { if (!EnvironmentLocked && outputType != OUTPUT_TYPE.ENVIRONMENT) { EnvironmentAmount += amountToAdd; amountToAdd = 0; } } if (amountToAdd > 0) { if (!DefenseLocked && outputType != OUTPUT_TYPE.DEFENSE) { DefenseAmount += amountToAdd; amountToAdd = 0; } } if (amountToAdd > 0) { if (!ResearchLocked && outputType != OUTPUT_TYPE.RESEARCH) { ResearchAmount += amountToAdd; amountToAdd = 0; } } if (amountToAdd > 0) { if (!ConstructionLocked && outputType != OUTPUT_TYPE.CONSTRUCTION) { ConstructionAmount += amountToAdd; amountToAdd = 0; } } if (amountToAdd > 0) //All other sliders has been locked, allocate the remaining points back to this output { switch (outputType) { case OUTPUT_TYPE.INFRASTRUCTURE: { InfrastructureAmount += amountToAdd; break; } case OUTPUT_TYPE.RESEARCH: { ResearchAmount += amountToAdd; break; } case OUTPUT_TYPE.ENVIRONMENT: { EnvironmentAmount += amountToAdd; break; } case OUTPUT_TYPE.DEFENSE: { DefenseAmount += amountToAdd; break; } case OUTPUT_TYPE.CONSTRUCTION: { ConstructionAmount += amountToAdd; break; } } } } UpdateOutputs(); }