Untitled
unknown
csharp
10 months ago
6.1 kB
19
Indexable
//23120044 - Tran Trung Hieu
//Week01 - Escape Room Challenge
using System.Text;
namespace W1_EscapeRoomChallenge
{
internal class Program
{
static char []answers = { '?', '?', '?' };
/// <summary>
/// Display the final result
/// </summary>
static void displayResult()
{
for(int i =0; i< answers.Length; i++)
{
answers[i] = char.ToLower(answers[i]);
}
Console.WriteLine($"Our contact email is : " +
$"{answers[0]}{answers[1]}{answers[2]}" +
$"[email protected]");
}
/// <summary>
/// Display question and choices
/// </summary>
static void displayMenu()
{
Console.WriteLine("Select an option by entering its number:");
Console.WriteLine("1.Question 1");
Console.WriteLine("2.Question 2");
Console.WriteLine("3.Question 3");
Console.WriteLine("4.Display current result");
Console.WriteLine("5.Exit");
}
/// <summary>
/// Clear the output screen from a specific line
/// </summary>
/// <param name="line"> the starting line to clear </param>
static void ClearFromLine(int line)
{
int totalLines = Console.WindowHeight;
for (int i = line; i < totalLines; i++)
{
Console.SetCursorPosition(0, i);
Console.Write(new string(' ', Console.WindowWidth));
}
// Move cursor back to the starting line
Console.SetCursorPosition(0, line);
}
/// <summary>
/// Interface for different questions
/// </summary>
interface IQuestion
{
string description { get; }
string hint { get; }
void displayQuestion()
{
Console.WriteLine(description + "(press any number to show hint)");
}
void displayHint()
{
ClearFromLine(11);
Console.WriteLine("Hint :"+hint);
}
}
/// <summary>
/// Question 1 contents
/// </summary>
class Question1: IQuestion
{
public string description { get; } = "1. -- ";
public string hint { get; } = "It's Morse Code";
}
/// <summary>
/// Question 2 contents
/// </summary>
class Question2 : IQuestion
{
public string description { get; } = " ((1 << 6) * 2) - (3 * 7) ";
public string hint { get; } = "ASCII";
}
/// <summary>
/// Question 3 contents
/// </summary>
class Question3 : IQuestion
{
public string description { get; } = " Which English word has this pronunciation \"aʊər\" ";
public string hint { get; } = "Think about time";
}
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.Unicode;
//Introduce the program purpose
Console.WriteLine("---Escape Room Challenge---");
Console.WriteLine("---Please answer the three questions below to find out our group contact email---");
int choice = 0; //Varible for choosing options
//Creating question
Question1 q1 = new Question1();
Question2 q2 = new Question2();
Question3 q3 = new Question3();
IQuestion[] questions = { q1, q2, q3 };
displayMenu();
while(choice != 5)
{
Console.WriteLine(); //A line break for seperation
Console.Write("Your choice : ");
string input = Console.ReadLine();
//Try to parse the input into int
if(int.TryParse(input, out choice))
{
//Display out the question based on the choice
switch (choice)
{
case 1: case 2: case 3:
questions[choice-1].displayQuestion();
input = Console.ReadLine();
string answer = "";
int num = 0;
//Check if the user want to get hint or to answer
if (int.TryParse(input, out num))
{
questions[choice-1].displayHint();
answer = Console.ReadLine();
}
else
{
answer = input;
}
Console.WriteLine("Your answer was :" + answer);
if(answer != "")
{
answers[choice-1] = answer[0];
}
break;
case 4:
displayResult();
break;
case 5:
Console.WriteLine("The program will shut down");
return;
default:
break;
}
}
else
{
Console.WriteLine("Invalid input, press Enter to try again.");
Console.ReadKey();
}
Console.Write("Press enter to go back to menu");
Console.ReadKey();
ClearFromLine(8);
}
//Closing off program
Console.WriteLine("Press Enter to exit the program");
}
}
}
Editor is loading...
Leave a Comment