Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Full tutorial on https://indiedevart.wordpress.com/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PrototypePattern
- {
- class Program
- {
- static void Main(string[] args)
- {
- Enemy enemy = new Enemy();
- enemy.Id = 1;
- Console.WriteLine("Enemy Copy ID: " + enemy.Id.ToString());
- // We enter the cheat code here and we have a new
- // player object that we can save on the disk asyncronously.
- Enemy clonedEnemy = enemy.Clone() as Enemy;
- Console.WriteLine("Enemy Copy ID: " + clonedEnemy.Id.ToString());
- Console.ReadLine();
- }
- }
- public abstract class AbstractEnemy
- {
- int _id;
- public int Id
- {
- get { return _id; }
- set { _id = value; }
- }
- public abstract AbstractEnemy Clone();
- }
- class Enemy : AbstractEnemy
- {
- public override AbstractEnemy Clone()
- {
- Console.WriteLine("cloning enemy");
- return this.MemberwiseClone() as AbstractEnemy;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement