feat: PongScoreboard
This commit is contained in:
		
							
								
								
									
										45
									
								
								Game/Behaviours/PongScoreboard.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								Game/Behaviours/PongScoreboard.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
using System;
 | 
			
		||||
using Syntriax.Engine.Core;
 | 
			
		||||
 | 
			
		||||
namespace Pong.Behaviours;
 | 
			
		||||
 | 
			
		||||
public class PongScoreboard(int WinScore) : BehaviourOverride
 | 
			
		||||
{
 | 
			
		||||
    public Action? OnReset { get; set; } = null;
 | 
			
		||||
    public Action? OnFinished { get; set; } = null;
 | 
			
		||||
    public Action? OnScored { get; set; } = null;
 | 
			
		||||
 | 
			
		||||
    public int ScoreLeft { get; private set; } = 0;
 | 
			
		||||
    public int ScoreRight { get; private set; } = 0;
 | 
			
		||||
    public int ScoreSum => ScoreLeft + ScoreRight;
 | 
			
		||||
 | 
			
		||||
    public int WinScore { get; } = WinScore;
 | 
			
		||||
 | 
			
		||||
    public void ScoreToLeft()
 | 
			
		||||
    {
 | 
			
		||||
        ScoreLeft++;
 | 
			
		||||
        OnScored?.Invoke();
 | 
			
		||||
 | 
			
		||||
        CheckFinish();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void ScoreToRight()
 | 
			
		||||
    {
 | 
			
		||||
        ScoreRight++;
 | 
			
		||||
        OnScored?.Invoke();
 | 
			
		||||
 | 
			
		||||
        CheckFinish();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Reset()
 | 
			
		||||
    {
 | 
			
		||||
        ScoreLeft = ScoreRight = 0;
 | 
			
		||||
        OnReset?.Invoke();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void CheckFinish()
 | 
			
		||||
    {
 | 
			
		||||
        if (ScoreSum == WinScore)
 | 
			
		||||
            OnFinished?.Invoke();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user