forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKernel.cs
66 lines (53 loc) · 1.61 KB
/
Kernel.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
using System;
using Sys = Cosmos.System;
namespace Guess
{
public class GuessOS : Sys.Kernel
{
private Random mRandom;
private int mCount;
private int mNumber;
protected override void BeforeRun()
{
mRandom = new Random();
mCount = 0;
mNumber = mRandom.Next(1, 101);
Console.Clear();
Console.WriteLine("Guess Demo");
Console.WriteLine("----------");
Console.WriteLine();
Console.WriteLine("Please guess a number from 1 to 100.");
Console.WriteLine();
}
protected override void Run()
{
mCount++;
Console.Write($"Guess #{mCount}: ");
var xGuess = Int32.Parse(Console.ReadLine());
mDebugger.Send($"Guess#{mCount}: {xGuess}");
if (xGuess < mNumber)
{
Console.WriteLine("Too low.");
}
else if (xGuess > mNumber)
{
Console.WriteLine("Too high.");
}
else
{
Console.WriteLine("You guessed it!");
Console.WriteLine("Press s to stop or any other key to play again. Thanks for playing!");
if (Console.ReadKey(true).Key == ConsoleKey.S)
{
Stop();
}
mNumber = mRandom.Next(1, 100);
mCount = 0;
}
}
protected override void AfterRun()
{
Sys.Power.Shutdown();
}
}
}