Permalink
Browse files

Update Trade

  • Loading branch information...
Matthew Moore
Matthew Moore committed May 17, 2012
1 parent 5bd0589 commit 73bf8716b09147ed67c764242b6d4d60b1b705d3
@@ -312,41 +312,15 @@ private void frm_gameBoard_FormClosed(object sender, FormClosedEventArgs e)
private void frm_gameBoard_Paint(object sender, PaintEventArgs e)
{
- int wool = 0;
- int brick = 0;
- int wood = 0;
- int ore = 0;
- int grain = 0;
+ Dictionary<CardType, int> resources = new Dictionary<CardType, int>();
int yearOfPlenty = 0;
int monopoly = 0;
int roadBuilding = 0;
int soldier = 0;
int victoryPoint = 0;
if (_gameController.CurrentPlayer != null)
{
- foreach (CardType t in _gameController.CurrentPlayer.ResourceHand)
- {
- switch (t)
- {
- case CardType.Grain:
- grain++;
- break;
- case CardType.Wool:
- wool++;
- break;
- case CardType.Brick:
- brick++;
- break;
- case CardType.Ore:
- ore++;
- break;
- case CardType.Lumber:
- wood++;
- break;
- default:
- break;
- }
- }
+ resources = _gameController.CurrentPlayer.GetNumberOfResources();
foreach (CardType c in _gameController.CurrentPlayer.DevelopmentHand)
{
switch (c)
@@ -371,11 +345,11 @@ private void frm_gameBoard_Paint(object sender, PaintEventArgs e)
}
}
}
- lbl_playerBrick.Text = brick.ToString();
- lbl_playerWool.Text = wool.ToString();
- lbl_playerWood.Text = wood.ToString();
- lbl_playerGrain.Text = grain.ToString();
- lbl_playerOre.Text = ore.ToString();
+ lbl_playerBrick.Text = resources[CardType.Brick].ToString();
+ lbl_playerWool.Text = resources[CardType.Wool].ToString();
+ lbl_playerWood.Text = resources[CardType.Lumber].ToString();
+ lbl_playerGrain.Text = resources[CardType.Grain].ToString();
+ lbl_playerOre.Text = resources[CardType.Ore].ToString();
lbl_playerSoldier.Text = soldier.ToString();
lbl_playerMonopoly.Text = monopoly.ToString();
lbl_playerVictoryPoint.Text = roadBuilding.ToString();
@@ -718,7 +692,6 @@ private void btn_trade_Click(object sender, EventArgs e)
{
_context = Context.Trade;
var tradeWindow = new frm_Trade(_gameController);
- this.Hide();
tradeWindow.ShowDialog();
if (tradeWindow.DialogResult == DialogResult.Cancel || tradeWindow.DialogResult == DialogResult.Abort)
@@ -15,7 +15,8 @@ public Player()
ResourceHand = new List<CardType>();
}
- public Player(String name) : this()
+ public Player(String name)
+ : this()
{
Name = name;
}
@@ -99,7 +100,7 @@ public bool CanBuildCity()
var wheatCount = 0;
var oreCount = 0;
- foreach(var card in ResourceHand)
+ foreach (var card in ResourceHand)
{
if (card == CardType.Grain) wheatCount++;
if (card == CardType.Ore) oreCount++;
@@ -168,5 +169,47 @@ public void Buy(object toBuy)
throw new Exception("Unable to buy type given");
}
}
+
+ public Dictionary<CardType, int> GetNumberOfResources()
+ {
+ int wool = 0;
+ int brick = 0;
+ int wood = 0;
+ int ore = 0;
+ int grain = 0;
+ foreach (CardType t in ResourceHand)
+ {
+ switch (t)
+ {
+ case CardType.Grain:
+ grain++;
+ break;
+ case CardType.Wool:
+ wool++;
+ break;
+ case CardType.Brick:
+ brick++;
+ break;
+ case CardType.Ore:
+ ore++;
+ break;
+ case CardType.Lumber:
+ wood++;
+ break;
+ default:
+ break;
+ }
+ }
+ Dictionary<CardType, int> temp = new Dictionary<CardType, int>
+
+ {
+ {CardType.Brick, brick},
+ {CardType.Ore, ore},
+ {CardType.Grain, grain},
+ {CardType.Lumber, wood},
+ {CardType.Wool, wool}
+ };
+ return temp;
+ }
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -64,6 +64,16 @@
<Compile Include="GameController.cs" />
<Compile Include="Dice.cs" />
<Compile Include="Enumerations.cs" />
+ <Compile Include="Resources.de.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Resources.de.resx</DependentUpon>
+ </Compile>
+ <Compile Include="Resources1.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Resources.resx</DependentUpon>
+ </Compile>
<Compile Include="ResourceSelect.cs">
<SubType>Form</SubType>
</Compile>
@@ -93,16 +103,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
- <Compile Include="Resources.de.Designer.cs">
- <AutoGen>True</AutoGen>
- <DesignTime>True</DesignTime>
- <DependentUpon>Resources.de.resx</DependentUpon>
- </Compile>
- <Compile Include="Resources1.Designer.cs">
- <AutoGen>True</AutoGen>
- <DesignTime>True</DesignTime>
- <DependentUpon>Resources.resx</DependentUpon>
- </Compile>
<Compile Include="ScorePanel.cs">
<SubType>Component</SubType>
</Compile>
Oops, something went wrong.

0 comments on commit 73bf871

Please sign in to comment.