0

嗨,我正在制作一个 C# 轮盘赌作为大学项目的一部分。我似乎无法使用数组对我的轮盘进行编程以识别红色或黑色。

我使用数组对轮盘赌球进行编码以落在轮盘的数字上,这很好用。我尝试使用相同的概念,但使用两种颜色。这是我到目前为止所做的:

int[] x = {213, 231, 250, 268, 285, 297, 310, 319, 324, 325, 326, 323, 315, 304, 291, 277, 260, 242, 223, 204, 183, 165, 147, 132, 120, 110, 102, 97, 98, 99, 104, 115, 126, 142, 158, 176, 194};
int[] y = {152, 153, 158, 165, 174, 185, 202, 219, 236, 254, 270, 293, 307, 322, 333, 348, 355, 361, 367, 364, 362, 357, 347, 338, 321, 307, 288, 269, 254, 234, 217, 201, 185, 174, 164, 160, 155};
string[] Number = { "0", "32", "15", "19", "4", "21", "2", "25", "17", "34", "6", "27", "13", "36", "11", "30", "8", "23", "10", "5", "24", "16", "33", "1", "20", "14", "31", "9", "22", "18", "29", "7", "28", "12", "35", "3", "26" };

string[] Red = { "32", "19", "21", "25", "34", "27", "36", "30", "23", "5", "16", "1", "14", "9", "18", "7", "12", "3" };
string[] Black = { "15", "4", "2", "17", "6", "13", "11", "8", "10", "24", "33", "20", "31", "22", "29", "28", "35", "26" };        

cboColour.Items.Add("Red");
cboColour.Items.Add("Black");

string guessColour = cboColour.Text;


if (position == ballPos && loopTimes == loopCount)             
{
    tmrRoll.Enabled = false;

    // Arrays (guessing)

    int arraypos = Array.IndexOf(Number, guess);

    int arrayRed = Array.IndexOf(Red, guessColour);
    int arrayBlack = Array.IndexOf(Black, guessColour);

    // Number + colour correct    
    if (ballPos == arraypos && ballPos == arrayBlack || ballPos == arraypos && ballPos == arrayRed)
    {
        MessageBox.Show("You guessed the number and the colour correctly!");
        addEarnings = currentBet * 35 + 10;
        totalGrapes = totalGrapes + addEarnings;              
    }
    // Only colour correct
    else if (ballPos != arraypos && ballPos == arrayBlack || ballPos != arraypos && ballPos == arrayRed)
    {
        MessageBox.Show("You guessed the colour correct!");
        addEarnings = currentBet + 10;
        totalGrapes = totalGrapes + addEarnings;
    }
    // Only Number correct
    if (ballPos == arraypos && ballPos != arrayBlack || ballPos == arraypos && ballPos != arrayRed)
    {
        MessageBox.Show("You guessed only the number correctly!");
        addEarnings = currentBet * 35;
        totalGrapes = totalGrapes + addEarnings;
    }
    // Nothing correct
    else if (ballPos != arraypos && ballPos != arrayEven || ballPos != arraypos && ballPos != arrayOdd)
    {
        MessageBox.Show("You have failed to guess the number or colour correctly.");                 
    }
}
4

1 回答 1

2

我不会为你做这项工作,所以这都是伪代码,但它应该会引导你找到正确的路径。

您不想从事将相关数据保存在两个不同位置的业务。这是使用类的最佳时机。想象一下,如果您有一个包含单个轮盘实例的所有属性的对象。

像这样的东西:

class RouletteInstance
{
    //an integer representing the number

    //an enum representing the color
}

然后你收集了轮盘赌上所有可能的实例:

Collection<RouletteInstance> instances

然后,您可以通过从集合中随机选择一个实例来“旋转”轮子。

从那里您将根据用户输入检查随机选择的实例以查看其是否匹配。

另外,请记住,轮盘赌有两种以上的颜色......

于 2017-05-11T20:45:44.040 回答