ИИ гонщиков, запуск, перезапуск игры и пр
This commit is contained in:
1 parent
f557c58c9d
commit
efcfaae647
48 files changed
+1486
-212
No files matched your search
@@ -1,14 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.Example.Race.Racer.Player;
|
||||
using Code.Example.Race.Track;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Reflex.Attributes;
|
||||
|
||||
namespace Code.Example.Race
|
||||
{
|
||||
public class RaceScores : IRacerPassedCheckpointHandler, IDisposable
|
||||
public class RaceScores : IRacerPassedCheckpointHandler, IDisposable, IPlayerPassedCheckpointHandler
|
||||
{
|
||||
private Dictionary<Racer.Racer, int> _scores = new();
|
||||
private Dictionary<Racer.Racer, ScoreData> _scores = new();
|
||||
private EventBus _eventBus;
|
||||
|
||||
public RaceScores(EventBus eventBus)
|
||||
@@ -16,25 +18,34 @@ namespace Code.Example.Race
|
||||
_eventBus = eventBus;
|
||||
_eventBus.Subscribe(this);
|
||||
}
|
||||
|
||||
public void SubscribeRacer(Racer.Racer racer)
|
||||
{
|
||||
_scores.Add(racer, 0);
|
||||
_scores.Add(racer, new ScoreData());
|
||||
}
|
||||
|
||||
public void ChangeScore(Racer.Racer racer, int additionalScore)
|
||||
{
|
||||
_scores[racer] += additionalScore;
|
||||
_eventBus.RaiseEvent<IScoreChangedHandle>(x=> x.ScoreChanged(racer,additionalScore, GetScores()));
|
||||
_scores[racer].checkpointsPassed += additionalScore;
|
||||
_eventBus.RaiseEvent<IScoreChangedHandle>(x=> x.ScoreChanged(racer,_scores[racer], GetScores()));
|
||||
}
|
||||
|
||||
|
||||
public void LapPassed(Racer.Racer racer)
|
||||
{
|
||||
_scores[racer].lapsPassed++;
|
||||
_eventBus.RaiseEvent<IScoreChangedHandle>(x=> x.ScoreChanged(racer,_scores[racer], GetScores()));
|
||||
if (_scores[racer].lapsPassed >= _raceTrackData.trackData.LapCount)
|
||||
_eventBus.RaiseEvent<IRaceGameHandle>(x=> x.RaceGameEnded(this));
|
||||
}
|
||||
|
||||
public void UnsubscribeRacer(Racer.Racer racer)
|
||||
{
|
||||
_scores.Remove(racer);
|
||||
}
|
||||
|
||||
public List<KeyValuePair<Racer.Racer, int>> GetScores()
|
||||
public List<KeyValuePair<Racer.Racer, ScoreData>> GetScores()
|
||||
{
|
||||
return _scores.OrderByDescending(x => x.Value).ToList();
|
||||
return _scores.OrderByDescending(x => x.Value.checkpointsPassed).ToList();
|
||||
}
|
||||
|
||||
public void OnRacerPassedCheckpoint(Racer.Racer racer) => ChangeScore(racer,1);
|
||||
@@ -43,10 +54,27 @@ namespace Code.Example.Race
|
||||
{
|
||||
_eventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
[Inject] private RaceTrackData _raceTrackData;
|
||||
|
||||
public void OnPlayerPassedCheckpoint(Racer.Racer racer)
|
||||
{
|
||||
var player = (PlayerRacer)racer;
|
||||
_raceTrackData.trackData.Checkpoints[player.CurrentWaypointIndex].Show();
|
||||
}
|
||||
|
||||
public void OnPlayerLapPassed(Racer.Racer racer)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ScoreData
|
||||
{
|
||||
public int checkpointsPassed;
|
||||
public int lapsPassed;
|
||||
}
|
||||
public interface IScoreChangedHandle : IGlobalSubscriber
|
||||
{
|
||||
void ScoreChanged(Racer.Racer racer, int additionalScore, List<KeyValuePair<Racer.Racer, int>> scores);
|
||||
void ScoreChanged(Racer.Racer racer, ScoreData score, List<KeyValuePair<Racer.Racer, ScoreData>> scores);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user