Add game example to template pattern

This commit is contained in:
Petrutiu Mihai
2016-07-06 10:24:01 +03:00
parent 97fb73c7fd
commit 9d16508e68
5 changed files with 95 additions and 0 deletions

View 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");
}
}
}

View 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");
}
}
}

View 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();
}
}
}

View 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();
}
}
}

View File

@@ -12,6 +12,8 @@ namespace TemplatePattern
Console.WriteLine(GetDescription());
GoToNextStep();
WorkersExample.WorkersExample.Run();
GoToNextStep();
GameExample.GameExample.Run();
}
private static string GetDescription()