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>
相关推荐
wuty0072 小时前
完善基于WPF开发的标尺控件(含实例代码)
wpf·wpf标尺·支持横向竖向标尺·ruler
mocoding7 小时前
使用Flutter设置UI三方库card_settings_ui重构鸿蒙版天气预报我的页面
flutter·ui·harmonyos
初九之潜龙勿用8 小时前
C# 操作Word模拟解析HTML标记之背景色
开发语言·c#·word·.net·office
雨季6668 小时前
Flutter 三端应用实战:OpenHarmony 简易点击计数器与循环颜色反馈器开发指南
开发语言·flutter·ui·ecmascript·dart
时光追逐者9 小时前
使用 MWGA 帮助 7 万行 Winforms 程序快速迁移到 WEB 前端
前端·c#·.net
老骥伏枥~10 小时前
【C# 入门】程序结构与 Main 方法
开发语言·c#
全栈师10 小时前
java和C#的基本语法区别
java·开发语言·c#
钰fly10 小时前
联合编程(加载单个工具,ini读写,图片读写,setting存储)
c#
雨季66612 小时前
Flutter 三端应用实战:OpenHarmony 简易“动态主题切换卡片”交互模式
flutter·ui·交互·dart
FuckPatience12 小时前
C# 对象初始化器对属性赋值vs构造函数里对属性赋值
c#