登录  /  注册

分享.net制作的抽餐厅和游戏装备的小程序

高洛峰
发布: 2017-03-28 13:22:25
原创
1268人浏览过

这篇文章主要介绍了.net制作的抽餐厅和游戏装备的小程序,小伙伴们以后再也不用每天都考虑去哪里吃饭了,非常好玩和实用,需要的朋友可以参考下

随便新建一个asp.net web项目,拖入即可。现在知道为什么游戏老是暴不出好装备,因为他的权重是非常小地。。。中午吃饭随机一下,想去哪一家,就把权重值设大一点,再中不了,就认命吧!

分享.net制作的抽餐厅和游戏装备的小程序

Default.aspx

 
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 


  <title>加权随机</title>
  
登录后复制
  

     
  
     
  
     
  
     
     

  

 Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI.Page
{
  //<string>:
  public Dictionary<string> Goods = new Dictionary<string>();
  public int TotalWeight = 0;
 
  public class Good
  {
    /// <summary>
    /// 名称
    /// </summary>
    public string Name
    {
      get;
      set;
    }
    /// <summary>
    /// 权重(大于等于1,否则出现的可能性为0)
    /// </summary>
    public int Weight
    {
      get;
      set;
    }
  }
 
  public List<good> Result = new List<good>();
 
  protected void Page_Load(object sender, EventArgs e)
  {
  }
 
  /// <summary>
  /// 初始化装备 俺是《梦三国》玩家,嘿嘿
  /// </summary>
  protected void InitGoods()
  {
    Goods.Clear();
    TotalWeight = 0;
 
    Goods.Add("寒冰爪", 2);     //神器(拳爪类)
    Goods.Add("重毛皮", 300);
    Goods.Add("小毛皮", 1000);
    Goods.Add("轻毛皮", 1000);
    Goods.Add("神之防具打造书", 5);
    Goods.Add("传说武器打造书", 20);
    Goods.Add("紫檀树枝", 300);
    Goods.Add("硬毛皮", 600);
    Goods.Add("勾魂水晶", 8);
    Goods.Add("真龙炙舞剑", 30);
    Goods.Add("董卓勾魂", 1);    //神器中的神器(长柄类)
 
    foreach (KeyValuePair<string> kvp in Goods)
    {
      TotalWeight += kvp.Value;
    } 
  }
 
  /// <summary>
  /// 初始化餐厅,公司楼下餐厅比较多,只写几个,意思意思。。。
  /// </summary>
  protected void InitFood()
  {
    Goods.Clear();
    TotalWeight = 0;
 
    Goods.Add("清真兰州", 1);
    Goods.Add("长安客", 1);
    Goods.Add("迎客松", 1);
    Goods.Add("吉祥混沌", 1);
 
    foreach (KeyValuePair<string> kvp in Goods)
    {
      TotalWeight += kvp.Value;
    }
  }
 
  protected int GetTryParse()
  {
    try
    {
      return int.Parse(txtNum.Text);
    }
    catch {
      return 1;
    }
  }
 
  //开始抽奖(装备)
  protected void btnRandom_Click(object sender, EventArgs e)
  {
    InitGoods();
 
    lblResult.Text = lblResult.Text + "<br>";
 
    int Count = GetTryParse();
    for (int i = 1; i  kvp in Goods)
    {
      int c = Result.Count(d =&gt; d.Name == kvp.Key);
      double rate = c * 1.0 / Count * 1.0 * 100;
 
      lblResult.Text = lblResult.Text + "物品名称:" + kvp.Key + " 权重:" + kvp.Value + " 暴出次数:" + c.ToString() + " 暴出率:" + rate + "%<br>";
    }
 
  }
 
  //开始抽奖(餐厅)
  protected void btnRandomFood_Click(object sender, EventArgs e)
  {
    InitFood();
 
    lblResult.Text = lblResult.Text + "<br>";
 
    int Count = GetTryParse();
    for (int i = 1; i  kvp in Goods)
    {
      int c = Result.Count(d =&gt; d.Name == kvp.Key);
      double rate = c * 1.0 / Count * 1.0 * 100;
 
      lblResult.Text = lblResult.Text + "餐厅名称:" + kvp.Key + " 权重:" + kvp.Value + " 暴出次数:" + c.ToString() + " 暴出率:" + rate + "%<br>";
    }
 
  }
 
  /// <summary>
  /// 根据随机权重判断所在范围
  /// </summary>
  /// <param>
  protected void ProduceResult(int Weight)
  {
    int min = 1;
    int max = 1;
    foreach (KeyValuePair<string> kvp in Goods)
    {
      max = min + kvp.Value - 1;
 
      if (Weight &gt;= min &amp;&amp; Weight 
  /// 随机种子值(防止速度过快造成的重复)
  /// 
  /// <returns></returns>
  private static int GetRandomSeed()
  {
    byte[] bytes = new byte[4];
    System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
    rng.GetBytes(bytes);
    return BitConverter.ToInt32(bytes, 0);
  }
 
  //清屏操作
  protected void btnClear_Click(object sender, EventArgs e)
  {
    lblResult.Text = "";
  }
}</string></string></string></good></good></string></string></string>
登录后复制

以上所述就是本文的全部内容了,希望大家能够喜欢。

以上就是分享.net制作的抽餐厅和游戏装备的小程序的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号