forked from Aniket965/Hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prototype.cs
52 lines (44 loc) · 1.15 KB
/
prototype.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
namespace lab2
{
class Program
{
static void Main(string[] args)
{
EnemyManager enemymanager = new EnemyManager();
Enemy e1 = enemymanager.SpawnStrongerEnemy();
Enemy e2 = enemymanager.SpawnStrongerEnemy();
Enemy e3 = enemymanager.SpawnStrongerEnemy();
Enemy e4 = enemymanager.SpawnStrongerEnemy();
}
}
abstract class EnemyPrototype
{
public abstract EnemyPrototype Clone();
}
class Enemy : EnemyPrototype
{
private int power;
public Enemy()
{
this.power = 0;
}
public override EnemyPrototype Clone()
{
EnemyPrototype clonedEnemy = this.MemberwiseClone() as EnemyPrototype;
this.power++;
Console.WriteLine(
"Cloning enemy with power " + this.power);
return clonedEnemy;
}
}
class EnemyManager
{
private Enemy enemy = new Enemy();
public Enemy SpawnStrongerEnemy()
{
return enemy.Clone() as Enemy;
}
}
}