Created
June 11, 2016 01:53
-
-
Save ShirakawaYoshimaru/5601f26945a803dcb24003de77c2f0ed to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using UnityEngine.UI; | |
using System; | |
public abstract class Factory | |
{ | |
Action createEvent; | |
public void AddListenCreateEvent (Action action) | |
{ | |
createEvent += action; | |
} | |
public Product Create (string name, int atk, int def, int haveCount) | |
{ | |
Product product = CreateProduct (name, atk, def, haveCount); | |
if (createEvent != null) { | |
createEvent (); | |
} | |
return product; | |
} | |
protected abstract Product CreateProduct (string name, int atk, int def, int haveCount); | |
} | |
public class CardFactory : Factory | |
{ | |
protected override Product CreateProduct (string name, int atk, int def, int haveCount) | |
{ | |
return new CardATK (name, atk, def, haveCount); | |
} | |
} |
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
using UnityEngine; | |
using UnityEngine.UI; | |
using System; | |
public abstract class Product | |
{ | |
protected string name; | |
protected int atk; | |
protected int def; | |
protected int haveCount; | |
public Product (string name, int atk, int def, int haveCount) | |
{ | |
this.name = name; | |
this.atk = atk; | |
this.def = def; | |
this.haveCount = haveCount; | |
} | |
public void Show () | |
{ | |
Debug.Log (this.name + "!" + GetInfo ()); | |
} | |
public abstract int GetInfo (); | |
} | |
public class CardATK : Product | |
{ | |
public CardATK (string name, int atk, int def, int haveCount) : base (name, atk, def, haveCount) | |
{ | |
} | |
public override int GetInfo () | |
{ | |
return this.atk; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment