代码没提示有错误,点调试什么也没有,一个比较扑克牌大小的程序

问题描述

代码没提示有错误,点调试什么也没有,一个比较扑克牌大小的程序
  public class Poker
    {
        public string Suit { get; set; }
        public string Value { get; set; }
        public  Poker()
        {
            int m;
            Random r1 = new Random();
            m = r1.Next(1, 5);
            int n;
            Random r2 = new Random();
            n = r2.Next(1, 14);
            if (m == 1)
                Suit = "黑桃";
            else if (m == 2)
                Suit = "红桃";
            else if (m == 3)
                Suit = "方块";
            else
                Suit = "梅花";
            if (n == 1)
                Value = "A";
            if (n == 2)
                Value = "2";
            if (n == 3)
                Value = "3";
            if (n == 4)
                Value = "4";
            if (n == 5)
                Value = "5";
            if (n == 6)
                Value = "6";
            if (n == 7)
                Value = "7";
            if (n == 8)
                Value = "8";
            if (n == 9)
                Value = "9";
            if (n == 10)
                Value = "10";
            if (n == 11)
                Value = "J";
            if (n == 12)
                Value = "Q";
            else
                Value = "K";
        }
    }
 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;

        }
        public int GetValue(Poker ob)
        {
            if (ob.Value.Equals("A"))
                return 1;
            else if (ob.Value.Equals("2"))
                return 2;
            else if (ob.Value.Equals("3"))
                return 3;
            else if (ob.Value.Equals("4"))
                return 4;
            else if (ob.Value.Equals("5"))
                return 5;
            else if (ob.Value.Equals("6"))
                return 6;
            else if (ob.Value.Equals("7"))
                return 7;
            else if (ob.Value.Equals("8"))
                return 8;
            else if (ob.Value.Equals("9"))
                return 9;
            else if (ob.Value.Equals("10"))
                return 10;
            else if (ob.Value.Equals("J"))
                return 11;
            else if (ob.Value.Equals("Q"))
                return 12;
            else
                return 13;
        }//方法:获取牌的大小

        public static Poker[] Shuffle()
        {
            Poker[] pokers = new Poker[52];
            for (int i = 0; i < 52; i++)
            {
                pokers[i] = new Poker();
                    for (int u = 0; u < i; u++)
                    {
                        while (pokers[u].Suit.Equals(pokers[i].Suit) == true && pokers[u].Value.Equals(pokers[i].Value) == true)
                        {
                            pokers[i] = null;
                            pokers[i] = new Poker();
                            u = 0;
                            continue;
                        }
                    }
            }
            return pokers;
        }//方法:洗牌,生成一副牌

        Poker[] pokers = Shuffle();
        int click1_time = 1;
        Poker[] gamerpoker = new Poker[26];
        Poker[] AIpoker = new Poker[26];

        private void button1_Click(object sender, EventArgs e)
        {
            if (click1_time == 26)
                MessageBox.Show("没有牌了!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            if (click1_time < 26)
            {
                listBox1.Items.Add("???");
                AIpoker[click1_time] = pokers[2 * click1_time - 2];
                gamerpoker[click1_time] = pokers[2 * click1_time-1];
                listBox2.Items.Add(gamerpoker[click1_time-1].Suit + gamerpoker[click1_time-1].Value);
                click1_time++;
            }
        }//按顺序摸牌
        int click2_time = 0;
        int AIpoint = 0;
        int gamerpoint = 0;
        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.SelectedIndex = click2_time;
            listBox2.SelectedIndex = click2_time;
            listBox1.Items[click2_time] = AIpoker[click2_time].Suit + AIpoker[click2_time].Value;

            if (GetValue(AIpoker[click2_time]) > GetValue(gamerpoker[click2_time]))
            {
                AIpoint += 1;
                label5.Text = "电脑+1";
                label3.Text += "{0},AIpoint";
            }
            if (GetValue(AIpoker[click2_time]) < GetValue(gamerpoker[click2_time]))
            {
                gamerpoint += 1;
                label5.Text = "玩家+1";
                label4.Text += "{0},gamerpoint";
            }
            click2_time++;
        }//比较大小并计分
    }

解决方案

生成牌的效率太低了,这重复率得多高,运行个几小时可能能初始化完52张牌
 public static Poker[] Shuffle()
        {
            Poker[] pokers = new Poker[52];
            for (int i = 0; i < 52; i++)
            {
                pokers[i] = new Poker();
                    for (int u = 0; u < i; u++)
                    {
                        while (pokers[u].Suit.Equals(pokers[i].Suit) == true && pokers[u].Value.Equals(pokers[i].Value) == true)
                        {
                            pokers[i] = null;
                            pokers[i] = new Poker();
                            u = 0;
                            continue;
                        }
                    }
            }
            return pokers;
        }//方法:洗牌,生成一副牌

改改方法

 class PokerContainer
    {
        private static PokerContainer pc = new PokerContainer();
        private List<string> pokerList = new List<string>();
        private string[] hsArr = new string[] { "黑桃", "红桃", "方块", "梅花" };
        private string[] numArr = new string[] { "A", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
        public static PokerContainer getInstance(){
            return pc;
        }
        public void init()
        {
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j <= 13; j++)
                {
                    pokerList.Add(hsArr[i - 1] + "," + numArr[j]);
                }
            }
        }
        public string[] getOne()
        {
            int m;
            Random r1 = new Random(10);
            m = r1.Next(1, pokerList.Count + 1);
            string[] arr = getInfo(pokerList[m-1]);
            pokerList.RemoveAt(m-1);
            return arr;
        }
        private string[] getInfo(string info)
        {
            string[] arr = info.Split(',');
            return arr;
            //Suit = arr[0];
            //Value = arr[1];
        }
        public PokerContainer()
        {
            init();
        }
    }

        public class Poker
    {
        public string Suit { get; set; }
        public string Value { get; set; }

        public Poker()
        {
            string[] arr = PokerContainer.getInstance().getOne();
            Suit = arr[0];
            Value = arr[1];
        }
    }

        最后去掉while比较
        public static Poker[] Shuffle()
        {
            Poker[] pokers = new Poker[52];
            for (int i = 0; i < 52; i++)
            {
                pokers[i] = new Poker();
            }
            return pokers;
        }//方法:洗牌,生成一副牌

解决方案二:

时间: 2024-09-19 08:18:17

代码没提示有错误,点调试什么也没有,一个比较扑克牌大小的程序的相关文章

java-为什么有三个警告就一直出不来结果?(下面其他的没提示有错误)

问题描述 为什么有三个警告就一直出不来结果?(下面其他的没提示有错误) 解决方案 有没有在构造方法里写setVisible(true),或在main方法里加上d.setVisible(true) 解决方案二: 这个写了,写在构造方法里面的 解决方案三: jsb构造函数,写在jsb类里面 解决方案四: 警告只是编译器的警告,没有大碍的.frame.setVisible(true); 代码贴图不全,测试不了啊.不介意的话,都贴出来,大家帮忙看看.

myeclipse jsp-在Myeclipse中每一段的这个代码都提示有错误,但是怎么也找不到

问题描述 在Myeclipse中每一段的这个代码都提示有错误,但是怎么也找不到 <td> <input type="text" name="m9" onkeyup="mostsum()" value="<c:choose> <c:when test="${form.m9[count.count-1] eq '0.000' or empty form.m9[count.count-1]}&qu

java遍历文件时提示空指针错误

问题描述 import java.io.*;public class FileList{public static int fileTotalNum = 0; //文件总数public static int directoryNum = 0; //文件夹总数public void FList(File f){String[] s = f.list();fileTotalNum+=s.length;for(int i = 0;i < s.length;i++){File filelist = ne

android linearlayout-android代码没错误提示,无法运行,求帮助!

问题描述 android代码没错误提示,无法运行,求帮助! package com.example.android_5_1; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; public class M

java代码-提示的错误,我自己始终没找到,求大神指导一下

问题描述 提示的错误,我自己始终没找到,求大神指导一下 class SelectSort { public static void SelectSort(int[]arr) { for(x=0;x { for(y=x+1;y { if(arr[x]>arr[y]); { int temp=arr[x]; arr[x]=arr[y]; arr[y]=temp; } } } } public static void Printfa(int[]arr) { for(i=0;i<arr.length;

编译-在VC2010上可以运行,但是改到Qt上就提示这个错误,请问是哪里没设置好吗?

问题描述 在VC2010上可以运行,但是改到Qt上就提示这个错误,请问是哪里没设置好吗? 程序编译时弹出这样的错误::-1: error: LNK1104: 无法打开文件"GCBase_MD_VC100_v2_3.lib",在VC2010上可以运行,但是改到Qt上就提示这个错误,请问是哪里没设置好吗? 解决方案 没用过 QT. QT 与 VS2010 编译时用的 LIB 是一样的吗? 如果是一样的,则是在 QT 中没有正确的设置库的路径,即没有正确的包含库: 如果是不同的,则需要下载

android studio-Android Studio使用真机可以调试,但是使用Genymotion却提示以下错误

问题描述 Android Studio使用真机可以调试,但是使用Genymotion却提示以下错误 03-23 02:25:43.682 1726-1726/? D/dalvikvm: Late-enabling CheckJNI 03-23 02:25:44.182 1726-1726/com.example.chenxuanhe.myapplication W/dalvikvm: VFY: unable to find class referenced in signature (Landr

c++-C++ 为什么同一段代码第一次提示左操作数必须为左值,改过运行之后再改回原来的,就不提示错误了。

问题描述 C++ 为什么同一段代码第一次提示左操作数必须为左值,改过运行之后再改回原来的,就不提示错误了. 选择排序 template void selectSort(T a[],int size) { int i,j,k; T tmp; for(i=0;i<size-1;i++) { k=i; for(j=i+1;j<size;j++) { if(a[j]<a[k]) k=j; } tmp=a[i];a[i]=a[k]; a[k]=tmp; } int main() {...} vs2

c-VS2013C语言代码无语法错误后调试窗口无显示结果的原因

问题描述 VS2013C语言代码无语法错误后调试窗口无显示结果的原因 include include int main() { int a[2],sum; a[1] = 0; a[0] = 35; sum = a[0] + a[1]; printf("%c", sum); return 0; } 解决方案 %c -> %d 在最后加上 getch() getchar() system("pause") 三者之一 解决方案二: 调试的时候,你设置断点了吗,是不是