Skip to content
Snippets Groups Projects
Commit c88c37e2 authored by Hanna Johansson's avatar Hanna Johansson
Browse files

adding first rev of game

parent ba4ea378
No related branches found
Tags bugzilla-4.2.5
No related merge requests found
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AttemptAnConsoleApp", "AttemptAnConsoleApp.csproj", "{B6F4D214-EE06-4C16-8AA7-07C56B3C1C31}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B6F4D214-EE06-4C16-8AA7-07C56B3C1C31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6F4D214-EE06-4C16-8AA7-07C56B3C1C31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6F4D214-EE06-4C16-8AA7-07C56B3C1C31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6F4D214-EE06-4C16-8AA7-07C56B3C1C31}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D9A44CFC-1352-400C-A847-4F3F3D8DF9A3}
EndGlobalSection
EndGlobal
using System.Text.RegularExpressions;
using System;
namespace AttemptAnConsoleApp
{
class Program
{
static void Main(string[] args)
{
Random r = new Random();
bool game = true;
Console.WriteLine("Welcome to the game, anytime you want to quit, type 'q'");
while (game)
{
int answer = r.Next(1, 9);
bool cont = true;
while (cont)
{
Console.WriteLine("Guess a number between 1 and 9");
char userInput = Console.ReadKey().KeyChar;
if (!IsValidInput(userInput))
{
continue;
}
if(userInput == 'q')
{
game = false;
break;
}
int IntUserInput = int.Parse(userInput.ToString());
if (IntUserInput == answer)
{
string message = Environment.NewLine + "That is correct!";
Console.WriteLine(message);
cont = false;
}
else
{
string message = Environment.NewLine + "That is not the number I thought of!";
Console.WriteLine(message);
Console.WriteLine("Try again!");
}
}
if (game == false)
{
Console.WriteLine();
break;
}
Console.WriteLine(Environment.NewLine + "Let's play more! Remember you can type q to exit!");
Console.WriteLine();
}
Console.WriteLine("Thanks for playing, exiting...");
}
static bool IsValidInput(char character)
{
Regex ValidInput = new Regex("([1-9]|q)");
Match Inputmatch = ValidInput.Match(character.ToString());
if (Inputmatch.Success)
{
return true;
}
Console.WriteLine();
Console.WriteLine("that is not a valid input, input a number between 1 and 9, or 'q' to quit");
return false;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment