diff --git a/src/TemplatePattern/GameExample/Basketball.cs b/src/TemplatePattern/GameExample/Basketball.cs new file mode 100644 index 0000000..9546921 --- /dev/null +++ b/src/TemplatePattern/GameExample/Basketball.cs @@ -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"); + } + } +} diff --git a/src/TemplatePattern/GameExample/Football.cs b/src/TemplatePattern/GameExample/Football.cs new file mode 100644 index 0000000..f6f447c --- /dev/null +++ b/src/TemplatePattern/GameExample/Football.cs @@ -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"); + } + } +} diff --git a/src/TemplatePattern/GameExample/Game.cs b/src/TemplatePattern/GameExample/Game.cs new file mode 100644 index 0000000..6aae2f5 --- /dev/null +++ b/src/TemplatePattern/GameExample/Game.cs @@ -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(); + } + + } +} diff --git a/src/TemplatePattern/GameExample/GameExample.cs b/src/TemplatePattern/GameExample/GameExample.cs new file mode 100644 index 0000000..d58487e --- /dev/null +++ b/src/TemplatePattern/GameExample/GameExample.cs @@ -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(); + } + } +} diff --git a/src/TemplatePattern/TemplatePatternExamples.cs b/src/TemplatePattern/TemplatePatternExamples.cs index 327a7b5..3d7d02f 100644 --- a/src/TemplatePattern/TemplatePatternExamples.cs +++ b/src/TemplatePattern/TemplatePatternExamples.cs @@ -12,6 +12,8 @@ namespace TemplatePattern Console.WriteLine(GetDescription()); GoToNextStep(); WorkersExample.WorkersExample.Run(); + GoToNextStep(); + GameExample.GameExample.Run(); } private static string GetDescription()