public ImportCommand(Guid accountId, string sourceName, SourceKind sourceKind) : this(accountId) { SourceName = sourceName; SourceKind = sourceKind; CreationDate = DateTime.UtcNow; }
public HexaModel(int value, HexaKind kind, SourceKind sourceKind, SourceBuildingKind buildingKind,SourceAll sourceBuildingCost) { if (kind == HexaKind.Water) { this.hexaID = -1; } else this.hexaID = ++counter; this.sourceBuildingCost = sourceBuildingCost; this.kind = kind; this.sourceKind = sourceKind; this.buildingKind = buildingKind; this.startSource = value; this.towns = new TownModel[(int) TownPos.Count]; this.roads = new RoadModel[(int)RoadPos.Count]; this.townOwner = new Boolean[(int)TownPos.Count]; this.roadOwner = new Boolean[(int)RoadPos.Count]; sourceDisaster = false; sourceMiracle = false; hexaDestroy = false; captureIs = false; capturePlayer = null; }
public void ForNonStaticMemberReferencedInInnerClass_Reports( [ValueSource(nameof(SourceKinds))] SourceKind sourceKind) { string source = @" using NUnit.Framework; [TestFixture] public class TestClass { " + CreateTestMethodString(sourceKind, "typeof(TestClass.InnerSource), \"Cases\"") + @" class InnerSource { object[] Cases = { new object[] {1}, new object[] {2} } } } "; VerifyCSharpDiagnostic(source, new DiagnosticResult { Id = "NU2M04", Locations = new[] { GetExpectedDiagnosticLocation(sourceKind) }, Message = GetExpectedAttributeName(sourceKind) + " attribute refers to 'TestClass.InnerSource.Cases' which is not static.", Severity = DiagnosticSeverity.Error }); }
public void StartsWithUsesCollectionsCountToAvoidUnnecessaryIteration(SourceKind sourceKind) { var first = new[] { 1, 2 }.ToSourceKind(sourceKind); var second = new[] { 1, 2, 3 }.ToSourceKind(sourceKind); Assert.False(first.StartsWith(second)); }
public MarketError CanBuyLicence(SourceKind source) { LicenceKind licenceKind = owner.GetMarketLicence(source); UpgradeKind upgradeKind; switch (licenceKind) { case LicenceKind.NoLicence: upgradeKind = UpgradeKind.FirstUpgrade; break; case LicenceKind.FirstLicence: upgradeKind = UpgradeKind.SecondUpgrade; break; default: upgradeKind = UpgradeKind.NoUpgrade; break; } if (upgradeKind == UpgradeKind.SecondUpgrade && Settings.banSecondLicence) return MarketError.BanSecondLicence; BuyingUpgradeError error = GameState.map.GetMapController().CanBuyUpgradeInSpecialBuilding(townID, hexaID, upgradeKind, (int)source); switch (error) { case BuyingUpgradeError.YouAlreadyHaveSecondUpgrade: GameState.map.GetMapController().SetLastError(Strings.ERROR_HAVE_SECOND_LICENCE); return MarketError.HaveSecondLicence; case BuyingUpgradeError.NoSources: GameState.map.GetMapController().SetLastError(Strings.ERROR_NO_SOURCES); return MarketError.NoSources; case BuyingUpgradeError.MaxUpgrades: GameState.map.GetMapController().SetLastError(Strings.ERROR_MAX_LICENCES); return MarketError.MaxLicences; case BuyingUpgradeError.OK: return MarketError.OK; } return MarketError.OK; }
public override double GetDesirability() { if (!HasFreeSlot()) return 0.0f; IPlayer me = map.GetPlayerMe(); ISourceAll source = me.GetCollectSourcesNormal(); int max = 0; bestKind = SourceKind.Count; for (int loop1 = 0; loop1 < 5; loop1++) { if (source[loop1] > max && me.GetMarketLicence((SourceKind)loop1) != LicenceKind.SecondLicence) { if (me.GetMarketLicence((SourceKind)loop1) == LicenceKind.FirstLicence && map.CanBuyLicence((SourceKind)loop1) == MarketError.BanSecondLicence) continue; max = source[loop1]; bestKind = (SourceKind)loop1; } } double bestSourceDesirability = ((max - 40) / 60.0) / 2.0; if (bestSourceDesirability < 0.0) return 0.0; if (bestSourceDesirability > 1.0) bestSourceDesirability = 1.0; return bestSourceDesirability; }
public ButtonComponent(Game game, int x, int y, Rectangle clickablePosition, SpriteFont font, int width, int height, String texture, SourceKind type) : base(game, x, y, font, width, height, texture) { this.sourceKind = type; this.init(clickablePosition, x, y, width, height); spriteBatch = new SpriteBatch(myGame.GraphicsDevice); colorHover = Settings.colorHoverItem; }
public void AggregateRight(SourceKind sourceKind) { var enumerable = Enumerable.Range(1, 5).Select(x => x.ToString()).ToSourceKind(sourceKind); var result = enumerable.AggregateRight((a, b) => string.Format("({0}+{1})", a, b)); Assert.That(result, Is.EqualTo("(1+(2+(3+(4+5))))")); }
public void FallbackIfEmptyPreservesFallbackCollectionIfPossible(SourceKind sourceKind) { var source = new int[0].ToSourceKind(sourceKind); var fallback = new[] { 1 }; Assert.AreSame(source.FallbackIfEmpty(fallback), fallback); Assert.AreSame(source.FallbackIfEmpty(fallback.AsEnumerable()), fallback); }
public void TrySingleWithSingleton(SourceKind kind) { var source = new int?[] { 10 }.ToSourceKind(kind); var(cardinality, value) = source.TrySingle("zero", "one", "many"); Assert.That(cardinality, Is.EqualTo("one")); Assert.That(value, Is.EqualTo(10)); }
public void TrySingleWithEmptySource(SourceKind kind) { var source = new int?[0].ToSourceKind(kind); var(cardinality, value) = source.TrySingle("zero", "one", "many"); Assert.That(cardinality, Is.EqualTo("zero")); Assert.That(value, Is.Null); }
public void BatchCollectionSmallerThanSize(SourceKind kind, int oversize) { var xs = new[] { 1, 2, 3, 4, 5 }; var result = xs.ToSourceKind(kind).Batch(xs.Length + oversize); using var reader = result.Read(); reader.Read().AssertSequenceEqual(1, 2, 3, 4, 5); reader.ReadEnd(); }
private static Configuration CreateDefaultCsvConfiguration(SourceKind sourceKind) { var configuration = new Configuration(); switch (sourceKind) { case SourceKind.FortisCsvArchive: configuration.RegisterClassMap <FortisOperationArchiveCsvMap>(); configuration.Encoding = Encoding.UTF8; configuration.CultureInfo = FileStructureMetadata.GetCultureInfo("fr-BE", ","); configuration.Delimiter = ";"; configuration.QuoteAllFields = true; configuration.TrimOptions = TrimOptions.InsideQuotes; configuration.MissingFieldFound = LogMissingFieldFound; configuration.HeaderValidated = LogHeaderValidatationFailed; break; case SourceKind.FortisCsvExport: configuration.RegisterClassMap <FortisOperationExportCsvMap>(); var ansiEncoding = Encoding.GetEncoding(1252); configuration.Encoding = ansiEncoding; configuration.CultureInfo = FileStructureMetadata.GetCultureInfo("fr-BE", "."); configuration.Delimiter = ";"; configuration.QuoteAllFields = false; configuration.TrimOptions = TrimOptions.Trim; configuration.MissingFieldFound = LogMissingFieldFound; configuration.HeaderValidated = LogHeaderValidatationFailed; break; case SourceKind.SodexoCsvExport: configuration.RegisterClassMap <SodexoOperationCsvMap>(); configuration.Encoding = Encoding.UTF8; configuration.CultureInfo = FileStructureMetadata.GetCultureInfo("fr-BE", "."); configuration.Delimiter = ";"; configuration.QuoteAllFields = true; configuration.TrimOptions = TrimOptions.InsideQuotes; configuration.MissingFieldFound = LogMissingFieldFound; configuration.HeaderValidated = LogHeaderValidatationFailed; break; case SourceKind.InternalCsvExport: configuration.RegisterClassMap <UnifiedAccountOperationCsvMap>(); configuration.Encoding = Encoding.UTF8; configuration.CultureInfo = FileStructureMetadata.GetCultureInfo("fr-BE", "."); configuration.Delimiter = ";"; configuration.QuoteAllFields = true; configuration.TrimOptions = TrimOptions.InsideQuotes; configuration.MissingFieldFound = LogMissingFieldFound; configuration.HeaderValidated = LogHeaderValidatationFailed; break; default: throw new ArgumentOutOfRangeException(nameof(sourceKind), sourceKind, null); } return(configuration); }
public override string ToString() { if (FileReference == null) { return(SourceKind.ToString()); } return(string.Format("{0} - {1}", SourceKind, FileReference)); }
public void ScanRight(SourceKind sourceKind) { var result = Enumerable.Range(1, 5) .Select(x => x.ToString()) .ToSourceKind(sourceKind) .ScanRight((a, b) => string.Format("({0}+{1})", a, b)); var expectations = new[] { "(1+(2+(3+(4+5))))", "(2+(3+(4+5)))", "(3+(4+5))", "(4+5)", "5" }; Assert.That(result, Is.EqualTo(expectations)); }
public void TestSliceOptimization(SourceKind sourceKind) { const int sliceStart = 4; const int sliceCount = 3; var sequence = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }.ToSourceKind(sourceKind); var result = sequence.Slice(sliceStart, sliceCount); Assert.AreEqual(sliceCount, result.Count()); CollectionAssert.AreEqual(Enumerable.Range(5, sliceCount), result); }
public Source( SourceKind sourceKind, string title, string author, int creationYear) { SourceKind = sourceKind; Title = title; Author = author; CreationYear = creationYear; }
public PropertyDescription(SourceKind kind, string name, object defaultValue, object minimum, object maximum, IValueConverter converter = null, string feedbackPropertyName = null) { Kind = kind; Name = name; DefaultValue = defaultValue; Minimum = minimum; Maximum = maximum; Converter = converter; FeedbackPropertyName = feedbackPropertyName; // ReadOnly = readOnly; }
public ActiveState() { activeLicenceKind = LicenceKind.SecondLicence; activeRoad = null; activeTown = null; activeHexa = null; activeTownPos = 255; activeSourceKind = SourceKind.Count; activeUpgradeKind = UpgradeKind.SecondUpgrade; activeSourceBuildingKind = SourceBuildingKind.Count; activePlayer = null; }
public void FallbackIfEmptyPreservesSourceCollectionIfPossible(SourceKind sourceKind) { var source = new[] { 1 }.ToSourceKind(sourceKind); // ReSharper disable PossibleMultipleEnumeration Assert.AreSame(source.FallbackIfEmpty(12), source); Assert.AreSame(source.FallbackIfEmpty(12, 23), source); Assert.AreSame(source.FallbackIfEmpty(12, 23, 34), source); Assert.AreSame(source.FallbackIfEmpty(12, 23, 34, 45), source); Assert.AreSame(source.FallbackIfEmpty(12, 23, 34, 45, 56), source); Assert.AreSame(source.FallbackIfEmpty(12, 23, 34, 45, 56, 67), source); // ReSharper restore PossibleMultipleEnumeration }
public bool BuyLicence(SourceKind source) { LicenceKind licenceKind = owner.GetMarketLicence(source); UpgradeKind upgradeKind; switch (licenceKind) { case LicenceKind.NoLicence: upgradeKind = UpgradeKind.FirstUpgrade; break; case LicenceKind.FirstLicence: upgradeKind = UpgradeKind.SecondUpgrade; break; default: return false; } return GameState.map.GetMapController().BuyUpgradeInSpecialBuilding(townID, hexaID, upgradeKind, (int)source); }
public static FileStructureMetadata CreateDefault(SourceKind sourceKind) { var metadata = new FileStructureMetadata { SourceKind = sourceKind }; if (CsvAccountOperationManager.DefaultCsvConfigurations.ContainsKey(sourceKind)) { var defaultConfig = CsvAccountOperationManager.DefaultCsvConfigurations[sourceKind]; metadata.Encoding = defaultConfig.Encoding.WebName; metadata.Culture = defaultConfig.CultureInfo.Name; metadata.DecimalSeparator = defaultConfig.CultureInfo.NumberFormat.CurrencyDecimalSeparator; } return(metadata); }
public void ForStaticMemberReferencedInSameClass_DoesNotReport( [ValueSource(nameof(SourceKinds))] SourceKind sourceKind) { string source = @" using NUnit.Framework; [TestFixture] public class TestClass { " + CreateTestMethodString(sourceKind, "\"Cases\"") + @" static object[] Cases = { new object[] {1}, new object[] {2} } } "; VerifyNoDiagnosticReported(source); }
private void Update() { #if UNITY_WSA || UNITY_EDITOR this.prevLeftHandState = this.leftHandState; this.leftHandState = null; this.prevRightHandState = this.rightHandState; this.rightHandState = null; this.prevUnspecifiedHandState = this.unspecifiedHandState; this.unspecifiedHandState = null; this.readings = MRWSAInput.InteractionManager.GetCurrentReading(); foreach (var reading in this.readings) { SourceKind sourceKind = SourceKind.Other; #if UNITY_5 sourceKind = (SourceKind)Enum.ToObject(typeof(SourceKind), reading.source.sourceKind); #else sourceKind = (SourceKind)Enum.ToObject(typeof(SourceKind), reading.source.kind); #endif if (sourceKind == kind) { if (reading.source.handedness == MRWSAInput.InteractionSourceHandedness.Left) { this.leftHandState = reading; } else if (reading.source.handedness == MRWSAInput.InteractionSourceHandedness.Right) { this.rightHandState = reading; } #if UNITY_5 else if (reading.source.handedness == MRWSAInput.InteractionSourceHandedness.Unspecified) #else else if (reading.source.handedness == MRWSAInput.InteractionSourceHandedness.Unknown) #endif { this.unspecifiedHandState = reading; } SetPressedPointerState(reading.source.handedness); } } #endif }
public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { if ((value == null)) { return(null); } SourceKind valueCasted = ((SourceKind)(value)); if ((valueCasted == SourceKind.Process)) { return("process"); } if ((valueCasted == SourceKind.Substituted)) { return("substituted"); } throw new ArgumentOutOfRangeException("value"); }
//--- ctor // Note importance of passing type through to base public RelationStream(SourceKind kind, string connector, string name, string heading = null) { if (connector == null) { throw Error.NullArg("connector"); } _stream = DataSourceStream.Create(kind, connector); if (_stream == null) { throw Error.Fatal($"cannot connect to '{kind}' with '{connector}'"); } if (!_stream.SelectTable(name)) { throw Error.Fatal($"cannot find '{name}' on '{connector}'"); } if (heading != null) { _stream.SetHeading(heading); } }
public async Task <List <AccountOperationBase> > ReadAsync(Stream sourceStream, FileStructureMetadata structureMetadata) { var result = new List <AccountOperationBase>(); SourceKind sourceKind = structureMetadata.SourceKind; var config = CreateCsvConfiguration(structureMetadata); using (var textReader = new StreamReader(sourceStream, config.Encoding, true, 1024, true)) using (var reader = new CsvReader(textReader, config)) { while (await reader.ReadAsync()) { AccountOperationBase record; switch (sourceKind) { case SourceKind.FortisCsvArchive: case SourceKind.FortisCsvExport: record = reader.GetRecord <FortisOperation>(); break; case SourceKind.SodexoCsvExport: record = reader.GetRecord <SodexoOperation>(); break; case SourceKind.InternalCsvExport: record = reader.GetRecord <UnifiedAccountOperation>(); break; default: throw new ArgumentOutOfRangeException(nameof(sourceKind)); } record.SourceKind = sourceKind; result.Add(record); } } return(result); }
public void ForStaticMemberReferencedInOtherNamespaceClass_DoesNotReport( [ValueSource(nameof(SourceKinds))] SourceKind sourceKind) { string source = @" using NUnit.Framework; namespace Outer { class OuterSource { public static object[] Cases = { new object[] {1}, new object[] {2} } } } [TestFixture] public class TestClass { " + CreateTestMethodString(sourceKind, "typeof(Outer.OuterSource), \"Cases\"") + @" } "; VerifyNoDiagnosticReported(source); }
public void ForTypeReferenced_DoesNotReport([ValueSource(nameof(SourceKinds))] SourceKind sourceKind) { string source = @" using NUnit.Framework; class TcSource : IEnumerable { public IEnumerator GetEnumerator() { yield return new object[] { 1 } yield return new object[] { 2 } } } [TestFixture] public class TestClass { " + CreateTestMethodString(sourceKind, "typeof(TcSource)") + @" } "; VerifyNoDiagnosticReported(source); }
internal static IEnumerable <T> ToSourceKind <T>(this IEnumerable <T> input, SourceKind sourceKind) { switch (sourceKind) { case SourceKind.Sequence: return(input.Select(x => x)); case SourceKind.BreakingList: return(input.ToBreakingList(false)); case SourceKind.BreakingReadOnlyList: return(input.ToBreakingList(true)); case SourceKind.BreakingCollection: return(input.ToBreakingCollection(false)); case SourceKind.BreakingReadOnlyCollection: return(input.ToBreakingCollection(true)); default: throw new ArgumentException(nameof(sourceKind)); } }
// Create an input source of given type and location // The locator argument is a path or connection string. The actual filename or table name comes later. internal static DataSourceStream Create(SourceKind source, string locator) { switch (source) { case SourceKind.Csv: return(DataSourceCsv.Create(locator)); case SourceKind.Text: return(DataSourceFile.Create(locator)); case SourceKind.Sql: return(DataSourceSql.Create(locator)); case SourceKind.Oledb: return(DataSourceOleDb.Create(locator)); case SourceKind.Odbc: return(DataSourceOdbc.Create(locator)); default: throw Error.Argument($"bad source: {source}"); } }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime) { base.Update(gameTime); if (fromSelectKind == SourceKind.Null || toSelectKind == SourceKind.Null) change_button.Disabled = true; else change_button.Disabled = false; foreach (GuiComponent g in content) { g.Update(gameTime); } if (wasActive != isActive) { // reset when user opens or closes market window foreach (ButtonComponent b in fromButtons) { b.setPicked(false); } foreach (ButtonComponent b in toButtons) { b.setPicked(false); } fromSelectKind = SourceKind.Null; toSelectKind = SourceKind.Null; marketSlider.ResetSlider(); wasActive = isActive; } marketSlider.Update(gameTime); if (InputManager.Inst().GetGameAction("gamemarket", "close").IsPressed()) MarketComponent.Inst().SetIsActive(false); if (InputManager.Inst().GetGameAction("gamemarket", "ok").IsPressed()) ChangeMaterial(); if (InputManager.Inst().GetGameAction("gamemarket", "left").IsPressed()) { marketSlider.MoveSliderLeft(); } if (InputManager.Inst().GetGameAction("gamemarket", "right").IsPressed()) { marketSlider.MoveSliderRight(); } }
public LicenceKind GetMarketLicence(SourceKind kind) { return licenceMarket[(int)kind]; }
private PriceKind GetPriceForMarketLicence(LicenceKind licenceKind, SourceKind sourceKind) { switch (licenceKind) { case LicenceKind.FirstLicence: switch (sourceKind) { case SourceKind.Corn: return PriceKind.MCorn1; case SourceKind.Meat: return PriceKind.MMeat1; case SourceKind.Stone: return PriceKind.MStone1; case SourceKind.Wood: return PriceKind.MWood1; case SourceKind.Ore: return PriceKind.MOre1; } break; case LicenceKind.SecondLicence: switch (sourceKind) { case SourceKind.Corn: return PriceKind.MCorn2; case SourceKind.Meat: return PriceKind.MMeat2; case SourceKind.Stone: return PriceKind.MStone2; case SourceKind.Wood: return PriceKind.MWood2; case SourceKind.Ore: return PriceKind.MOre2; } break; } return PriceKind.MCorn1; }
public bool HaveEnoughMaterialForConversion(SourceKind kind) { return source.Get(kind) >= GetConversionRate(kind); }
public bool BuyLicence(SourceKind source) { Player p = gm.GetActivePlayer(); List<IMarket> market = p.GetMarket(); foreach (IMarket m in market) { switch (m.CanBuyLicence(source)) { case MarketError.HaveSecondLicence: case MarketError.BanSecondLicence: return false; case MarketError.NoSources: return false; case MarketError.OK: return m.BuyLicence(source); case MarketError.MaxLicences: // May be free slot in another market break; } } return false; }
public MarketError CanBuyLicence(SourceKind source) { Player p = gm.GetActivePlayer(); List<IMarket> market = p.GetMarket(); foreach (IMarket m in market) { switch (m.CanBuyLicence(source)) { case MarketError.BanSecondLicence : SetLastError(Strings.ERROR_BAN_SECOND_LICENCE); return MarketError.BanSecondLicence; case MarketError.HaveSecondLicence : SetLastError(Strings.ERROR_HAVE_SECOND_LICENCE); return MarketError.HaveSecondLicence; case MarketError.NoSources : SetLastError(Strings.ERROR_NO_SOURCES); return MarketError.NoSources; case MarketError.OK : return MarketError.OK; case MarketError.MaxLicences : // May be free slot in another market break; } } SetLastError(Strings.ERROR_MAX_LICENCES); return MarketError.MaxLicences; }
public void BatchEmptySource(SourceKind kind) { var batches = Enumerable.Empty <int>().ToSourceKind(kind).Batch(100); Assert.That(batches, Is.Empty); }
public BuyLicenceAtom(IMapController map, SourceKind kind, int depth) : base(map, depth, "Buy licence") { this.kind = kind; }
public int Get(SourceKind sourceKind) { switch (sourceKind) { case SourceKind.Corn: return corn; case SourceKind.Meat: return meat; case SourceKind.Ore: return ore; case SourceKind.Stone: return stone; case SourceKind.Wood: return wood; default: return 0; } }
public int KindToInt(SourceKind kind) { switch (kind) { case SourceKind.Corn: return 0; case SourceKind.Meat: return 1; case SourceKind.Stone: return 2; case SourceKind.Wood: return 3; case SourceKind.Ore: return 4; } return -1; }
public SourceKind[] Order() { SourceKind[] kind = new SourceKind[(int) SourceKind.Count]; kind[0] = SourceKind.Corn; kind[1] = SourceKind.Meat; kind[2] = SourceKind.Stone; kind[3] = SourceKind.Wood; kind[4] = SourceKind.Ore; int[] number = this; int min; int tempInt; SourceKind tempKind; for (int loop1 = 0; loop1 < 5; loop1++) { min = loop1; for (int loop2 = loop1 + 1; loop2 < 5; loop2++) { if (number[loop2] < number[min]) min = loop2; } tempInt = number[loop1]; number[loop1] = number[min]; number[min] = tempInt; tempKind = kind[loop1]; kind[loop1] = kind[min]; kind[min] = tempKind; } return kind; }
public void ResetSlider() { sliderPosition.X = spritePosition.X; clickablePos = new Rectangle(Settings.scaleW(sliderPosition.X), Settings.scaleH(sliderPosition.Y), sliderW, sliderH); this.fromKind = SourceKind.Null; this.toKind = SourceKind.Null; this.fromTypeCount = 0; this.fromConvertedCount = 0; this.toTypeCount = 0; this.toConvertedCount = 0; }
internal bool BuyLicence(SourceKind activeSourceKind) { if (mapController.BuyLicence(activeSourceKind)) { licenceAmount++; return true; } else { if (mapController.CanBuyLicence(activeSourceKind) == MarketError.BanSecondLicence) return false; throw new Exception("Buying licence. " + mapController.GetLastError()); //return false; } }
public void setFromType(SourceKind k) { this.fromKind = k; this.fromTypeCount = GameMaster.Inst().GetActivePlayer().GetMaterialNumber(fromKind); this.fromConvertedCount = fromTypeCount; MoveSliderToStart(); }
public ISourceAll GetPrice(SourceKind sourceKind, LicenceKind licenceKind) { if (licenceKind == LicenceKind.NoLicence) return new SourceAll(0); return GetPrice(GetPriceForMarketLicence(licenceKind, sourceKind)); }
public ChangingSourcesError ChangeSources(SourceKind fromSource, SourceKind toSource, int fromAmount) { GameMaster gm = GameMaster.Inst(); int rate = gm.GetActivePlayer().GetConversionRate(fromSource); if (fromAmount > gm.GetActivePlayer().GetSource().Get(fromSource)) { SetLastError(Strings.ERROR_NOT_ENOUGHT_FROM_SOURCE); return ChangingSourcesError.NotEnoughFromSource; } gm.DoMaterialConversion(fromSource, toSource, gm.GetActivePlayer(), fromAmount - (fromAmount % rate), fromAmount / rate); return ChangingSourcesError.OK; }
/// <summary> /// Event handler for materials button /// </summary> void MaterialButtonAction(object sender, PlayerIndexEventArgs e) { ButtonComponent btn = (ButtonComponent)sender; if (disallowChangingSameTypes(btn)) { return; } //disallow clicking on inactive button - only for first row if (fromButtons.Contains(btn) && !btn.isActive()) { return; } //reset - only one button from the row can be picked if (toButtons.Contains(btn)) { foreach (ButtonComponent b in toButtons) { b.setPicked(false); } toSelectKind = btn.getType(); TriggerManager.Inst().TurnTrigger(TriggerType.MarketSecondRow, (int)toSelectKind); marketSlider.setToType(toSelectKind); } else { //dealing with second row of the buttons foreach (ButtonComponent b in fromButtons) { b.setPicked(false); } fromSelectKind = btn.getType(); TriggerManager.Inst().TurnTrigger(TriggerType.MarketFirstRow, (int)fromSelectKind); marketSlider.setFromType(fromSelectKind); marketSlider.MoveSliderToStart(); } btn.setPicked(!btn.getPicked()); }
public void MemoizeWithInMemoryCollection(SourceKind sourceKind) { var collection = Enumerable.Empty <int>().ToSourceKind(sourceKind); Assert.That(collection.Memoize(), Is.SameAs(collection)); }
public void DoMaterialConversion(SourceKind from, SourceKind to, Player p, int fromAmount, int toAmount) { if (from == SourceKind.Null || to == SourceKind.Null) return; int rate = p.GetConversionRate(from); if (!this.IsMaterialAvailable(from,rate)) { return; } //remove material from player SourceAll cost = CreateSourceAllCost(from, -fromAmount); p.AddSources(cost,TransactionState.TransactionStart); //add new material SourceAll get = CreateSourceAllCost(to, toAmount); p.AddSources(get, TransactionState.TransactionEnd); }
private HexaKind SourceKindToHexaKind(SourceKind source) { switch (source) { case SourceKind.Corn: return HexaKind.Cornfield; case SourceKind.Meat: return HexaKind.Pasture; case SourceKind.Ore: return HexaKind.Mountains; case SourceKind.Stone: return HexaKind.Stone; case SourceKind.Wood: return HexaKind.Forest; default : return HexaKind.Nothing; // shouldnt happened } }
private static string GetExpectedAttributeName(SourceKind sourceKind) => sourceKind.ToString();
/// <summary> /// Checks whether user has enough resources from the type he wants to change in market /// </summary> /// <returns></returns> protected bool IsMaterialAvailable(SourceKind from, int rate) { return GetActivePlayer().HaveEnoughMaterialForConversion(from); }
public void setToType(SourceKind k) { toKind = k; this.toTypeCount = GameMaster.Inst().GetActivePlayer().GetMaterialNumber(toKind); this.toConvertedCount = toTypeCount; MoveSliderToStart(); }
private static string CreateTestMethodString(SourceKind sourceKind, string attributeParams) { return(sourceKind == SourceKind.TestCaseSource ? "[TestCaseSource(" + attributeParams + ")] public void TestMethod(int x) {}" : "public void TestMethod([ValueSource(" + attributeParams + ")]int x) {}"); }
protected SourceAll CreateSourceAllCost(SourceKind kind, int rate) { switch (kind) { case SourceKind.Wood: return new SourceAll(0, 0, 0, rate, 0); case SourceKind.Stone: return new SourceAll(0, 0, rate, 0, 0); case SourceKind.Corn: return new SourceAll(rate, 0, 0, 0, 0); case SourceKind.Meat: return new SourceAll(0, rate, 0, 0, 0); case SourceKind.Ore: return new SourceAll(0, 0, 0, 0, rate); default : return new SourceAll(0); } }
private static DiagnosticResultLocation GetExpectedDiagnosticLocation(SourceKind sourceKind) => sourceKind == SourceKind.TestCaseSource ? new DiagnosticResultLocation("Test0.cs", 7, 6) : new DiagnosticResultLocation("Test0.cs", 7, 29);
/// <summary> /// Method is responsible for disapproving changing same material for same material - like corn for corn /// </summary> /// <returns>true if we should disallow clicking</returns> bool disallowChangingSameTypes(ButtonComponent btn) { if (fromButtons.Contains(btn)) { foreach (ButtonComponent b in toButtons) { //trying to find selected button if (b.getPicked()) { if (b.getType() == btn.getType()) { // first row has bigger priority b.setPicked(false); toSelectKind = SourceKind.Null; marketSlider.setToType(SourceKind.Null); return false; } //we can break because only one button can be selected break; } } } else { foreach (ButtonComponent b in fromButtons) { //trying to find selected button if (b.getPicked()) { if (b.getType() == btn.getType()) { return true; } //we can break because only one button can be selected break; } } } return false; }
public int GetMaterialNumber(SourceKind k) { return source.Get(k); }
public int GetConversionRate(SourceKind kind) { if (kind == SourceKind.Null) return -1; switch (licenceMarket[(int)kind]) { case LicenceKind.NoLicence: return 4; case LicenceKind.FirstLicence: return 3; case LicenceKind.SecondLicence: return 2; } return -1; }