mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 04:18:43 +00:00
Guess demo improvements.
This commit is contained in:
parent
8bed32957e
commit
7befa1eb3c
2 changed files with 40 additions and 33 deletions
|
|
@ -1,8 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
//using Cosmos.Debug.Kernel;
|
||||
|
||||
using Cosmos.Debug.Kernel;
|
||||
using Sys = Cosmos.System;
|
||||
|
||||
/*
|
||||
|
|
@ -13,55 +11,61 @@ namespace Guess
|
|||
{
|
||||
public class GuessOS : Sys.Kernel
|
||||
{
|
||||
protected int mCount = 0;
|
||||
|
||||
protected int mMagicNo = 22;
|
||||
|
||||
public GuessOS()
|
||||
{
|
||||
// Didnt check if tickcount is working yet.. can change this later
|
||||
//var xRandom = new Random(234243534);
|
||||
//mMagicNo = xRandom.Next(1, 100);
|
||||
}
|
||||
|
||||
private Random mRandom;
|
||||
private int mCount;
|
||||
private int mNumber;
|
||||
|
||||
protected override void BeforeRun()
|
||||
{
|
||||
//Cosmos.Core.HMI.Init();
|
||||
mRandom = new Random();
|
||||
|
||||
mCount = 0;
|
||||
mNumber = mRandom.Next(1, 100);
|
||||
|
||||
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}");
|
||||
|
||||
//mDebugger.Send("");
|
||||
//mDebugger.SendMessage("Kernel", "New iteration");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Guess #" + mCount);
|
||||
Console.Write("Please enter a guess: ");
|
||||
string xInputStr = Console.ReadLine();
|
||||
Console.Write("Input length: ");
|
||||
Console.WriteLine(xInputStr.Length.ToString());
|
||||
int xGuess = int.Parse(xInputStr);
|
||||
Console.WriteLine("Your guess was " + xGuess);
|
||||
if (xGuess < mMagicNo)
|
||||
if (xGuess < mNumber)
|
||||
{
|
||||
Console.WriteLine("Too low.");
|
||||
}
|
||||
else if (xGuess > mMagicNo)
|
||||
else if (xGuess > mNumber)
|
||||
{
|
||||
Console.WriteLine("Too high.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("You guessed it!");
|
||||
Console.WriteLine("Press any key to end Guess Demo. Thanks for playing!");
|
||||
Console.ReadKey();
|
||||
Stop();
|
||||
Console.WriteLine("Press s to stop or any other key to play again. Thanks for playing!");
|
||||
|
||||
if (Console.ReadKey().Key == ConsoleKey.S)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
mNumber = mRandom.Next(1, 100);
|
||||
mCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void AfterRun()
|
||||
{
|
||||
Sys.Power.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using Cosmos.HAL;
|
|||
namespace Cosmos.System_Plugs.System
|
||||
{
|
||||
[Plug(Target = typeof(Random))]
|
||||
public class RandomImpl
|
||||
public static class RandomImpl
|
||||
{
|
||||
public static void Ctor(Random aThis)
|
||||
{
|
||||
|
|
@ -17,6 +17,9 @@ namespace Cosmos.System_Plugs.System
|
|||
//empty ATM
|
||||
}
|
||||
|
||||
// TODO: improve this
|
||||
public static int GenerateGlobalSeed() => RTC.Second;
|
||||
|
||||
public static int Next(Random aThis, int maxValue)
|
||||
{
|
||||
return (int)(GetUniform() * maxValue);
|
||||
|
|
@ -60,4 +63,4 @@ namespace Cosmos.System_Plugs.System
|
|||
return uniform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue