/
BuildUpPile.as
150 lines (111 loc) · 2.7 KB
/
BuildUpPile.as
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
//-----------------------
//Purpose:
//Properties:
//
//Methods:
//
//-----------------------
public class BuildUpPile extends CardStack
{
// Constants //
//- Constants -//
// Public Properties //
public override function get faceUp():Boolean
{
return true;
}
public function get suit():int
{
return _suit;
}
public function set suit(value:int):void
{
_suit = value;
}
//- Public Properties -//
// Private Properties //
private var _parent:GameController;
private var _suit:int;
//- Private Properties -//
// Initialization //
public function BuildUpPile(parent:GameController, suit:int)
{
_parent = parent;
_suit = suit;
}
//- Initialization -//
// Public Methods //
public function GetNextCardNeeded():Card
{
var iRank = 1 + _cards.length;
var oCard:Card = new Card(null, iRank, _suit);
return oCard;
}
public override function Paint():MovieClip
{
if (_cards.length == 0)
{
var mcStack:StackStart_MC = new StackStart_MC();
_container.addChild(mcStack);
var mcSuit:Suit_Standard_MC = new Suit_Standard_MC();
mcSuit.width = 50;
mcSuit.height = 50;
mcSuit.x = 0;
mcSuit.y = 40;
mcSuit.gotoAndStop(_suit);
_container.addChild(mcSuit);
_container.addEventListener(MouseEvent.CLICK, OnBuildUpPileClick, false, 0, true);
}
else
{
var iNumCardsToDraw:int = Math.floor(_cards.length / 5);
var iCardIndex:int = 4;
var iX:int = 0;
var iY:int = 0;
// base cards
for (var i:int = 0; i < iNumCardsToDraw; i++)
{
var oCard:Card = Card(_cards[iCardIndex]);
var mcCard:MovieClip = oCard.Paint(this.faceUp);
mcCard.x = iX;
mcCard.y = iY;
_cardGraphics.push(mcCard);
_container.addChild(mcCard);
iX -= 2;
iY -= 2;
iCardIndex += 5;
}
// top card
if (_cards.length % 5 != 0)
{
oCard = Card(_cards[_cards.length - 1]);
mcCard = oCard.Paint(this.faceUp);
mcCard.x = iX;
mcCard.y = iY;
_cardGraphics.push(mcCard);
_container.addChild(mcCard);
}
_container.removeEventListener(MouseEvent.CLICK, OnBuildUpPileClick);
}
return _container;
}
public function BuildUpPileClick():void
{
_parent.OnBuildUpPileClick(this);
}
//- Public Methods -//
// Private Methods //
private function OnBuildUpPileClick(event:MouseEvent):void
{
event.stopPropagation();
_parent.OnBuildUpPileClick(this);
}
//- Private Methods -//
// Testing Methods //
//- Testing Methods -//
}
}