Add initial project files and configurations for Unity setup

This commit is contained in:
2025-12-12 22:04:14 +01:00
commit b6106cf82b
205 changed files with 79202 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using Core.Ports;
namespace Core.Domain
{
public class GameSession
{
private const string HighScoreKey = "HighScore";
public int Score { get; private set; }
public int HighScore { get; private set; }
public bool IsGameOver { get; private set; }
public event Action<int> OnScoreChanged;
public event Action<string> OnOrbSpawned;
public event Action OnOrbReset;
public event Action OnGameOver;
private readonly List<Tile> _tiles;
private readonly IPersistenceService _persistenceService;
private readonly Random _rng = new();
private int _playerFloorIndex = 0;
public GameSession(List<Tile> tiles, IPersistenceService persistenceService)
{
_tiles = tiles;
_persistenceService = persistenceService;
Score = 0;
IsGameOver = false;
HighScore = _persistenceService.Load(HighScoreKey, 0);
}
public void StartGame()
{
SpawnNextOrb();
}
public void OrbCollected()
{
if (IsGameOver) return;
Score += 10;
OnScoreChanged?.Invoke(Score);
SpawnNextOrb();
}
private void SpawnNextOrb()
{
var validTiles = _tiles.FindAll(t =>
t.CurrentState == TileState.Stable &&
t.Floor == _playerFloorIndex
);
if (validTiles.Count == 0)
{
validTiles = _tiles.FindAll(t => t.CurrentState == TileState.Stable);
}
if (validTiles.Count == 0)
{
EndGame();
return;
}
var pick = validTiles[_rng.Next(validTiles.Count)];
OnOrbSpawned?.Invoke(pick.Id);
}
public void EndGame()
{
if (IsGameOver) return;
IsGameOver = true;
if (Score > HighScore)
{
HighScore = Score;
_persistenceService.Save(HighScoreKey, HighScore);
}
OnGameOver?.Invoke();
}
public void SetPlayerFloor(int floorIndex)
{
if (_playerFloorIndex == floorIndex) return;
_playerFloorIndex = floorIndex;
if (IsGameOver) return;
OnOrbReset?.Invoke();
SpawnNextOrb();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0d87b26f6f6c4273baa331c65f412eb2
timeCreated: 1765563052

View File

@@ -0,0 +1,61 @@
using System.Collections.Generic;
using UnityEngine;
namespace Core.Domain
{
public static class MapPatterns
{
public static List<Vector2Int> GenerateSquare(int width, int height)
{
var positions = new List<Vector2Int>();
for (var x = 0; x < width; x++)
{
for (var y = 0; y < height; y++)
{
positions.Add(new Vector2Int(x, y));
}
}
return positions;
}
public static List<Vector2Int> GenerateCircle(int diameter)
{
var positions = new List<Vector2Int>();
var radius = diameter / 2.0f;
var center = new Vector2(radius, radius);
for (var x = 0; x < diameter; x++)
{
for (var y = 0; y < diameter; y++)
{
if (Vector2.Distance(new Vector2(x, y), center) <= radius)
{
positions.Add(new Vector2Int(x, y));
}
}
}
return positions;
}
public static List<Vector2Int> GenerateDonut(int diameter, int holeSize)
{
var positions = new List<Vector2Int>();
var radius = diameter / 2.0f;
var holeRadius = holeSize / 2.0f;
var center = new Vector2(radius, radius);
for (var x = 0; x < diameter; x++)
{
for (var y = 0; y < diameter; y++)
{
var dist = Vector2.Distance(new Vector2(x, y), center);
if (dist <= radius && dist >= holeRadius)
{
positions.Add(new Vector2Int(x, y));
}
}
}
return positions;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 75b47c1431af431685b2b6b69775a812
timeCreated: 1765570591

View File

@@ -0,0 +1,60 @@
using System;
namespace Core.Domain
{
public class Tile
{
public string Id { get; }
public int Floor { get; }
public TileState CurrentState { get; private set; }
private readonly float _warningDuration;
private readonly float _fallingDuration;
private float _stateTimer;
public event Action<Tile> OnStateChanged;
public Tile(string id, int floor, float warningDuration, float fallingDuration)
{
Id = id;
Floor = floor;
_warningDuration = warningDuration;
_fallingDuration = fallingDuration;
CurrentState = TileState.Stable;
}
public void StepOn()
{
if (CurrentState == TileState.Stable)
{
TransitionTo(TileState.Warning);
}
}
public void Tick(float deltaTime)
{
if (CurrentState == TileState.Stable || CurrentState == TileState.Destroyed) return;
_stateTimer += deltaTime;
if (CurrentState == TileState.Warning && _stateTimer >= _warningDuration)
{
TransitionTo(TileState.Falling);
}
else if (CurrentState == TileState.Falling && _stateTimer >= _fallingDuration)
{
TransitionTo(TileState.Destroyed);
}
}
private void TransitionTo(TileState newState)
{
CurrentState = newState;
_stateTimer = 0f;
OnStateChanged?.Invoke(this);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2f320af19d414e688f733d2f49c85499
timeCreated: 1765560252

View File

@@ -0,0 +1,10 @@
namespace Core.Domain
{
public enum TileState
{
Stable,
Warning,
Falling,
Destroyed
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 251941ec93e643f1bb352d1ba27415fa
timeCreated: 1765560203