-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathStartingConfiguration.cs
More file actions
115 lines (94 loc) · 3.67 KB
/
StartingConfiguration.cs
File metadata and controls
115 lines (94 loc) · 3.67 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using Dominion.Cards.Curses;
using Dominion.Cards.Treasure;
using Dominion.Cards.Victory;
using Dominion.Rules;
using Dominion.Rules.CardTypes;
namespace Dominion.GameHost
{
public abstract class StartingConfiguration
{
private readonly int _numberOfPlayers;
public StartingConfiguration(int numberOfPlayers)
{
if(numberOfPlayers < 1)
throw new ArgumentException("Number of players must be greater than 0", "numberOfPlayers");
_numberOfPlayers = numberOfPlayers;
}
public virtual void InitializeBank(CardBank bank)
{
bank.AddCardPile(Gold);
bank.AddCardPile(Silver);
bank.AddCardPileWhichEndsTheGameWhenEmpty(Provinces);
bank.AddCardPile(Duchies);
bank.AddCardPile(Copper);
bank.AddCardPile(Estates);
bank.AddCardPile(Curses);
if(bank.Piles.Any(p => p.TopCard.Cost.Potions > 0))
bank.AddCardPile(Potions);
}
protected void AddProsperityCards(CardBank bank)
{
bank.AddCardPile(new UnlimitedSupplyCardPile(() => new Platinum()));
var colonyPile = new LimitedSupplyCardPile();
colonyPile.WithNewCards<Colony>(_numberOfPlayers <= 2 ? 8 : 12);
bank.AddCardPileWhichEndsTheGameWhenEmpty(colonyPile);
}
public Game CreateGame(IEnumerable<string> playerNames)
{
if(playerNames.Count() != _numberOfPlayers)
throw new ArgumentException(string.Format("Expected {0} player names.", playerNames));
var bank = new CardBank();
InitializeBank(bank);
var players = playerNames.Select(name => new Player(name, CreateStartingDeck()));
return new Game(players, bank, new TextGameLog());
}
public IEnumerable<ICard> CreateStartingDeck()
{
return 3.NewCards<Estate>().Concat(7.NewCards<Copper>());
}
private int VictoryCardCount
{
get { return (Math.Max(0, _numberOfPlayers - 4) * 3) + 12; }
}
private CardPile Copper
{
get { return new UnlimitedSupplyCardPile(() => new Copper()); }
}
private CardPile Silver
{
get { return new UnlimitedSupplyCardPile(() => new Silver()); }
}
private CardPile Gold
{
get { return new UnlimitedSupplyCardPile(() => new Gold()); }
}
private CardPile Estates
{
get { return new LimitedSupplyCardPile().WithNewCards<Estate>(VictoryCardCount); }
}
private CardPile Duchies
{
get { return new LimitedSupplyCardPile().WithNewCards<Duchy>(VictoryCardCount); }
}
private CardPile Provinces
{
get { return new LimitedSupplyCardPile().WithNewCards<Province>(VictoryCardCount); }
}
private CardPile Curses
{
get { return new LimitedSupplyCardPile().WithNewCards<Curse>(Math.Max(10, (_numberOfPlayers - 1) * 10)); }
}
private CardPile Potions
{
get { return new LimitedSupplyCardPile().WithNewCards<Potion>(20); }
}
public int GetStartingCount(string cardName)
{
var card = CardFactory.CreateCard(cardName);
return card is IVictoryCard ? 12 : 10;
}
}
}