aboutsummaryrefslogtreecommitdiff
path: root/V3/Objects/CreatureFactory.cs
blob: 238ea411a1374a6f312181b49b5c71d27e0383b2 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using Microsoft.Xna.Framework;
using V3.Data;

namespace V3.Objects
{
    // ReSharper disable once ClassNeverInstantiated.Global
    public sealed class CreatureFactory
    {
        private readonly IBasicCreatureFactory mFactory;
        private readonly Random mRnd = new Random();

        public CreatureFactory(IBasicCreatureFactory factory)
        {
            mFactory = factory;
        }

        public ICreature CreateCreature(CreatureType type, int id)
        {
            IdGenerator.SetIdOnce(id);
            switch (type)
            {
                case CreatureType.FemalePeasant:
                    return mFactory.CreateFemalePeasant();
                case CreatureType.King:
                    return mFactory.CreateKing();
                case CreatureType.KingsGuard:
                    return mFactory.CreateKingsGuard();
                case CreatureType.Knight:
                    return mFactory.CreateKnight();
                case CreatureType.MalePeasant:
                    return mFactory.CreateMalePeasant();
                case CreatureType.Meatball:
                    return mFactory.CreateMeatball();
                case CreatureType.Necromancer:
                    return mFactory.CreateNecromancer();
                case CreatureType.Prince:
                    return mFactory.CreatePrince();
                case CreatureType.Skeleton:
                    return mFactory.CreateSkeleton();
                case CreatureType.Zombie:
                    return mFactory.CreateZombie();
                default:
                    IdGenerator.ClearIdOnce();
                    return null;
            }
        }

        public MalePeasant CreateMalePeasant(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreateMalePeasant(), position, movementDirection);
        }

        public FemalePeasant CreateFemalePeasant(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreateFemalePeasant(), position, movementDirection);
        }

        public Necromancer CreateNecromancer(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreateNecromancer(), position, movementDirection);
        }

        public Skeleton CreateSkeleton(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreateSkeleton(), position, movementDirection);
        }

        public SkeletonElite CreateSkeletonElite(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreateSkeletonElite(), position, movementDirection);
        }

        public Zombie CreateZombie(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreateZombie(), position, movementDirection);
        }

        public Knight CreateKnight(Vector2 position, MovementDirection movementDirection)
        {
            Knight knight = CreateCreature(mFactory.CreateKnight(), position, movementDirection);
            if (mRnd.Next(3) == 0)
            {
                knight.MakeFemale();
            }
            return knight;
        }

        public KingsGuard CreateKingsGuard(Vector2 position, MovementDirection movementDirection)
        {
            KingsGuard guard = CreateCreature(mFactory.CreateKingsGuard(), position, movementDirection);
            if (mRnd.Next(3) == 0)
            {
                guard.MakeFemale();
            }
            return guard;
        }

        public SkeletonHorse CreateSkeletonHorse(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreateSkeletonHorse(), position, movementDirection);
        }

        public Meatball CreateMeatball(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreateMeatball(), position, movementDirection);
        }

        public Prince CreatePrince(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreatePrince(), position, movementDirection);
        }

        public King CreateKing(Vector2 position, MovementDirection movementDirection)
        {
            return CreateCreature(mFactory.CreateKing(), position, movementDirection);
        }

        private T CreateCreature<T>(T creature, Vector2 position, MovementDirection movementDirection) where T: ICreature
        {
            creature.Position = position;
            creature.InitialPosition = position;
            creature.MovementDirection = movementDirection;
            return creature;
        }
    }
}