-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
98 lines (86 loc) · 3.85 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
// Every class in the program is defined within the "Quest" namespace
// Classes within the same namespace refer to one another without a "using" statement
namespace Quest
{
class Program
{
static void Main(string[] args) //~ explain and string args
{
// Create a few challenges for our Adventurer's quest
// The "Challenge" Constructor takes three arguments
// the text of the challenge
// a correct answer
// a number of awesome points to gain or lose depending on the success of the challenge
Challenge twoPlusTwo = new Challenge("2 + 2?", 4, 10);
Challenge theAnswer = new Challenge(
"What's the answer to life, the universe and everything?", 42, 25);
Challenge whatSecond = new Challenge(
"What is the current second?", DateTime.Now.Second, 50);
int randomNumber = new Random().Next() % 10;
Challenge guessRandom = new Challenge("What number am I thinking of?", randomNumber, 25);
Challenge favoriteBeatle = new Challenge(
@"Who's your favorite Beatle?
1) John
2) Paul
3) George
4) Ringo
",
4, 20
);
// "Awesomeness" is like our Adventurer's current "score"
// A higher Awesomeness is better
// Here we set some reasonable min and max values.
// If an Adventurer has an Awesomeness greater than the max, they are truly awesome
// If an Adventurer has an Awesomeness less than the min, they are terrible
bool endGame = false;
while (!endGame)
{
Console.Clear();
int minAwesomeness = 0;
int maxAwesomeness = 100;
// Make a new "Adventurer" object using the "Adventurer" class
Robe adventurerRobe = new Robe()
{
Colors = new List<string> { "peach", "olive green", "cerulean blue", "goldenrod", "indigo", "crimson" },
Length = 42
};
Console.Write("Enter your character's name: ");
Adventurer theAdventurer = new Adventurer(Console.ReadLine());
// A list of challenges for the Adventurer to complete
// Note we can use the List class here because have the line "using System.Collections.Generic;" at the top of the file.
List<Challenge> challenges = new List<Challenge>()
{
twoPlusTwo,
theAnswer,
whatSecond,
guessRandom,
favoriteBeatle
};
// Loop through all the challenges and subject the Adventurer to them
foreach (Challenge challenge in challenges)
{
challenge.RunChallenge(theAdventurer);
}
// This code examines how Awesome the Adventurer is after completing the challenges
// And praises or humiliates them accordingly
if (theAdventurer.Awesomeness >= maxAwesomeness)
{
Console.WriteLine("YOU DID IT! You are truly awesome!");
}
else if (theAdventurer.Awesomeness <= minAwesomeness)
{
Console.WriteLine("Get out of my sight. Your lack of awesomeness offends me!");
}
else
{
Console.WriteLine("I guess you did...ok? ...sorta. Still, you should get out of my sight.");
}
Console.WriteLine();
Console.Write("Play again? Y/N: ");
endGame = Console.ReadLine().ToLower() == "y" ? false : true;
}
}
}
}