首頁  >  文章  >  微信小程式  >  分享.net製作的抽餐廳和遊戲裝備的小程序

分享.net製作的抽餐廳和遊戲裝備的小程序

高洛峰
高洛峰原創
2017-03-28 13:22:251412瀏覽

這篇文章主要介紹了.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 => 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 => 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 >= min && 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中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn