Skip to content

Instantly share code, notes, and snippets.

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 ShirakawaYoshimaru/5601f26945a803dcb24003de77c2f0ed to your computer and use it in GitHub Desktop.
Save ShirakawaYoshimaru/5601f26945a803dcb24003de77c2f0ed to your computer and use it in GitHub Desktop.
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);
}
}
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