您好我正在制作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.");
}
}
答案 0 :(得分:2)
我不会为你做这项工作,所以这些都是伪造的代码,但它应该引导你找到正确的道路。
您不希望尝试将相关数据保存在两个不同的位置。这是使用课程的最佳时机。想象一下,如果你有一个包含单个轮盘赌轮实例的所有属性的对象。
这样的事情:
class RouletteInstance
{
//an integer representing the number
//an enum representing the color
}
然后你在轮盘赌轮上收集了所有可能的实例:
Collection<RouletteInstance> instances
然后你可以通过从集合中随机选择一个实例来“旋转”。
从那里,您将根据用户输入检查随机选择的实例,以查看它是否匹配。
,请注意轮盘赌轮超过two colors ...