Spielablauf umgesetzt
This commit is contained in:
1 parent
749bdb5179
commit
1097ab98fc
29 files changed
+828
-148
No files matched your search
@@ -0,0 +1,55 @@
|
||||
using FWLAZ_Web.Data;
|
||||
using Blazored.LocalStorage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace FWLAZ_Web.Objects
|
||||
{
|
||||
public class GameState
|
||||
{
|
||||
public enum QuizMode
|
||||
{
|
||||
Practice,
|
||||
Tournament
|
||||
}
|
||||
|
||||
public const string STORAGEKEY = "QuizSetting";
|
||||
public QuizMode Mode { get; set; } = QuizMode.Practice;
|
||||
|
||||
public int QuizId { get; }
|
||||
public bool QuizIsMultipleChoice { get; set; }
|
||||
public string? Title { get; set; } = null!;
|
||||
|
||||
|
||||
public string? Username { get; set; }
|
||||
public List<Question>? Questions { get; set; }
|
||||
|
||||
public List<QuestionAnswer>? QuestionAnswers { get; set; }
|
||||
public Question? CurrentQuestion
|
||||
{
|
||||
get
|
||||
{
|
||||
return Questions?.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public GameState() { }
|
||||
|
||||
public GameState(Quiz quiz)
|
||||
{
|
||||
QuizId = quiz.Id;
|
||||
QuizIsMultipleChoice = quiz.IsMultipleChoice;
|
||||
Title = quiz.Name;
|
||||
}
|
||||
|
||||
public bool NextQuestion()
|
||||
{
|
||||
if (Questions == null || Questions.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Questions.Remove(Questions[0]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using FWLAZ_Web.Data;
|
||||
|
||||
namespace FWLAZ_Web.Objects
|
||||
{
|
||||
public class QuestionAnswer
|
||||
{
|
||||
public Question question { get; set; }
|
||||
public List<Answer> GivenAnswers { get; set; } = new();
|
||||
|
||||
public bool IsCorrect
|
||||
{
|
||||
get
|
||||
{
|
||||
return GivenAnswers.All(a => a.IsCorrect);
|
||||
}
|
||||
}
|
||||
|
||||
public QuestionAnswer(Question question)
|
||||
{
|
||||
this.question = question;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using FWLAZ_Web.Data;
|
||||
|
||||
namespace FWLAZ_Web.Objects
|
||||
{
|
||||
public class QuestionGroupSelect
|
||||
{
|
||||
public bool Checked { get; set; }
|
||||
|
||||
public QuestionGroup questionGroup { get; }
|
||||
|
||||
public QuestionGroupSelect(QuestionGroup questionGroup)
|
||||
{
|
||||
this.questionGroup = questionGroup;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using FWLAZ_Web.Data;
|
||||
|
||||
namespace FWLAZ_Web.Objects
|
||||
{
|
||||
public class QuestionGroupSummary
|
||||
{
|
||||
public int QuestionGroupID { get; set; }
|
||||
public string QuestionGroupName { get; set; }
|
||||
public int QuestionCount { get; set; }
|
||||
|
||||
public QuestionGroupSummary(QuestionGroup questionGroup)
|
||||
{
|
||||
QuestionGroupID = questionGroup.Id;
|
||||
QuestionGroupName = questionGroup.Name;
|
||||
QuestionCount = questionGroup.Questions.Count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Blazored.LocalStorage;
|
||||
namespace FWLAZ_Web.Objects
|
||||
{
|
||||
|
||||
|
||||
public class SessionState
|
||||
{
|
||||
public GameState? LoadGame { get; set; }
|
||||
|
||||
private ILocalStorageService localStorage;
|
||||
public SessionState(ILocalStorageService localStorage)
|
||||
{
|
||||
this.localStorage = localStorage;
|
||||
}
|
||||
|
||||
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadGame = await localStorage.GetItemAsync<GameState>(nameof(LoadGame));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error loading state: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveAsync()
|
||||
{
|
||||
await localStorage.SetItemAsync(nameof(LoadGame), LoadGame);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user