///<summary> ///回购物品(玩家买入) ///</summary> ///<param name="goods">回购的商品</param> ///<returns>回购是否成功</returns> public bool Buy(Goods goods) { //有此物品并且玩家的金钱足够 if(GameManager.GameInfo.Pack.GoodsList.ContainsKey(goods) && GameManager.GameInfo.Hero.Money - goods.Money >= 0) { //判断包裹中对应物品的位置 GameManager.GameInfo.Hero.Money -= goods.Money; //减去物品金额 GameManager.GameInfo.Pack.GoodsList[goods]++; //包裹物品数量加1 return true; } return false; }
/// <summary> /// 回购物品(请编码实现) /// </summary> /// <param name="goods">物品对象</param> private void Buy(Goods goods) { if(eatery.Sell(goods)) { lblHeroMoney.Text = GameManager.GameInfo.Hero.Money.ToString(); //显示更新后玩家金钱 MessageBox.Show("购买了1个" + goods.Name + "!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("你是不是忘记带钱了!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public Goods QQStar; //QQ星 #endregion Fields #region Methods /// <summary> /// 初始化所有物品 /// </summary> public void Init() { //面包 Bread = new Goods(); Bread.Name = "面包"; Bread.Type = GoodsType.Power; Bread.Money = 680; Bread.SaleMoney = Bread.Money / 10; Bread.Details = "知道金刚吗,它就是经常吃这个,才能在大厦顶打飞机的!(增加力量)"; //钙片 Calcium = new Goods(); Calcium.Name = "钙片"; Calcium.Type = GoodsType.Charm; Calcium.Money = 1080; Calcium.SaleMoney = Calcium.Money / 10; Calcium.Details = "吃一片,腰不酸、腿不疼,小脸蛋也更迷人啦!(增加魅力)"; //小红花 Flower = new Goods(); Flower.Name = "小红花"; Flower.Type = GoodsType.Morality; Flower.Money = 1280; Flower.SaleMoney = Flower.Money / 10; Flower.Details = "戴朵小红花,人见人夸!(增加道德)"; //彩票 Lottery = new Goods(); Lottery.Name = "彩票"; Lottery.Type = GoodsType.Luck; Lottery.Money = 1680; Lottery.SaleMoney = Lottery.Money / 10; Lottery.Details = "想有车有房有肉汤就靠它了!(增加运气)"; //QQ星 QQStar = new Goods(); QQStar.Name = "QQ星"; QQStar.Type = GoodsType.Intellect; QQStar.Money = 1880; QQStar.SaleMoney = QQStar.Money / 10; QQStar.Details = "自从喝了它,妈妈再也不担心我的学习了!(增加智力)"; //徽章 Badge = new Goods(); Badge.Name = "徽章"; Badge.Type = GoodsType.Prestige; Badge.SaleMoney = Badge.Money / 10; Badge.Details = "荣耀的象征,成功人士的标记!(增加威望)"; }
///<summary> ///出售物品(玩家出售) ///</summary> ///<param name="goods">出售的商品</param> ///<returns>出售的商品</returns> public bool Sell(Goods goods) { //判断包裹中对应物品的位置,数量大于0则可出售 if(GameManager.GameInfo.Pack.GoodsList.ContainsKey(goods) && GameManager.GameInfo.Pack.GoodsList[goods] > 0) { GameManager.GameInfo.Hero.Money += goods.SaleMoney; //增加物品出售金额 GameManager.GameInfo.Pack.GoodsList[goods]--; //包裹物品数量减1 return true; } return false; }
///<summary> ///随机运气效果 ///</summary> ///<returns>返回结果</returns> public string Luck() { StringBuilder strInfo = new StringBuilder(); //奖励字符串 Goods goods = new Goods(); Random rand = new Random(); //1.生成随机奖励物品 int tmp = rand.Next(1000) % 6; switch(tmp) { case 0: goods = GameManager.GameInfo.AllGoodsList.Bread; break; case 1: goods = GameManager.GameInfo.AllGoodsList.Calcium; break; case 2: goods = GameManager.GameInfo.AllGoodsList.Flower; break; case 3: goods = GameManager.GameInfo.AllGoodsList.Lottery; break; case 4: goods = GameManager.GameInfo.AllGoodsList.QQStar; break; case 5: goods = GameManager.GameInfo.AllGoodsList.Badge; break; } //2.生成随机奖励物品数量(1~5之间) int number = rand.Next(1000) % 5 +1; strInfo.Append("恭喜你获得"+ number + "个"+goods.Name+"。"); //3.奖励物品添加到包裹 GameManager.GameInfo.Pack.GoodsList[goods] += number; //4.10%几率另外提升随机属性 int randnum = rand.Next(1000); if(randnum<=100) { int value = rand.Next(10)+1; switch(tmp) { case 0: GameManager.GameInfo.Hero.Power += value; //提升力量 strInfo.Append("\n小宇宙爆发额外获得了"+value+"点力量。"); break; case 1: GameManager.GameInfo.Hero.Charm += value; //提升魅力 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点魅力。"); break; case 2: GameManager.GameInfo.Hero.Morality += value; //提升道德 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点道德。"); break; case 3: GameManager.GameInfo.Hero.Luck += value; //提升运气 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点运气。"); break; case 4: GameManager.GameInfo.Hero.Intellect += value; //提升智力 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点智力。"); break; case 5: GameManager.GameInfo.Hero.Prestige += value; //提升威望 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点威望。"); break; } } //5.返回结果信息 return strInfo.ToString(); }
/// <summary> /// 出售物品(请编码实现) /// </summary> /// <param name="goods">物品对象</param> private void Sell(Goods goods) { if(eatery.Buy(goods)) { lblHeroMoney.Text = GameManager.GameInfo.Hero.Money.ToString(); //显示更新后玩家金钱 MessageBox.Show("售出了1个" + goods.Name + "!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("抱歉,你身上没有" + goods.Name + "了!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
///<summary> ///随机运气效果 ///</summary> ///<returns>返回结果</returns> public string Luck() { StringBuilder strInfo = new StringBuilder(); //奖励字符串 Goods goods = new Goods(); Random rand = new Random(); //1.生成随机奖励物品 int tmp = rand.Next(1000) % 6; switch (tmp) { case 0: goods = GameManager.GameInfo.AllGoodsList.Bread; break; case 1: goods = GameManager.GameInfo.AllGoodsList.Calcium; break; case 2: goods = GameManager.GameInfo.AllGoodsList.Flower; break; case 3: goods = GameManager.GameInfo.AllGoodsList.Lottery; break; case 4: goods = GameManager.GameInfo.AllGoodsList.QQStar; break; case 5: goods = GameManager.GameInfo.AllGoodsList.Badge; break; } //2.生成随机奖励物品数量(1~5之间) int number = rand.Next(1000) % 5 + 1; strInfo.Append("恭喜你获得" + number + "个" + goods.Name + "。"); //3.奖励物品添加到包裹 GameManager.GameInfo.Pack.GoodsList[goods] += number; //4.10%几率另外提升随机属性 int randnum = rand.Next(1000); if (randnum <= 100) { int value = rand.Next(10) + 1; switch (tmp) { case 0: GameManager.GameInfo.Hero.Power += value; //提升力量 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点力量。"); break; case 1: GameManager.GameInfo.Hero.Charm += value; //提升魅力 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点魅力。"); break; case 2: GameManager.GameInfo.Hero.Morality += value; //提升道德 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点道德。"); break; case 3: GameManager.GameInfo.Hero.Luck += value; //提升运气 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点运气。"); break; case 4: GameManager.GameInfo.Hero.Intellect += value; //提升智力 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点智力。"); break; case 5: GameManager.GameInfo.Hero.Prestige += value; //提升威望 strInfo.Append("\n小宇宙爆发额外获得了" + value + "点威望。"); break; } } //5.返回结果信息 return(strInfo.ToString()); }