在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → c#窗体应用双色球小游戏(含文档)

c#窗体应用双色球小游戏(含文档)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.05M
  • 下载次数:14
  • 浏览次数:451
  • 发布时间:2019-06-24
  • 实例类别:C#语言基础
  • 发 布 人:1395138548
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 游戏 C# 双色球 窗体

实例介绍

【实例简介】

本次论文研究双色球运行机制,如何灵活的运用数组实现程序可行性。采用C#编程语言模拟双色球系统深入了解

【实例截图】

from clipboard

【核心代码】

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DoubleColorBall
{
    public class Manager
    {
        private char selected;
        private int cnt;//注数
        private int num;//几注
        private int money = 200;
        private int totalMoney = 100000000;
        private Random r = new Random();
        public void Start()
        {
            while (true)
            {
                Console.WriteLine("您的游戏币为:{0}元", money);
                if (money <= 0)
                {
                    Console.WriteLine("游戏币已用完,gameover。");
                    return;
                }
                if (money >= 100000000)
                {
                    Console.WriteLine("胜利,victory。");
                    return;

                }
                List<List<int>> myNums = new List<List<int>>();
                List<int> innerNums;
                SelectWay();
                var color = Console.ForegroundColor;
                if (selected == '1')
                {
                    SelectNum("机选");
                    InputCnt();
                    for (int i = 0; i < this.num; i  )
                    {
                        myNums.Add(RandomNumArray());
                    }

                    Console.WriteLine("您的号码为:         ");
                    for (int j = 0; j < myNums.Count;   j)
                    {
                        Console.Write("号码{0}:   ", j   1);
                        int tmp = 0;
                        foreach (var i in myNums.ElementAt(j))
                        {
                            if (tmp < 6)
                                Console.ForegroundColor = ConsoleColor.Red;
                            else
                                Console.ForegroundColor = ConsoleColor.Blue;
                            Console.Write(i   " ");
                            tmp  ;
                            Console.ForegroundColor = color;
                        }
                        if (j != myNums.Count - 1)
                            Console.WriteLine();
                    }


                }
                else
                {
                    SelectNum("手选");
                    InputCnt();
                    for (int i = 0; i < this.num; i  )
                    {
                        Console.WriteLine("请输入您的第{0}个号码", i   1);
                        myNums.Add(InputSelfNums());
                    }
                    Console.WriteLine("您的号码为:         ");
                    for (int j = 0; j < myNums.Count;   j)
                    {
                        Console.Write("号码{0}:   ", j   1);
                        int tmp = 0;
                        foreach (var i in myNums.ElementAt(j))
                        {
                            if (tmp < 6)
                                Console.ForegroundColor = ConsoleColor.Red;
                            else
                                Console.ForegroundColor = ConsoleColor.Blue;
                            Console.Write(i   " ");
                            tmp  ;
                            Console.ForegroundColor = color;
                        }
                        if (j != myNums.Count - 1)
                            Console.WriteLine();
                    }
                }
                Console.ForegroundColor = color;



                innerNums = RandomNumArray();
                Console.WriteLine();
                Console.Write("开奖号码为:    ");
                int tmpcnt = 0;
                foreach (var i in innerNums)
                {
                    //if (tmpcnt < 6)
                    //{
                    //    if(myNums.Take(6).Contains(i))
                    //    {
                    //        Console.ForegroundColor = ConsoleColor.Green;
                    //    }
                    //    else
                    //    {
                    //        Console.ForegroundColor = color;
                    //    }
                    //}
                    //else
                    //{
                    //    if(i == myNums[tmpcnt])
                    //        Console.ForegroundColor = ConsoleColor.Green;
                    //    else
                    //    {
                    //        Console.ForegroundColor = color;
                    //    }
                    //}
                    Console.Write(i   " ");
                    tmpcnt  ;
                }
                Console.ForegroundColor = color;
                int redSame = 0;
                int blueSame = 0;
                Console.WriteLine();
                for (int i = 0; i < myNums.Count;   i)
                {
                    Console.Write("号码{0}:   ", i   1);
                    List<int> goodNums = CompareNums(myNums.ElementAt(i), innerNums, ref redSame, ref blueSame);
                    this.IsWhich(redSame, blueSame, goodNums);
                }

                Console.WriteLine("1 继续   2 退出");
                char conti;
                while (true)
                {
                    var key = Console.ReadKey(true);
                    conti = key.KeyChar;
                    if (conti == '1' || conti == '2')
                    {
                        break;
                    }
                    Console.Clear();
                    Console.WriteLine("请正确选择");
                    Console.WriteLine("1 继续   2 退出");
                }
                if (conti == '2')
                    break;
                Console.Clear();
            }
        }
        private void SelectWay()
        {
            Console.Write("请问您要机选还是手选?\n");
            Console.WriteLine("1. 机选  2. 手选");
            while (true)
            {
                var key = Console.ReadKey(true);
                selected = key.KeyChar;
                if (selected == '1' || selected == '2')
                {
                    break;
                }
                Console.WriteLine("请正确选择");
            }
        }
        //选几注
        private void SelectNum(string name)
        {
            Console.Write("请问您要");
            Console.WriteLine("{0}几注?", name);
            while (true)
            {
                string tmp = Console.ReadLine();
                if (int.TryParse(tmp, out num))
                {
                    break;
                }
                Console.WriteLine("请正确输入");
            }
        }
        //输入下注注数
        private void InputCnt()
        {
            Console.WriteLine("请问您要投多少注?最高99注");
            while (true)
            {
                string str = Console.ReadLine();
                if (int.TryParse(str, out cnt))
                {
                    if (cnt < 100)
                    {
                        if (cnt * 2 * num <= money)
                        {
                            money -= cnt * 2 * num;
                            break;
                        }
                        else
                        {
                            Console.WriteLine("游戏币不足,请重新输入");
                            continue;
                        }

                    }
                    Console.WriteLine("最高注数为99注,请重新输入");
                }
            }
        }
        //随机产生
        private List<int> RandomNumArray()
        {
            //System.Random r = new Random();
            List<int> numList = new List<int>();
            while (numList.Count < 6)
            {
                int i = r.Next(1, 34);
                if (!numList.Contains(i))
                {
                    numList.Add(i);
                }
            }
            while (true)
            {
                int i = r.Next(1, 17);
                //if(!numList.Contains(i))
                //{
                numList.Add(i);
                break;
                //}
            }
            return numList;

        }
        private List<int> InputSelfNums()
        {
            List<int> myNums = new List<int>();
            while (true)
            {
                myNums.Clear();
                Console.WriteLine("请输入您的号码,每个号码间以空格键分离,前六个号码为1~33,最后一个号码为1~16, 前六个号码不能重复:");
                string str = Console.ReadLine();
                string[] arr = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (arr.Count() != 7)
                {
                    Console.WriteLine("请输入您的七个号码");
                    continue;
                }
                for (int i = 0; i < 7;   i)
                {
                    int tmp = int.Parse(arr[i]);
                    if (i < 6)
                    {
                        if (tmp >= 1 && tmp <= 33)
                        {
                            if (!myNums.Contains(tmp))
                            {
                                myNums.Add(tmp);
                            }
                        }

                    }
                    else
                    {
                        if (tmp >= 1 && tmp <= 16)
                        {
                            //if (!myNums.Contains(tmp))
                            //{
                            myNums.Add(tmp);
                            //}
                        }
                    }


                }
                if (myNums.Count == 7)
                    break;
            }
            return myNums;

        }
        private List<int> CompareNums(List<int> myNums, List<int> innerNums, ref int redSame, ref int bluesame)
        {
            List<int> cnt = new List<int>();
            redSame = 0;
            bluesame = 0;


            List<int> tmp = myNums.Take(6).ToList();
            List<int> tmp1 = innerNums.Take(6).ToList();
            //myNums.Remove(myNums[6]);
            //innerNums.Remove(innerNums[6]);
            for (int i = 0; i < 6; i  )
            {
                if (tmp1.Contains(tmp.ElementAt(i)))
                {

                    cnt.Add(tmp.ElementAt(i));
                    redSame  ;
                }
            }
            if (myNums[6] == innerNums[6])
            {
                bluesame  ;
                if (!cnt.Contains(myNums[6]))
                    cnt.Add(myNums[6]);
            }

            return cnt;
        }
        public void IsWhich(int redSame, int blueSame, List<int> goodNums)
        {
            string str = "";
            foreach (var item in goodNums)
            {
                str  = item.ToString()   " ";
            }
            if (redSame   blueSame == 7)
            {
                Console.Write("恭喜您获得一等奖,奖金{0}万元,", 1000 * cnt);
                Console.Write("中奖号码为:");
                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(str);
                Console.ForegroundColor = color;
                totalMoney -= 10000000 * cnt;
                money  = 10000000 * cnt;
            }
            else if (redSame == 6)
            {
                Console.Write("恭喜您获得二等奖,奖金{0}万元,", 500 * cnt);
                Console.Write("中奖号码为:");
                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(str);
                Console.ForegroundColor = color;
                totalMoney -= 5000000 * cnt;
                money  = 5000000 * cnt;
            }
            else if (redSame == 5 && blueSame == 1)
            {
                Console.Write("恭喜您获得三等奖,奖金{0}元,", 3000 * cnt);
                Console.Write("中奖号码为:");
                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(str);
                Console.ForegroundColor = color;
                totalMoney -= 3000 * cnt;
                money  = 3000 * cnt;
            }
            else if (redSame == 5 || (redSame == 4 && blueSame == 1))
            {
                Console.Write("恭喜您获得四等奖,奖金{0}元,", 200 * cnt);
                Console.Write("中奖号码为:");
                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(str);
                Console.ForegroundColor = color;
                totalMoney -= 200 * cnt;
                money  = 200 * cnt;
            }
            else if (redSame == 4 || (redSame == 3 && blueSame == 1))
            {
                Console.Write("恭喜您获得五等奖,奖金{0}元,", 10 * cnt);
                Console.Write("中奖号码为:");
                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(str);
                Console.ForegroundColor = color;

                totalMoney -= 10 * cnt;
                money  = 10 * cnt;
            }
            else if (blueSame == 1)
            {
                str = goodNums.ElementAt(goodNums.Count - 1).ToString();
                Console.Write("恭喜您获得六等奖,奖金{0}元,", 5 * cnt);
                Console.Write("中奖号码为:");
                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(str);
                Console.ForegroundColor = color;
                totalMoney -= 5 * cnt;
                money  = 5 * cnt;
            }
            else
            {
                Console.WriteLine("很遗憾您没有中奖!");
            }
        }
    }
}

实例下载地址

c#窗体应用双色球小游戏(含文档)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警