Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaRi0ooo committed Jun 23, 2022
1 parent 419cabf commit 495aaaa
Show file tree
Hide file tree
Showing 9 changed files with 814 additions and 0 deletions.
25 changes: 25 additions & 0 deletions SuperQuiz.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32407.343
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperQuiz", "SuperQuiz\SuperQuiz.csproj", "{4124B805-25B9-453B-809C-D98BA98EEC49}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4124B805-25B9-453B-809C-D98BA98EEC49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4124B805-25B9-453B-809C-D98BA98EEC49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4124B805-25B9-453B-809C-D98BA98EEC49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4124B805-25B9-453B-809C-D98BA98EEC49}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B4A6423A-C164-48E0-8803-23E09C601F13}
EndGlobalSection
EndGlobal
79 changes: 79 additions & 0 deletions SuperQuiz/Common/Account/Authorization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using SuperQuiz.Common.Account;
using Console = Colorful.Console;
using System.Drawing;
using Colorful;

namespace SuperQuiz.Common.Account
{
public class Authorization
{
public void Logistry()
{
Console.Clear();
Menu menu = new();
User user = new();
List<User> users = new();
StyleSheet styleSheet = new(Color.LightGray);

String? point = "point.txt",
path = point.Replace("point.txt", "Users");
bool passwordWrong = false;

DirectoryInfo dict = new(path);
var Files = dict.GetFiles();
foreach (var file in Files)
{
FileStream fso = new(file.FullName, FileMode.Open);
users.Add(JsonSerializer.Deserialize<User>(fso)!);
fso.Close();
}

Console.WriteLine("\n\n\t\t\t\t\t ------------| SIGN IN |------------");
Console.Write("\n\t\t\t\t\t\t Login: ");
String? tempLogin = Console.ReadLine();

foreach (var item in users) {
if (tempLogin == item.Login) { user = item; }
}
if (user.Password.Length == 0)
{
Console.Clear();
styleSheet.AddStyle("SIGN IN", Color.Red);
String? loginError = "\n\n\t\t\t\t\t ------------| SIGN IN |------------";
Console.WriteLineStyled(loginError, styleSheet);
Console.WriteLine("\n\t\t\t\t\t\t Login not exist!", Color.Red);

Console.ReadKey();
Logistry();
}

Console.Write("\t\t\t\t\t\t Password: ");
String? tempPassword = Console.ReadLine();

if (tempPassword == user.Password) { menu.MainMenu(user); }
else { passwordWrong = true; }
while (passwordWrong != false)
{
Console.Clear();
styleSheet.AddStyle("SIGN IN", Color.Red);
String? loginError = "\n\n\t\t\t\t\t ------------| SIGN IN |------------";
Console.WriteLineStyled(loginError, styleSheet);
Console.WriteLine("\n\t\t\t\t\t\t Wrong password!", Color.Red);
Console.WriteLine("\n\t\t\t\t\t\t [1] - Try Again");
Console.WriteLine("\t\t\t\t\t\t [2] - Go to start screen");
Console.WriteLine("\n\t\t\t\t\t -----------------------------------");
Console.Write("\t\t\t\t\t Enter: ");

String? choice = Console.ReadLine();
if (choice == "1") { passwordWrong = false; Logistry(); }
else if (choice == "2") { passwordWrong = false; menu.StartMenu(); }
}
}
}
}
74 changes: 74 additions & 0 deletions SuperQuiz/Common/Account/Registration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using SuperQuiz.Common;
using SuperQuiz.Common.Account;
using Colorful;
using Console = Colorful.Console;
using System.Drawing;

namespace SuperQuiz.Common.Account
{
public class Registration
{
public void Registry()
{
Console.Clear();
User user = new();
Menu menu = new();
List<User> users = new();
StyleSheet styleSheet = new(Color.LightGray);

String? point = "point.txt",
path = point.Replace("point.txt", "Users");
bool loginExistCheck = false;

DirectoryInfo dict = new(path);
var Files = dict.GetFiles();
foreach (var file in Files)
{
FileStream fso = new(file.FullName, FileMode.Open);
users.Add(JsonSerializer.Deserialize<User>(fso)!); fso.Close();
}

Console.WriteLine("\n\n\t\t\t\t\t ------------| SIGN UP |------------");
Console.Write("\n\t\t\t\t\t\t Login: ");
String? tempLogin = Console.ReadLine()!;

if (tempLogin.Length == 0) { tempLogin = Console.ReadLine(); }
foreach (var i in users) { if (tempLogin == i.Login) { loginExistCheck = true; } }

while (loginExistCheck != false)
{
Console.Clear();
styleSheet.AddStyle("SIGN UP", Color.Red);
String? loginError = "\n\n\t\t\t\t\t ------------| SIGN UP |------------";
Console.WriteLineStyled(loginError, styleSheet);
Console.WriteLine("\n\t\t\t\t\t\t Such user already exists!", Color.Red);
Console.WriteLine("\n\t\t\t\t\t\t [1] - Try Again");
Console.WriteLine("\t\t\t\t\t\t [2] - Go to start screen");
Console.WriteLine("\n\t\t\t\t\t -----------------------------------");
Console.Write("\t\t\t\t\t Enter: ");

String? choice = Console.ReadLine();
if (choice == "1") { loginExistCheck = false; Registry(); }
else if (choice == "2") { loginExistCheck = false; menu.StartMenu(); }
}
user.Login = tempLogin!;

Console.Write("Write your password: "); user.Password = Console.ReadLine()!;
if (user.Password.Length == 0) { user.Password = Console.ReadLine()!; }

Console.Write("Write your birthday DD.MM.YYYY: "); user.Date = Console.ReadLine()!;
if (user.Date.Length == 0) { user.Date = Console.ReadLine()!; }

FileStream fs = new($"{path}\\{user.Login}.json", FileMode.Create);
JsonSerializer.Serialize(fs, user, new JsonSerializerOptions { WriteIndented = true }); fs.Close();

menu.MainMenu(user);
}
}
}
28 changes: 28 additions & 0 deletions SuperQuiz/Common/Account/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuperQuiz.Common.Account
{
public class User
{
public string Login { get; set; } = "";
public string Password { get; set; } = "";
public string Date { get; set; } = "";

public List<String> quizHistory { get; set; } = new();
public void ShowQuizHistory()
{
if (quizHistory.Count == 0) { Console.WriteLine("You doesn't complete any quiz yet!"); }
else
{
foreach (var quiz in quizHistory) {
Console.WriteLine($"\t\t\t\t\t\t {quiz}");
}
}
}
public override string ToString() { return $"Login: {Login}\nPassword: {Password}\nDate: {Date}"; }
}
}
72 changes: 72 additions & 0 deletions SuperQuiz/Common/Game/Question.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuperQuiz.Common.Game
{
public class Question
{
public string Quest { get; set; } = "";
public List<String> Answers { get; set; } = new();
public List<String> RightAnswers { get; set; } = new();

public void Set()
{
Console.Write("\n\t\t\t\t\t\tQuestion: ");
Quest = Console.ReadLine()!;
if (Quest.Length == 0) { Quest = Console.ReadLine()!; }

Console.Clear();
Console.WriteLine("\n\n\t\t\t\t\t ------------| SET QUESTION |------------");
Console.WriteLine("\n\t\t\t\t\t When you're done, write \"end\" for quit");
Console.WriteLine("\t\t\t\t\t\t Write answer for question");
bool EXT = true;
while (EXT != false)
{
Console.Write("\n\t\t\t\t\t Enter: ");
String? stop = Console.ReadLine()!;
if (stop == "end") { EXT = false; }
else { Answers.Add(stop); }
for (int i = 0; i < Answers.Count; i++) {
Console.WriteLine($"\t\t\t\t\t [{i}] {Answers[i]}");
}
}

Console.Clear();
Console.WriteLine("\n\n\t\t\t\t\t ------------| SET ANSWER |------------");
Console.WriteLine("\n\t\t\t\t\t When you're done, write \"end\" for quit");
Console.WriteLine("\t\t\t\t\tChoose number of answer for question");
EXT = true;
while (EXT != false)
{
for (int i = 0; i < Answers.Count; i++) {
Console.Write($"\n\t\t\t\t\t [{i}] {Answers[i]}");
}
Console.Write("\n\t\t\t\t\tEnter: ");
String? stop = Console.ReadLine()!;
if (stop == "end") { EXT = false; }
else { RightAnswers.Add(stop); }

for (int i = 0; i < RightAnswers.Count; i++) {
Console.Write(Answers[int.Parse(RightAnswers[i])]);
}
}
}
public override string ToString()
{
String? str = $"Question: {Quest}\n";
for (int i = 0; i < Answers.Count; i++)
{
str += $"[{i}] {Answers[i]}";
for (int j = 0; j < RightAnswers.Count; j++)
{
if (i == int.Parse(RightAnswers[j])) { str += " +"; }
}
str += '\n';
}
return str;
}
}
}
Loading

0 comments on commit 495aaaa

Please sign in to comment.