Skip to content

Commit c35de9e

Browse files
committed
Removed Game class. Fixed reset issue.
1 parent fe1cf29 commit c35de9e

File tree

10 files changed

+58
-98
lines changed

10 files changed

+58
-98
lines changed

Assets/Scripts/App.cs

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,75 @@
1+
using System;
2+
using Common.GameModes;
3+
using Match3.Infrastructure.Extensions;
4+
using Match3.Infrastructure.Interfaces;
15
using UnityEngine;
26

37
public class App : MonoBehaviour
48
{
59
[SerializeField] private AppContext _appContext;
610

7-
private Game _game;
11+
private int _currentModeIndex;
12+
13+
private IGameMode _activeMode;
14+
private IGameMode[] _gameModes;
815

916
private void Awake()
1017
{
1118
_appContext.Construct();
12-
_game = new Game(_appContext);
19+
_gameModes = new IGameMode[]
20+
{
21+
new DrawGameBoardMode(_appContext),
22+
new GameInitMode(_appContext),
23+
new GamePlayMode(_appContext),
24+
new GameResetMode(_appContext)
25+
};
1326
}
1427

1528
private void Start()
1629
{
17-
_game.Start();
30+
ActivateGameMode(0);
1831
}
1932

2033
private void OnEnable()
2134
{
22-
_game.Enable();
35+
foreach (var gameMode in _gameModes)
36+
{
37+
gameMode.Finished += OnGameModeFinished;
38+
}
2339
}
2440

2541
private void OnDisable()
2642
{
27-
_game.Disable();
43+
foreach (var gameMode in _gameModes)
44+
{
45+
gameMode.Finished -= OnGameModeFinished;
46+
}
2847
}
2948

3049
private void OnDestroy()
3150
{
32-
_game.Dispose();
51+
foreach (var gameMode in _gameModes)
52+
{
53+
gameMode.Dispose();
54+
}
55+
}
56+
57+
private void OnGameModeFinished(object sender, EventArgs e)
58+
{
59+
_currentModeIndex++;
60+
61+
if (_currentModeIndex >= _gameModes.Length)
62+
{
63+
_currentModeIndex = 0;
64+
}
65+
66+
ActivateGameMode(_currentModeIndex);
67+
}
68+
69+
private void ActivateGameMode(int gameModeIndex)
70+
{
71+
_activeMode?.Deactivate();
72+
_activeMode = _gameModes[gameModeIndex];
73+
_activeMode.Activate();
3374
}
3475
}

Assets/Scripts/AppContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
using FillStrategies;
88
using Match3.Core.Interfaces;
99
using Match3.Infrastructure;
10+
using Match3.Infrastructure.Interfaces;
1011
using Match3.Infrastructure.SequenceDetectors;
1112
using Match3.UnityApp;
1213
using Match3.UnityApp.Interfaces;
1314
using UnityEngine;
15+
using IItemGenerator = Common.Interfaces.IItemGenerator;
1416

1517
public class AppContext : MonoBehaviour, IAppContext
1618
{

Assets/Scripts/Common/Extensions/ItemsPoolExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using Common.Interfaces;
3+
using Match3.Infrastructure.Interfaces;
34

45
namespace Common.Extensions
56
{

Assets/Scripts/Common/GameModes/GameResetMode.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ namespace Common.GameModes
88
public class GameResetMode : IGameMode
99
{
1010
private readonly UnityGame _unityGame;
11-
private readonly Interfaces.IItemsPool<IUnityItem> _itemsPool;
11+
private readonly IItemsPool<IUnityItem> _itemsPool;
12+
private readonly IUnityGameBoardRenderer _gameBoardRenderer;
1213

1314
public GameResetMode(IAppContext appContext)
1415
{
1516
_unityGame = appContext.Resolve<UnityGame>();
16-
_itemsPool = appContext.Resolve<Interfaces.IItemsPool<IUnityItem>>();
17+
_itemsPool = appContext.Resolve<IItemsPool<IUnityItem>>();
18+
_gameBoardRenderer = appContext.Resolve<IUnityGameBoardRenderer>();
1719
}
1820

1921
public event EventHandler Finished;
2022

2123
public void Activate()
2224
{
2325
_itemsPool.ReturnAllItems(_unityGame.GetGridSlots());
26+
_gameBoardRenderer.ResetGridTiles();
2427
_unityGame.ResetGameBoard();
2528

2629
Finished?.Invoke(this, EventArgs.Empty);

Assets/Scripts/Common/Interfaces/IItemsPool.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

Assets/Scripts/Common/Interfaces/IItemsPool.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

Assets/Scripts/Common/ItemGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Collections.Generic;
22
using Common.Interfaces;
3+
using Match3.Infrastructure.Interfaces;
34
using UnityEngine;
5+
using IItemGenerator = Common.Interfaces.IItemGenerator;
46
using Random = System.Random;
57

68
namespace Common

Assets/Scripts/FillStrategies/BaseFillStrategy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Match3.Core.Interfaces;
66
using Match3.Core.Models;
77
using Match3.Core.Structs;
8+
using Match3.Infrastructure.Interfaces;
89
using Match3.UnityApp.Interfaces;
910
using UnityEngine;
1011

Assets/Scripts/Game.cs

Lines changed: 0 additions & 76 deletions
This file was deleted.

Assets/Scripts/Game.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)