add all
This commit is contained in:
15
lab1_PP/HighScore.cs
Normal file
15
lab1_PP/HighScore.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace lab1_PP
|
||||
{
|
||||
internal class HighScore
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Trials { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
66
lab1_PP/Program.cs
Normal file
66
lab1_PP/Program.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
//zadanie 1.3.
|
||||
using lab1_PP;
|
||||
using System.Text.Json;
|
||||
using System.Xml.Linq;
|
||||
|
||||
Console.WriteLine("zadanie 1.3.");
|
||||
for (int i = 1; i <= 100; i++)
|
||||
{
|
||||
if(i%3==0 && i % 5 == 0) { Console.WriteLine("FizzBuzz"); }
|
||||
else if(i%3==0) { Console.WriteLine("Fizz"); }
|
||||
else if(i%5==0) { Console.WriteLine("Buzz"); }
|
||||
else { Console.WriteLine(i); }
|
||||
}
|
||||
|
||||
//zadanie 1.3.
|
||||
Console.WriteLine("zadanie 1.3.");
|
||||
var rand = new Random();
|
||||
var value = rand.Next(1, 101);
|
||||
int guess = 0;
|
||||
bool validInput = false;
|
||||
int trials = 0;
|
||||
while (guess != value)
|
||||
{
|
||||
Console.WriteLine("Wprowadź wartość: ");
|
||||
validInput = int.TryParse(Console.ReadLine(), out guess);
|
||||
if (!validInput)
|
||||
{
|
||||
Console.WriteLine("To nie jest poprawna liczba. Spróbuj ponownie.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (guess > value)
|
||||
{
|
||||
trials++;
|
||||
Console.WriteLine("Za dużo");
|
||||
}
|
||||
else if (guess < value)
|
||||
{
|
||||
trials++;
|
||||
Console.WriteLine("Za mało");
|
||||
}
|
||||
}
|
||||
trials++;
|
||||
Console.WriteLine("Wygrana w "+trials+" probie!");
|
||||
string name;
|
||||
do
|
||||
{
|
||||
Console.WriteLine("Podaj swoje imię:");
|
||||
name = Console.ReadLine();
|
||||
} while (string.IsNullOrWhiteSpace(name));
|
||||
|
||||
//zapisanie do listy i utworzenie pliku jesli nie istnieje
|
||||
List<HighScore> highScores;
|
||||
const string FileName = "highscores.json";
|
||||
if (File.Exists(FileName))
|
||||
highScores = JsonSerializer.Deserialize<List<HighScore>>(File.ReadAllText(FileName));
|
||||
else
|
||||
highScores = new List<HighScore>();
|
||||
|
||||
var hs = new HighScore { Name = name, Trials = trials };
|
||||
highScores.Add(hs);
|
||||
File.WriteAllText(FileName,JsonSerializer.Serialize(highScores));
|
||||
foreach (var item in highScores.OrderBy(h => h.Trials))
|
||||
{
|
||||
Console.WriteLine($"{item.Name} -- {item.Trials} prób");
|
||||
}
|
||||
10
lab1_PP/lab1_PP.csproj
Normal file
10
lab1_PP/lab1_PP.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user