20.抽卡只有金,带保底(WPF) C#

这是一个界面应用化后的抽卡,目前只能抽金,只有基础概率加保底概率

适合界面化应用初学者。

这是展示图:

使用的是WPF不是winform,我也是第一次做WPF内容,就可以试一试,代码都在这里了,简单来说,复制过去就能用。XAML就是界面设计的描述性语言,和界面一样的。

看到左下角那个XAML了吗,点进去复制粘贴就行了

代码:

cs 复制代码
using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 抽卡只有金_带保底
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static List<double> randomNumbers = new List<double>();
        public MainWindow()
        {
            InitializeComponent();

            Random random = new Random(); // 不使用种子值
            int Length = 60000;
            

            
            randomNumbers.Clear();
            for (int j = 0; j < Length; j++)
            {
                    //minValue 是包含的下界(即可以生成该值),而 maxValue 是不包含的上界(即不会生成该值)。
               randomNumbers.Add(random.NextDouble()); // 生成0到999之间的随机数

            }
            

        }

        //保底记录
        static int minimumGuarantee = 0;
        //保底概率
        static double guaranteeProbability = 0;

        static int i = 0;
        //抽中总数
        static int num2 = 0;
        //抽取总数
        static int num = 0;
        static double realp = 0;
        static double p = 0.6 * 0.01;


        private void Button_Click(object sender, RoutedEventArgs e)
        {


            for (int n = 0; n < 10; n++, i++)
            {
                minimumGuarantee = minimumGuarantee + 1;

                if (randomNumbers[i] <= p + guaranteeProbability)
                {
                    //Console.WriteLine("***抽中了***");
                    num2 = num2 + 1;
                    minimumGuarantee = 0;
                    guaranteeProbability = 0;
                }
                else
                {
                    //Console.WriteLine("没抽中");
                }

                //第59抽结尾增加概率并一次性减去p,第60抽开始使用高概率,结果实际计算时发现去掉这个p才是实际的1.605%
                if (minimumGuarantee == 73)
                {
                    guaranteeProbability = 0;
                }
                if (minimumGuarantee >= 73)
                {
                    guaranteeProbability = guaranteeProbability + (double)1 / 17;
                }


            }
            //更新十次抽取总数
            num = num + 10;
            realp = (double)num2 / num * 100;
            Console.WriteLine("已经抽了{0},抽中{1},概率{2:0.000}%", num, num2, realp);



            Label1.Content = ($"已经抽了{num},抽中{num2},概率{realp:0.000}%");

        }
    }
}

XAML:

XML 复制代码
<Window x:Class="抽卡只有金_带保底.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:抽卡只有金_带保底"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Content="一次十连" HorizontalAlignment="Left" Margin="205,163,0,0" VerticalAlignment="Top" Click="Button_Click" Height="45" Width="120" FontSize="24"/>
        <Label x:Name="Label1" Content="结合保底综合命中率1.6%" HorizontalAlignment="Left" Margin="360,165,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" FontSize="22">
            <Label.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="-0.356"/>
                    <TranslateTransform/>
                </TransformGroup>
            </Label.RenderTransform>
        </Label>

    </Grid>
</Window>
相关推荐
葬歌倾城5 小时前
JSON的缩进格式方式和紧凑格式方式
c#·json
Eiceblue7 小时前
使用 C# 发送电子邮件(支持普通文本、HTML 和附件)
开发语言·c#·html·visual studio
小小小小王王王7 小时前
hello判断
开发语言·c#
共享ui设计和前端开发人才7 小时前
UI前端大数据处理安全性保障:数据加密与隐私保护策略
ui
ui设计前端开发老司机7 小时前
UI前端大数据处理性能瓶颈突破:分布式计算框架的应用
ui
前端开发与ui设计的老司机7 小时前
UI前端与数字孪生结合实践探索:智慧物流的货物追踪与配送优化
前端·ui
金增辉9 小时前
基于C#的OPCServer应用开发,引用WtOPCSvr.dll
c#
future141211 小时前
C#学习日记
开发语言·学习·c#
UI设计和前端开发从业者11 小时前
从UI设计到数字孪生实战应用:构建智慧金融的智能风控平台
ui·金融
傻啦嘿哟12 小时前
Python 办公实战:用 python-docx 自动生成 Word 文档
开发语言·c#