Add initial project files and configurations for Unity setup
This commit is contained in:
3
Assets/Scripts/Core/Domain.meta
Normal file
3
Assets/Scripts/Core/Domain.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 214b1d40bd8c47dab78f4b861f1a3bef
|
||||
timeCreated: 1765560149
|
||||
99
Assets/Scripts/Core/Domain/GameSession.cs
Normal file
99
Assets/Scripts/Core/Domain/GameSession.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Domain/GameSession.cs.meta
Normal file
3
Assets/Scripts/Core/Domain/GameSession.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d87b26f6f6c4273baa331c65f412eb2
|
||||
timeCreated: 1765563052
|
||||
61
Assets/Scripts/Core/Domain/MapPatterns.cs
Normal file
61
Assets/Scripts/Core/Domain/MapPatterns.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Domain/MapPatterns.cs.meta
Normal file
3
Assets/Scripts/Core/Domain/MapPatterns.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75b47c1431af431685b2b6b69775a812
|
||||
timeCreated: 1765570591
|
||||
60
Assets/Scripts/Core/Domain/Tile.cs
Normal file
60
Assets/Scripts/Core/Domain/Tile.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Domain/Tile.cs.meta
Normal file
3
Assets/Scripts/Core/Domain/Tile.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f320af19d414e688f733d2f49c85499
|
||||
timeCreated: 1765560252
|
||||
10
Assets/Scripts/Core/Domain/TileState.cs
Normal file
10
Assets/Scripts/Core/Domain/TileState.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Core.Domain
|
||||
{
|
||||
public enum TileState
|
||||
{
|
||||
Stable,
|
||||
Warning,
|
||||
Falling,
|
||||
Destroyed
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Domain/TileState.cs.meta
Normal file
3
Assets/Scripts/Core/Domain/TileState.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 251941ec93e643f1bb352d1ba27415fa
|
||||
timeCreated: 1765560203
|
||||
3
Assets/Scripts/Core/Ports.meta
Normal file
3
Assets/Scripts/Core/Ports.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37708dbb6aaf42298419527eb635dda8
|
||||
timeCreated: 1765560153
|
||||
8
Assets/Scripts/Core/Ports/IPersistenceService.cs
Normal file
8
Assets/Scripts/Core/Ports/IPersistenceService.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Core.Ports
|
||||
{
|
||||
public interface IPersistenceService
|
||||
{
|
||||
void Save(string key, int value);
|
||||
int Load(string key, int defaultValue = 0);
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Ports/IPersistenceService.cs.meta
Normal file
3
Assets/Scripts/Core/Ports/IPersistenceService.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b21e8384f7154851a4b258200a5eaed8
|
||||
timeCreated: 1765568951
|
||||
13
Assets/Scripts/Core/Ports/ITileView.cs
Normal file
13
Assets/Scripts/Core/Ports/ITileView.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Core.Domain;
|
||||
|
||||
namespace Core.Ports
|
||||
{
|
||||
public interface ITileView
|
||||
{
|
||||
string TileId { get; }
|
||||
void Initialize(Tile tile);
|
||||
void SetVisualState(TileState state);
|
||||
void DropPhysics();
|
||||
void Dispose();
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Core/Ports/ITileView.cs.meta
Normal file
3
Assets/Scripts/Core/Ports/ITileView.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4d59fe7258e450a868cd36cd306c0da
|
||||
timeCreated: 1765560752
|
||||
Reference in New Issue
Block a user