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 小时前
缺料分析时携带用料清单的二开字段
c#·金蝶云星空
bugcome_com6 小时前
深入了解 C# 编程环境及其开发工具
c#
wfserial8 小时前
c#使用微软自带speech选择男声仍然是女声的一种原因
microsoft·c#·speech
御承扬8 小时前
鸿蒙NDK UI之文本自定义样式
ui·华为·harmonyos·鸿蒙ndk ui
阔皮大师9 小时前
INote轻量文本编辑器
java·javascript·python·c#
聆风吟º10 小时前
CANN hccl 深度解析:异构计算集群通信库的跨节点通信与资源管控实现逻辑
人工智能·wpf·transformer·cann
一起养小猫10 小时前
Flutter for OpenHarmony 实战_魔方应用UI设计与交互优化
flutter·ui·交互·harmonyos
kylezhao201910 小时前
C# 中的 SOLID 五大设计原则
开发语言·c#
啦啦啦_999911 小时前
Redis-5-doFormatAsync()方法
数据库·redis·c#
Porco.w11 小时前
C#与三菱PLC FX5U通信
网络·c#