比较阵列位置,但选择不同的位置 [英] Comparing array positions , but choose the diferent ones
问题描述
我正在制作一个谁想成为百万富翁类型的游戏。
所以我有一个问题和答案的数组,其中:
等级[current_level] [x] [0] - 是问题
等级[current_level] [x] [1-4] - 是问题
等级[current_level] [x] [5]是正确答案
我用来比较一个用户选择和正确的用户选择:
string key_pressed = Console.ReadLine()。ToUpper( );
string resp = levels [current_level] [x] [ 5 ]
if (key_pressed.Equals( A ))
{
if (levels [current_level] [x] [ 1 ]。等于(resp))
{ // 正确}
else
{ // INCORRECT}
}
现在我正在尝试制作观众的帮助,我需要相反的:
level [current_level] [x] [ 1 ]。等于(分别)
所以观众的少数人投票给错误答案。
谢谢
string key_pressed = Console.ReadLine()。ToUpper();
switch (key_pressed)
{
case :
case B:
case C:
case D:
if (levels [current_level] [x] [ 5 ] == key_pressed)
{ // 正确
}
其他
{ // INCORRECT
}
break < /跨度>;
case 1 :
break ;
case 2 :
默认:
break ;
}
你不需要这么多支票
I am making a Who wants to be a millionaire type of game.
So I have a array with the questions and answers, where:
levels[current_level][x][0] - is the question
levels[current_level][x][1-4] - are the questions
levels[current_level][x][5] is the correct answer
I use to compare one of users choices to the right one:
string key_pressed = Console.ReadLine().ToUpper();
string resp = levels[current_level][x][5]
if(key_pressed.Equals("A"))
{
if (levels[current_level][x][1].Equals(resp))
{//CORRECT}
else
{//INCORRECT}
}
Now I am trying to make the Audience help, and I need the opposite of:
levels[current_level][x][1].Equals(resp)
So the minority of the "audience" vote for the wrong answers.
Thank you
Why wouldn't you make this simpler by:
string key_pressed = Console.ReadLine().ToUpper(); switch (key_pressed) { case "A": case "B": case "C": case "D": if(levels[current_level][x][5] == key_pressed) {//CORRECT } else {//INCORRECT } break; case "1": break; case "2": default: break; }
you won't have to do so many checks
这篇关于比较阵列位置,但选择不同的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!