我正在尝试创建一个简单的多项选择测验游戏,该游戏计算一个人的分数并在最后向他们展示。
问题是我的教授给了我们一个可选功能来添加,我不知道如何编码。他希望程序在游戏结束时显示前 5 名的最高分数,经过大量搜索,由于我缺乏编程经验,我无法弄清楚。
这是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TeamYeahGame
{
class Program
{
static void Main(string[] args)
{
Beginning:
string username;
int YourScore = 0;
Console.SetWindowSize(75, 50);
Console.ForegroundColor = ConsoleColor.Yellow;//yellow's pretty good aesthetically and functionally
Console.WriteLine(" ___________________________________________________ ");
Console.WriteLine(" | | ");
Console.WriteLine(" | Salutations! Brave hero of the class! | ");// "/" cannot be used for some reason in writelines
Console.WriteLine(" | Welcome to the legendary quiz | ");
Console.WriteLine(" | of IntrDev class TCOB2! | ");
Console.WriteLine(" | | ");
Console.WriteLine(" |___________________________________________________| ");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("First, you must enter your name.");
username = Console.ReadLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Good day, " + username + ", the following quiz will test your knowledge of"); // leave spaces for sentences between concatenated data
Console.WriteLine("close strangers, goodluck.");
Console.WriteLine();
Console.ReadLine();
Console.Clear(); //Clears the current screen, needs action such as "readline" so it won't supercede writelines
Console.WriteLine("Quiz Time!");
Console.WriteLine("Question 1: What is Frederick Bunao's favorite hobby?");
Console.WriteLine("a) Writing");
Console.WriteLine("b) Reading");
Console.WriteLine("c) Gaming");
Console.WriteLine("d) Sports");
Console.WriteLine();
string answer1 = "C";
string usersAnswer1;
Console.Write("Answer: ");
usersAnswer1 = Console.ReadLine();
if (usersAnswer1 == answer1)
YourScore++;
if (usersAnswer1 == answer1)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("What is Frederick Bunao's second favorite hobby?");
Console.WriteLine("a) Writing");
Console.WriteLine("b) Reading");
Console.WriteLine("c) Gaming");
Console.WriteLine("d) Sports");
string answer2 = "A";
string usersAnswer2;
Console.Write("Answer: ");
usersAnswer2 = Console.ReadLine();
if (usersAnswer2 == answer2)
YourScore++;
if (usersAnswer2 == answer2)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("Which weapon would Frederick Bunao choose?");
Console.WriteLine("a) Sword");
Console.WriteLine("b) Dagger");
Console.WriteLine("c) Staff");
Console.WriteLine("d) Rocket Launcher");
string answer3 = "C";
string usersAnswer3;
Console.Write("Answer: ");
usersAnswer3 = Console.ReadLine();
if (usersAnswer3 == answer3)
YourScore++;
if (usersAnswer3 == answer3)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("Who is Frederick Bunao's favorite writer?");
Console.WriteLine("a) Stephen King");
Console.WriteLine("b) Stephenie Meyer");
Console.WriteLine("c) Mark Twain");
Console.WriteLine("d) Edgar Allan Poe");
string answer4 = "D";
string usersAnswer4;
Console.Write("Answer: ");
usersAnswer4 = Console.ReadLine();
if (usersAnswer4 == answer4)
YourScore++;
if (usersAnswer4 == answer4)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("What is Frederick Bunao's favorite game?");
Console.WriteLine("a) FPS");
Console.WriteLine("b) TPS");
Console.WriteLine("c) RPG");
Console.WriteLine("d) RTS");
string answer5 = "C";
string usersAnswer5;
Console.Write("Answer: ");
usersAnswer5 = Console.ReadLine();
if (usersAnswer5 == answer5)
YourScore++;
if (usersAnswer5 == answer5)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("What is Lloyd Abella's favorite color?");
Console.WriteLine("a) Blue");
Console.WriteLine("b) Red");
Console.WriteLine("c) Green");
Console.WriteLine("d) Orange");
string answer6 = "B";
string usersAnswer6;
Console.Write("Answer: ");
usersAnswer6 = Console.ReadLine();
if (usersAnswer6 == answer6)
YourScore++;
if (usersAnswer6 == answer6)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("What is Lloyd Abella's favorite number?");
Console.WriteLine("a) 1");
Console.WriteLine("b) 3");
Console.WriteLine("c) 18");
Console.WriteLine("d) 20");
string answer7 = "C";
string usersAnswer7;
Console.Write("Answer: ");
usersAnswer7 = Console.ReadLine();
if (usersAnswer7 == answer7)
YourScore++;
if (usersAnswer7 == answer7)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("What is Lloyd Abella's favorite hobby?");
Console.WriteLine("a) Basketball");
Console.WriteLine("b) Table Tennis");
Console.WriteLine("c) Volleyball");
Console.WriteLine("d) Badminton");
string answer8 = "A";
string usersAnswer8;
Console.Write("Answer: ");
usersAnswer8 = Console.ReadLine();
if (usersAnswer8 == answer8)
YourScore++;
if (usersAnswer8 == answer8)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("Who is Lloyd Abella's favorite celebrity?");
Console.WriteLine("a) Jake Cuenca");
Console.WriteLine("b) Coco Martin");
Console.WriteLine("c) John Lloyd");
Console.WriteLine("d) Gabriel Gaerlan");
string answer9 = "C";
string usersAnswer9;
Console.Write("Answer: ");
usersAnswer9 = Console.ReadLine();
if (usersAnswer9 == answer9)
YourScore++;
if (usersAnswer9 == answer9)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("How old is Lloyd Abella?");
Console.WriteLine("a) 16");
Console.WriteLine("b) 17");
Console.WriteLine("c) 15");
Console.WriteLine("d) 12");
string answer10 = "B";
string usersAnswer10;
Console.Write("Answer: ");
usersAnswer10 = Console.ReadLine();
if (usersAnswer10 == answer10)
YourScore++;
if (usersAnswer10 == answer10)
Console.Beep(2500, 200);
else Console.Beep(500, 800);
Console.Clear();
Console.WriteLine("Your score is being calculated. Please type any key to continue...");
Console.ReadLine();
Console.Clear();
if (YourScore == 10)
Console.WriteLine("Congratulations! You got a perfect score of 10!");
else if (YourScore == 9 || YourScore == 8 || YourScore == 7)
Console.Write("Great Job!! You got a " + YourScore + "!!");
else if (YourScore == 6 || YourScore == 5)
Console.Write("You got a " + YourScore + ", kinda good I guess");
else if (YourScore < 5)
Console.Write("Your score is... " + YourScore + " unfortunately, you failed the quiz");
Console.WriteLine();
string usersChoice;
string answer = "Y";
Console.WriteLine("Would you like to play again? (Y/N)");
usersChoice = Console.ReadLine();
Console.Clear();
if (usersChoice == answer) //use this type of if statement for Y/N stuff
{
goto Beginning;
}
Console.ReadKey();
}
}
}