Skip to content

Instantly share code, notes, and snippets.

@GarethOates
Last active January 27, 2020 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GarethOates/c8045890cd6e483850c66b0ad3b476a9 to your computer and use it in GitHub Desktop.
Save GarethOates/c8045890cd6e483850c66b0ad3b476a9 to your computer and use it in GitHub Desktop.
Decorator Pattern Output
using System;
using System.Linq;
using System.Collections.Generic;
namespace MagicTheProgramming
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Creating a new Creature");
ICreature creature = new Creature("Nyxborn Courser", 2, 4);
Console.WriteLine($"Name: {creature.Name}");
Console.WriteLine($"Base Power: {creature.Power}");
Console.WriteLine($"Base Toughness: {creature.Toughness}");
Console.WriteLine("Equipping a Sword to the creature..");
creature = new Sword(creature);
getStats(creature);
Console.WriteLine("Equipping a Shield...");
Console.WriteLine("Currently Equipped: Sword and Shield");
creature = new Shield(creature);
getStats(creature);
Console.WriteLine("Equipping a Helmet...");
Console.WriteLine("Currently Equipped: Sword, Shield and Helmet");
creature = new Helmet(creature);
getStats(creature);
Console.WriteLine("Equipping Variable Weapon");
creature = new Weapon(creature, 5, 10);
getStats(creature);
Console.ReadLine();
}
private static void getStats(ICreature creature)
{
Console.WriteLine($"New Power: {creature.Power}");
Console.WriteLine($"New Toughness: {creature.Toughness}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment