最近在做斗地主扑克游戏的一些代码和思路

 

扑克游戏共54张牌,因此只创建了54个牌的实例,并且这些实例在整个应用中只创建一次,以节省内存,

背面牌创建了17*2个普通背面牌实例,17个地主背牌实例,17*2个农民背牌实例

因为会频繁的出牌,删牌

 

代码
1 /**
2 * set方法仅刷新位置
3 *
4 */
5 public function setPaiLeft(rivalUser:IUserModel,rivalChair:IChairModel):void
6 {
7 //loop use
8   var i:int = 0;
9 var numChild:int = (this.board.mc_pailist_v_left.mc_container as MovieClip).numChildren;
10
11 //clear
12   for(i=0;i<numChild;i++)
13 {
14 (this.board.mc_pailist_v_left.mc_container as MovieClip).removeChildAt(0);
15 }
16
17 //棋子
18   var arr:Array = GameGlobals.qpc.data.activeRoom.getItemList();
19
20 this.paiRule.sort(arr,rivalChair.getId());
21
22 var len:int = GameGlobals.qpc.data.activeRoom.getItemList().length;
23
24 for(i =0;i<len;i++)
25 {
26 h = rivalChair.getId()-1;
27
28 if(h == (arr[i] as ItemModelByDdz).h)//这是你的牌
29 {
30 var paiMc:MovieClip;
31
32 if(PokerName.BG_NORMAL == (arr[i] as ItemModelByDdz).name)
33 {
34 paiMc = this.bgPaiList_normal[ (arr[i] as ItemModelByDdz).v ] as MovieClip;
35
36 }else if(PokerName.BG_DIZHU == (arr[i] as ItemModelByDdz).name)
37 {
38 paiMc = this.bgPaiList_diZhu[ (arr[i] as ItemModelByDdz).v ] as MovieClip;
39
40 }else if(PokerName.BG_NONGMING == (arr[i] as ItemModelByDdz).name)
41 {
42 paiMc = this.bgPaiList_nongMing[ (arr[i] as ItemModelByDdz).v ] as MovieClip;
43
44 }else
45 {
46 //明牌
47 paiMc = this.paiRule.getFrontPaiMcByName((arr[i] as ItemModelByDdz).name);
48
49 }
50
51 //
52 paiMc.y = (arr[i] as ItemModelByDdz).v * PaiLayout.LIST_V_PADDING;
53
54 (this.board.mc_pailist_v_left.mc_container as MovieClip).addChild(paiMc);
55
56 }//end if
57 }//end for
58
59
60 }
61
62 public function setPaiRight(rivalUser:IUserModel,rivalChair:IChairModel):void
63 {
64 //loop use
65 var i:int = 0;
66 var numChild:int = (this.board.mc_pailist_v_right.mc_container as MovieClip).numChildren;
67
68 //clear
69 for(i=0;i<numChild;i++)
70 {
71 (this.board.mc_pailist_v_right.mc_container as MovieClip).removeChildAt(0);
72 }
73
74 //棋子
75 var arr:Array = GameGlobals.qpc.data.activeRoom.getItemList();
76
77 this.paiRule.sort(arr,rivalChair.getId());
78
79 var len:int = GameGlobals.qpc.data.activeRoom.getItemList().length;
80
81 for(var i:int =0;i<len;i++)
82 {
83 var cId:int = rivalChair.getId()-1;
84
85 if(cId == (arr[i] as ItemModelByDdz).h)//这是你的牌
86 {
87 var paiMc:MovieClip;
88
89 if(PokerName.BG_NORMAL == (arr[i] as ItemModelByDdz).name)
90 {
91 paiMc = this.bgPaiList_normal[ (arr[i] as ItemModelByDdz).v + 17 ] as MovieClip;
92
93 }else if(PokerName.BG_DIZHU == (arr[i] as ItemModelByDdz).name)
94 {
95 paiMc = this.bgPaiList_diZhu[ (arr[i] as ItemModelByDdz).v ] as MovieClip;//地主只有一家
96
97 }else if(PokerName.BG_NONGMING == (arr[i] as ItemModelByDdz).name)
98 {
99 paiMc = this.bgPaiList_nongMing[ (arr[i] as ItemModelByDdz).v + 17 ] as MovieClip;
100 }else
101 {
102 //明牌
103 paiMc = this.paiRule.getFrontPaiMcByName((arr[i] as ItemModelByDdz).name);
104 }
105
106 //
107 paiMc.y = (arr[i] as ItemModelByDdz).v * PaiLayout.LIST_V_PADDING;
108
109 (this.board.mc_pailist_v_right.mc_container as MovieClip).addChild(paiMc);
110
111 }//end if
112 }//end for
113
114
115 }
116
117 public function addPaiRight(rivalUser:IUserModel,rivalChair:IChairModel,curInd:int = -1):void
118 {
119 //棋子
120 var arr:Array = GameGlobals.qpc.data.activeRoom.getItemList();
121
122 this.paiRule.sort(arr,rivalChair.getId());
123
124 var len:int = GameGlobals.qpc.data.activeRoom.getItemList().length;
125
126
127
128 }
129
130 /**
131 * 出牌显示
132 */
133 public function setPaiDown2(value:Array):void
134 {
135 //loop use
136 var i:int = 0;
137 var len:int = value.length;
138
139 for(i=0;i<len;i++)
140 {
141 //
142 //x
143
144 (this.board.mc_pailist_h_down2.mc_container as MovieClip).addChild((value[i] as MovieClip));
145
146 }
147
148 }
149
150 //addEvt:Boolean=true
151 public function setPaiDown():void
152 {
153 //loop use
154 var i:int = 0;
155 var numChild:int = (this.board.mc_pailist_h_down.mc_container as MovieClip).numChildren;
156
157 //clear
158 for(i=0;i<numChild;i++)
159 {
160 var dobj:DisplayObject = (this.board.mc_pailist_h_down.mc_container as MovieClip).removeChildAt(0);
161
162 if(
163 (dobj as MovieClip).hasEventListener(MouseEvent.CLICK)
164 )
165 {
166 (dobj as MovieClip).removeEventListener(MouseEvent.CLICK,paiMcClick);
167 }
168
169 }
170
171 //add
172 var hero:IUserModel = GameGlobals.qpc.data.activeRoom.findHero(GameGlobals.qpc.data.hero);
173 var chair:IChairModel = GameGlobals.qpc.data.activeRoom.getChair(hero);
174
175 //棋子
176 var arr:Array = GameGlobals.qpc.data.activeRoom.getItemList();
177
178 this.paiRule.sort(arr,chair.getId());
179
180 var len:int = GameGlobals.qpc.data.activeRoom.getItemList().length;
181
182 for(i =0;i<len;i++)
183 {
184 var cId:int = chair.getId()-1;
185
186 if(cId == (arr[i] as ItemModelByDdz).h)//这是你的牌
187 {
188 var paiMc:MovieClip;
189
190 //自已的牌不会是背面牌
191 //因此这里去掉背面牌的逻辑
192 // 获取正面牌的MC
193 // 参数value 为 牌的名称
194 //
195 paiMc = this.paiRule.getFrontPaiMcByName((arr[i] as ItemModelByDdz).name);
196
197 //间隔为横向20
198 paiMc.x = (arr[i] as ItemModelByDdz).v * 20;
199
200 //事件侦听
201 paiMc.addEventListener(MouseEvent.CLICK,paiMcClick);
202
203 (this.board.mc_pailist_h_down.mc_container as MovieClip).addChild(paiMc);
204
205 }//end if
206 }//end for
207
208 }
209
210 //clear
211 for(i=0;i<numChild;i++)
212 {
213 var paiMc:MovieClip = (this.board.mc_pailist_h_down.mc_container as MovieClip).getChildAt(i) as MovieClip;
214
215 if(0 == paiMc.y)
216 {
217
218 }else
219 {
220 //paiMc.y = 0;//出牌后再设
221
222 var dj:MovieClip = (this.board.mc_pailist_h_down.mc_container as MovieClip).removeChildAt(i);
223
224 value.push(paiMc);
225
226 //restore
227 i=-1;
228 numChild = (this.board.mc_pailist_h_down.mc_container as MovieClip).numChildren;
229 }
230
231 }

 

posted on 2011-01-16 20:54  jiahuafu  阅读(704)  评论(0编辑  收藏  举报

导航