-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pedro Moreira
committed
Sep 22, 2017
1 parent
d63d6b5
commit 1d84ee3
Showing
10 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace StrategyPattern | ||
{ | ||
public class Barney : Character | ||
{ | ||
public Barney() | ||
: base((string)nameof(Barney)) | ||
{ | ||
} | ||
|
||
public override void Fight() | ||
{ | ||
this.Weapon.UseWeapon(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace StrategyPattern | ||
{ | ||
using System; | ||
|
||
public abstract class Character | ||
{ | ||
protected Character(string name) | ||
{ | ||
this.Name = name; | ||
} | ||
|
||
public string Name { get; } | ||
|
||
public IWeaponBehavior Weapon { get; private set; } | ||
|
||
public void SetWeapon(IWeaponBehavior weapon) | ||
{ | ||
this.Weapon = weapon; | ||
} | ||
|
||
public abstract void Fight(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace StrategyPattern | ||
{ | ||
public interface IWeaponBehavior | ||
{ | ||
void UseWeapon(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace StrategyPattern | ||
{ | ||
using System; | ||
|
||
public class Marshall : Character | ||
{ | ||
public Marshall() | ||
: base((string) nameof(Marshall)) | ||
{ | ||
} | ||
|
||
public override void Fight() | ||
{ | ||
this.Weapon.UseWeapon(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
|
||
namespace StrategyPattern | ||
{ | ||
internal class Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
var sword = new SwordBehavior(); | ||
var slap = new SlapBehavior(); | ||
|
||
var marshall = new Marshall(); | ||
var barney = new Barney(); | ||
|
||
Console.WriteLine("Slapbet round 1!"); | ||
|
||
Console.WriteLine("Barney annoys Marshall!"); | ||
|
||
Console.WriteLine("Marshall prepares his hand!"); | ||
marshall.SetWeapon(slap); | ||
|
||
marshall.Fight(); | ||
|
||
Console.WriteLine("Barney is slapped in the face!"); | ||
Console.WriteLine("Barney equips a sword!"); | ||
|
||
barney.SetWeapon(sword); | ||
barney.Fight(); | ||
|
||
Console.WriteLine("Marshall equips a Sword too!"); | ||
marshall.SetWeapon(sword); | ||
marshall.Fight(); | ||
|
||
Console.WriteLine("They duel."); | ||
|
||
Console.ReadLine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace StrategyPattern | ||
{ | ||
using System; | ||
|
||
public class SlapBehavior : IWeaponBehavior | ||
{ | ||
public void UseWeapon() | ||
{ | ||
Console.WriteLine("You just got Slapped! In the face my friend."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace StrategyPattern | ||
{ | ||
using System; | ||
|
||
public class SwordBehavior : IWeaponBehavior | ||
{ | ||
public void UseWeapon() | ||
{ | ||
Console.WriteLine("You got Slashed!"); | ||
} | ||
} | ||
} |