Add game example to template pattern
This commit is contained in:
25
src/TemplatePattern/GameExample/Basketball.cs
Normal file
25
src/TemplatePattern/GameExample/Basketball.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TemplatePattern.GameExample
|
||||
{
|
||||
public class Basketball : Game
|
||||
{
|
||||
protected override void EndGame()
|
||||
{
|
||||
Console.WriteLine("Good basketball game, GG");
|
||||
}
|
||||
|
||||
protected override void InitGame()
|
||||
{
|
||||
Console.WriteLine("Le players are warming up, shooting at the goal");
|
||||
}
|
||||
|
||||
protected override void StartGame()
|
||||
{
|
||||
Console.WriteLine("Let le basket game, start");
|
||||
}
|
||||
}
|
||||
}
|
||||
25
src/TemplatePattern/GameExample/Football.cs
Normal file
25
src/TemplatePattern/GameExample/Football.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TemplatePattern.GameExample
|
||||
{
|
||||
public class Football : Game
|
||||
{
|
||||
protected override void EndGame()
|
||||
{
|
||||
Console.WriteLine("90 minutes over, game ended");
|
||||
}
|
||||
|
||||
protected override void InitGame()
|
||||
{
|
||||
Console.WriteLine("Let the players get on the field with their kids");
|
||||
}
|
||||
|
||||
protected override void StartGame()
|
||||
{
|
||||
Console.WriteLine("Let le ball in le goal");
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/TemplatePattern/GameExample/Game.cs
Normal file
24
src/TemplatePattern/GameExample/Game.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TemplatePattern.GameExample
|
||||
{
|
||||
public abstract class Game
|
||||
{
|
||||
protected abstract void InitGame();
|
||||
|
||||
protected abstract void StartGame();
|
||||
|
||||
protected abstract void EndGame();
|
||||
|
||||
public void Play()
|
||||
{
|
||||
InitGame();
|
||||
StartGame();
|
||||
EndGame();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
19
src/TemplatePattern/GameExample/GameExample.cs
Normal file
19
src/TemplatePattern/GameExample/GameExample.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace TemplatePattern.GameExample
|
||||
{
|
||||
public class GameExample
|
||||
{
|
||||
public static void Run()
|
||||
{
|
||||
Console.WriteLine("Basketball game:");
|
||||
|
||||
Basketball b = new Basketball();
|
||||
b.Play();
|
||||
|
||||
Console.WriteLine("Football game:");
|
||||
Football f = new Football();
|
||||
f.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ namespace TemplatePattern
|
||||
Console.WriteLine(GetDescription());
|
||||
GoToNextStep();
|
||||
WorkersExample.WorkersExample.Run();
|
||||
GoToNextStep();
|
||||
GameExample.GameExample.Run();
|
||||
}
|
||||
|
||||
private static string GetDescription()
|
||||
|
||||
Reference in New Issue
Block a user