initial
This commit is contained in:
commit
8ce1137eb7
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
.vscode/
|
14
HighScore.cs
Normal file
14
HighScore.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Lab1
|
||||||
|
{
|
||||||
|
internal class HighScore
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int Trials { get; set; }
|
||||||
|
}
|
||||||
|
}
|
10
Lab1.csproj
Normal file
10
Lab1.csproj
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
25
Lab1.sln
Normal file
25
Lab1.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.2.32602.215
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab1", "Lab1.csproj", "{32FE7F03-E9ED-411A-9046-4E691EF040BA}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{32FE7F03-E9ED-411A-9046-4E691EF040BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{32FE7F03-E9ED-411A-9046-4E691EF040BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{32FE7F03-E9ED-411A-9046-4E691EF040BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{32FE7F03-E9ED-411A-9046-4E691EF040BA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {326F17E7-2CD2-4C6A-8484-8D0952D2FECE}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
43
Program.cs
Normal file
43
Program.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using Lab1;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
var rand = new Random();
|
||||||
|
var value = rand.Next(1, 100);
|
||||||
|
|
||||||
|
int guess;
|
||||||
|
int trials = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.Write("Wprowadź wartość: ");
|
||||||
|
guess = Convert.ToInt32(Console.ReadLine());
|
||||||
|
|
||||||
|
if (guess > value)
|
||||||
|
Console.WriteLine("Za dużo!");
|
||||||
|
else if (guess < value)
|
||||||
|
Console.WriteLine("Za mało!");
|
||||||
|
|
||||||
|
trials++;
|
||||||
|
}
|
||||||
|
while (guess != value);
|
||||||
|
|
||||||
|
Console.WriteLine($"Wygrana w {trials} próbie!");
|
||||||
|
Console.Write("Podaj swoje imię: ");
|
||||||
|
var name = Console.ReadLine();
|
||||||
|
|
||||||
|
var hs = new HighScore { Name = name, Trials = trials };
|
||||||
|
|
||||||
|
List<HighScore> highScores = null;
|
||||||
|
const string FileName = "highscores.json";
|
||||||
|
if (File.Exists(FileName))
|
||||||
|
highScores = JsonSerializer.Deserialize<List<HighScore>>(File.ReadAllText(FileName));
|
||||||
|
|
||||||
|
if (highScores == null)
|
||||||
|
highScores = new List<HighScore>();
|
||||||
|
|
||||||
|
highScores.Add(hs);
|
||||||
|
File.WriteAllText(FileName, JsonSerializer.Serialize(highScores));
|
||||||
|
|
||||||
|
foreach (var item in highScores.OrderBy(x => x.Trials))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{item.Name} -- {item.Trials} prób");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user