/// <summary> /// Naissance du bébé /// </summary> /// <param name="x"></param> /// <param name="y"></param> public void Born(int x, int y, CoinTypes coinType) { this.IsAlive = true; this.coinType = coinType; if (coinType == CoinTypes.Coin1) { coinAnimator = coin1Animator; } else { coinAnimator = coin5Animator; } coinAnimator.AnimationType = AnimationTypes.Manual; coinAnimator.Start(); int yPath = machine.Screen.BoundsClipped.Bottom - y - this.Height - 4; var width = this.machine.GetRandomInteger(10, 70); var direction = this.machine.GetRandomInteger(2) == 0 ? -1 : 1; // deplacement this.pathMove.Initialize(EasingFunctions.QuinticEaseOut, EasingFunctions.BounceEaseOut, width, yPath, direction, 1, 100); // temps d'animation : plus c'est le debut plus c'est rapide this.pathAnimation.Initialize(EasingFunctions.QuinticEaseOut, EasingFunctions.Linear, 5, 0, 1, 1, 100); this.X = x; this.Y = y; this.originalY = y; this.originalX = X; }
/// <summary> /// 从数据库中获取Ticker数据 /// </summary> public IExecuteResult <Ticker> GetDataFromDataBase(string key) { try { KeyParse keyParse; KeyParse.TryParse(key, out keyParse); CoinTypes coinType = keyParse.CoinType; PlatformTypes platformType = keyParse.PlatformType; string sqlStr = string.Format("SELECT * FROM `coin`.`trades` WHERE `CoinId` ={0} AND `PlatformId` = {1} ORDER BY `NowTime` DESC LIMIT 1" , (int)coinType, (int)platformType); DataTable dt = QueryData(sqlStr); if (dt == null || dt.Rows.Count == 0) { return(ExecuteResult <Ticker> .Fail(SystemErrors.Unknown, "没有获取到数据")); } Ticker ticker = new Ticker { BuyPrice = double.Parse(dt.Rows[0]["BuyPrice"].ToString()), SellPrice = double.Parse(dt.Rows[0]["SellPrice"].ToString()), HignPrice = double.Parse(dt.Rows[0]["HighPrice"].ToString()), LowPrice = double.Parse(dt.Rows[0]["LowPrice"].ToString()), LastPrice = double.Parse(dt.Rows[0]["LastPrice"].ToString()), Vol = double.Parse(dt.Rows[0]["TradeVol"].ToString()) }; //Tradescs tradesc = new Tradescs(coinType, ticker, platformType, ((MySqlDateTime)dt.Rows[0]["NowTime"]).GetDateTime()); return(ExecuteResult <Ticker> .Succeed(ticker)); } catch (Exception ex) { _tracing.Error(ex, null); return(ExecuteResult <Ticker> .Fail(SystemErrors.Unknown, ex.Message)); } }
public IExecuteResult GetValue(CoinTypes coinType, PlatformTypes platformType) { try { KeyParse keyParse = new KeyParse { CoinType = coinType, PlatformType = platformType }; string key = keyParse.ToString(); string content = m_Cache[key] as string; if (content == null) { CacheItemPolicy policy = new CacheItemPolicy(); policy.AbsoluteExpiration = DateTime.Now.AddMilliseconds(25000); IExecuteResult <Ticker> result = _remoteApiService.GetDataFromDataBase(key); if (result.State != ExecuteResults.Succeed) { return(ExecuteResult.Fail(SystemErrors.Unknown, null)); } content = result.GetResult().ToString(); m_Cache.Set(key, content, policy); } return(ExecuteResult.Succeed(JsonConvert.DeserializeObject <Ticker>(content))); } catch (Exception ex) { _tracing.Error(ex, null); return(ExecuteResult.Fail(SystemErrors.NotFound, null)); } }
/// <summary> /// 根据指定编号异步获取Ticker对象的操作 /// </summary> /// <param name="coinType">币种编号</param> /// <param name="platformType">平台编号</param> /// <returns>返回执行结果</returns> public async Task <IExecuteResult> GetTickerAsync(CoinTypes coinType, PlatformTypes platformType) { MetadataMessageTransaction transaction = SystemWorker.Instance.CreateMetadataTransaction("CoinAPI"); MetadataContainer reqMsg = new MetadataContainer(); reqMsg.SetAttribute(0x00, new MessageIdentityValueStored(new MessageIdentity { ProtocolId = 1, ServiceId = 0, DetailsId = 0 })); reqMsg.SetAttribute(0x0F, new ByteValueStored((byte)coinType)); reqMsg.SetAttribute(0x10, new ByteValueStored((byte)platformType)); TaskCompletionSource <IExecuteResult> completionSource = new TaskCompletionSource <IExecuteResult>(); Task <IExecuteResult> task = completionSource.Task; transaction.ResponseArrived += delegate(object sender, LightSingleArgEventArgs <MetadataContainer> e) { MetadataContainer rspMsg = e.Target; completionSource.SetResult((!rspMsg.IsAttibuteExsits(0x0A)) ? (rspMsg.GetAttribute(0x0F).GetValue <ResourceBlock>() == null ? ExecuteResult.Succeed(null) : ExecuteResult.Succeed(ConverterFactory.GetTickerConverter().ConvertToDomainObject(rspMsg.GetAttribute(0x0F).GetValue <ResourceBlock>()))) : ExecuteResult.Fail(rspMsg.GetAttribute(0x0A).GetValue <byte>(), rspMsg.GetAttribute(0x0B).GetValue <string>())); }; transaction.Timeout += delegate { completionSource.SetResult(ExecuteResult.Fail(SystemErrors.Timeout, string.Format("[Async Handle] Transaction: {0} execute timeout!", transaction.Identity))); }; transaction.Failed += delegate { completionSource.SetResult(ExecuteResult.Fail(SystemErrors.Unknown, string.Format("[Async Handle] Transaction: {0} execute failed!", transaction.Identity))); }; transaction.SendRequest(reqMsg); return(await task); }
public int GetCoinsFromCustomer() { foreach (var item in CoinInventory) { Console.WriteLine($"{(int)item.Key}: {item.Key.ToString()}"); } int userInput = int.Parse(Console.ReadLine()); if (userInput < 1 || userInput > 4) { if (userInput == -1) { GiveChange(); } else if (userInput == -2) { UpdateData(); } else if (userInput != 0) { Console.WriteLine("Thanks for the fake coin"); } return(userInput); } CoinTypes coinIn = (CoinTypes)userInput; Cents += GetCoinValue(coinIn); CoinInventory[coinIn]++; Console.WriteLine("Total: $" + string.Format("{0:#.00}", Convert.ToDecimal(Cents.ToString()) / 100)); return(userInput); }
public CoinsViewModel(CoinTypes type, Int32 count, String name = null) { Type = type; _count = count; _name = name; ChooseCommand = new Command(WhenChoosed); }
private int GetCoinValue(CoinTypes coin) { Type coinType = typeof(CoinTypes); FieldInfo coinInType = coinType.GetField(coin.ToString()); var coinValueAttribute = coinInType.GetCustomAttribute <CoinValueAttribute>(false); //hi return(coinValueAttribute.Value); }
/// <summary> /// 构造器 /// </summary> /// <param name="coinType"></param> /// <param name="ticker"></param> /// <param name="platformTypes"></param> /// <param name="dateTime"></param> /// <exception cref="ArgumentNullException">参数不能为空</exception> public Tradescs(CoinTypes coinType, Ticker ticker, PlatformTypes platformTypes, DateTime dateTime) { if (ticker == null) { throw new ArgumentNullException("ticker"); } _coinType = coinType; _ticker = ticker; _platformType = platformTypes; _nowTime = dateTime; }
public IEthereumService GetService(CoinTypes coinType, bool testNet) { switch (coinType) { case CoinTypes.Ethereum: if (!testNet) { return(new EthereumService(_siteUrl, "eth", "main")); } break; } throw new ServiceNotAvailableException(coinType, testNet); }
protected override void DoBussiness(MetadataContainer reqMsg, MetadataMessageTransaction transaction) { CoinTypes coinType = (CoinTypes)reqMsg.GetAttribute(0x0F).GetValue <byte>(); PlatformTypes platformType = (PlatformTypes)reqMsg.GetAttribute(0x10).GetValue <byte>(); IExecuteResult executeResult = CacheManager.Instance.GetValue(coinType, platformType); if (executeResult.State != ExecuteResults.Succeed) { transaction.SendResponse(GetErrorResponseMessage(SystemErrors.Unknown, executeResult.Error)); } else { ResourceBlock rspCampaignData = ConverterFactory.GetTickerConverter().ConvertToNetworkObject(executeResult.GetResult <Ticker>()); transaction.SendResponse(GetSucceedResponseMessage(rspCampaignData)); } }
public void GiveChange() { for (int i = 1; i < 5; i++) { CoinTypes coinType = (CoinTypes)i; int coinValue = GetCoinValue(coinType); int counter = 0; while (Cents / coinValue > 0 && CoinInventory[coinType] > 0) { Cents -= coinValue; CoinInventory[coinType]--; counter++; } Console.WriteLine($"Here is {counter} {coinType.ToString()}"); } }
public IBitcoinService GetService(CoinTypes coinType, bool testNet) { switch (coinType) { case CoinTypes.Bitcoin: return(new BitcoinService(_token, "btc", testNet ? "test3" : "main")); case CoinTypes.Dogecoin: if (!testNet) { return(new BitcoinService(_token, "doge", "main")); } break; case CoinTypes.Litecoin: if (!testNet) { return(new BitcoinService(_token, "ltc", "main")); } break; } throw new ServiceNotAvailableException(coinType, testNet); }
public void InsertCoin(CoinTypes coinType, int number) { switch (coinType) { case CoinTypes.USNickel: nickels += number; break; case CoinTypes.USDime: dimes += number; break; case CoinTypes.USQuarter: quarters += number; break; case CoinTypes.USPenny: break; default: break; } updateAmount(); }
/// <summary> /// Ajouter un hit de monstre (or mother) et donne une récompense eventuellement /// </summary> public void AddHitSmallMonster(int x, int y) { this.hitSmallMonsterCount++; bool hasReward = false; CoinTypes coinType = CoinTypes.Coin1; if (hitSmallMonsterCount != 0) { hasReward = this.hitSmallMonsterCount % 10 == 0; if (this.hitSmallMonsterCount % 100 == 0) { hasReward = true; coinType = CoinTypes.Coin5; } } if (hasReward) { this.coins.GetFreeSprite().Born(x, y, coinType); } }
/// <summary> /// Function for user to insert coin /// </summary> /// <param name="type">Coin type</param> public void InsertUserCoin(CoinTypes type) { if (_userBank.Keys.Contains(type)) _userBank[type].AddItems(1); else _userBank.Add(type, new CoinsViewModel(type, 1)); OnPropertyChanged("UserBankString"); }
public Coin(CoinTypes type) : base() { CoinType = type; }
public Coin(CoinTypes type, int x, int y) : this(type) { UpdatePosition(x, y); }
public void LoadCoins(CoinTypes type, int number) => coinHandler.InsertCoin(type, number);
public ServiceNotAvailableException(CoinTypes coinType, bool testNet) { CoinType = coinType; TestNet = testNet; }
/// <summary> /// Initializes a new instance of the <see cref="Coin" /> class. /// </summary> /// <param name="coinType">The type of coin.</param> public Coin(CoinTypes coinType) { this.CoinType = coinType; }
/// <summary> /// Adding coins to user's vallet /// </summary> /// <param name="type">Coins type</param> /// <param name="count">Number of coins</param> public void GiveCoins(CoinTypes type, int count) { _vallet[type].AddItems(count); }
/// <summary> /// Tries to return to user a number of coins of a special type /// </summary> /// <param name="type">Coins type</param> /// <param name="count">Needed count</param> /// <returns>Returns false if there is not enougth coins, operation does not perform</returns> private bool TryCoinsReturn(CoinTypes type, Int32 count) { if (SummaryCoinsNumber(type) < count) return false; if (_userBank.Keys.Contains(type)) { if (_userBank[type].Count >= count) { _VMvallet[type].AddItems(_userBank[type].Count - count); _userBank[type].TakeItems(_userBank[type].Count); OnPropertyChanged("UserBankString"); return true; } else { count -= _userBank[type].Count; _userBank[type].TakeItems(_userBank[type].Count); OnPropertyChanged("UserBankString"); } } _VMvallet[type].TakeItems(count); BankToVallet(count * _VMvallet[type].Value); return true; }
/// <summary> /// Counting number of coins of a specific type in VM vallet and user bank /// </summary> /// <param name="type">Coin type</param> /// <returns>Returns number of coins</returns> private int SummaryCoinsNumber(CoinTypes type) { var valletCount = 0; var bankCount = 0; if (_VMvallet.Keys.Contains(type)) valletCount = _VMvallet[type].Count; if (_userBank.Keys.Contains(type)) bankCount = _userBank[type].Count; return valletCount + bankCount; }