Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
NumberQuestionGame
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hanna Johansson
NumberQuestionGame
Commits
c88c37e2
Commit
c88c37e2
authored
3 years ago
by
Hanna Johansson
Browse files
Options
Downloads
Patches
Plain Diff
adding first rev of game
parent
ba4ea378
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
AttemptAnConsoleApp.csproj
+8
-0
8 additions, 0 deletions
AttemptAnConsoleApp.csproj
AttemptAnConsoleApp.sln
+25
-0
25 additions, 0 deletions
AttemptAnConsoleApp.sln
Program.cs
+73
-0
73 additions, 0 deletions
Program.cs
with
106 additions
and
0 deletions
AttemptAnConsoleApp.csproj
0 → 100644
+
8
−
0
View file @
c88c37e2
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>
This diff is collapsed.
Click to expand it.
AttemptAnConsoleApp.sln
0 → 100644
+
25
−
0
View file @
c88c37e2
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
This diff is collapsed.
Click to expand it.
Program.cs
0 → 100644
+
73
−
0
View file @
c88c37e2
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
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment