Implement core game functionality with AppRoot, SaveClient, PlayerRepository, and LevelRepository classes
This commit is contained in:
34
game/repositories/LevelRepository.cs
Normal file
34
game/repositories/LevelRepository.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Mr.BrickAdventures.game.repositories;
|
||||
|
||||
public sealed class LevelRepository
|
||||
{
|
||||
public int Current { get; private set; } = 0;
|
||||
public HashSet<int> Unlocked { get; } = new() { 0 };
|
||||
public HashSet<int> Completed { get; } = new();
|
||||
|
||||
public event Action<int>? CurrentChanged;
|
||||
|
||||
public void SetCurrent(int idx) { Current = idx; CurrentChanged?.Invoke(Current); }
|
||||
public void Unlock(int idx) => Unlocked.Add(idx);
|
||||
public void Complete(int idx) { Completed.Add(idx); Unlock(idx + 1); }
|
||||
|
||||
public LevelState Export() => new() {
|
||||
Current = Current, Unlocked = [..Unlocked], Completed = [..Completed]
|
||||
};
|
||||
public void Load(LevelState s) {
|
||||
Current = s.Current;
|
||||
Unlocked.Clear(); foreach (var i in s.Unlocked) Unlocked.Add(i);
|
||||
Completed.Clear(); foreach (var i in s.Completed) Completed.Add(i);
|
||||
CurrentChanged?.Invoke(Current);
|
||||
}
|
||||
}
|
||||
|
||||
public record LevelState {
|
||||
public int Current;
|
||||
public int[] Unlocked = [];
|
||||
public int[] Completed = [];
|
||||
}
|
1
game/repositories/LevelRepository.cs.uid
Normal file
1
game/repositories/LevelRepository.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d0604lmwpadt5
|
25
game/repositories/PlayerRepository.cs
Normal file
25
game/repositories/PlayerRepository.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace Mr.BrickAdventures.game.repositories;
|
||||
|
||||
public sealed class PlayerRepository
|
||||
{
|
||||
public int Coins { get; private set; } = 0;
|
||||
public int Lives { get; private set; } = 3;
|
||||
|
||||
public event Action<int>? CoinsChanged;
|
||||
public event Action<int>? LivesChanged;
|
||||
|
||||
public void SetCoins(int value) { Coins = Math.Max(0, value); CoinsChanged?.Invoke(Coins); }
|
||||
public void AddCoins(int amount) { SetCoins(Coins + amount); }
|
||||
public void RemoveCoins(int amount){ SetCoins(Coins - amount); }
|
||||
|
||||
public void SetLives(int value) { Lives = value; LivesChanged?.Invoke(Lives); }
|
||||
public void AddLives(int amount) { SetLives(Lives + amount); }
|
||||
public void RemoveLives(int amount){ SetLives(Lives - amount); }
|
||||
|
||||
public PlayerState Export() => new() { Coins = Coins, Lives = Lives };
|
||||
public void Load(PlayerState s) { SetCoins(s.Coins); SetLives(s.Lives); }
|
||||
}
|
||||
|
||||
public record PlayerState { public int Coins; public int Lives; }
|
1
game/repositories/PlayerRepository.cs.uid
Normal file
1
game/repositories/PlayerRepository.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d1dijkt574x4b
|
6
game/repositories/SessionRepository.cs
Normal file
6
game/repositories/SessionRepository.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Mr.BrickAdventures.game.repositories;
|
||||
|
||||
public sealed class SessionRepository
|
||||
{
|
||||
|
||||
}
|
1
game/repositories/SessionRepository.cs.uid
Normal file
1
game/repositories/SessionRepository.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b550hcqugygv0
|
6
game/repositories/SettingsRepository.cs
Normal file
6
game/repositories/SettingsRepository.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Mr.BrickAdventures.game.repositories;
|
||||
|
||||
public class SettingsRepository
|
||||
{
|
||||
|
||||
}
|
1
game/repositories/SettingsRepository.cs.uid
Normal file
1
game/repositories/SettingsRepository.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bk11iduo7bg2h
|
6
game/repositories/SkillsRepository.cs
Normal file
6
game/repositories/SkillsRepository.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Mr.BrickAdventures.game.repositories;
|
||||
|
||||
public class SkillsRepository
|
||||
{
|
||||
|
||||
}
|
1
game/repositories/SkillsRepository.cs.uid
Normal file
1
game/repositories/SkillsRepository.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cymx7mtmdblun
|
Reference in New Issue
Block a user