GoldFlowView.m 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  1. //
  2. // GoldFlowView.m
  3. // GoldenFlowerDemo
  4. //
  5. // Created by GuoMs on 16/11/17.
  6. // Copyright © 2016年 zcd. All rights reserved.
  7. //
  8. #import "GoldFlowView.h"
  9. #import "PokerStr.h"
  10. #import "THLabel.h"
  11. #define space 10
  12. #define pokerY 5
  13. #define pokerH 93
  14. NS_ENUM(NSInteger, LicensingPosition)
  15. {
  16. LicensingPosition_Left = 4, // 发牌到最左边第一张位置
  17. LicensingPosition_Between, // 发牌到中间第二张位置
  18. LicensingPosition_Right, // 发牌到最右边第三张位置
  19. };
  20. NS_ENUM(NSInteger, LotPokerPosition)
  21. {
  22. LotPokerPosition_Left = 1, // 发牌到最左边
  23. LotPokerPosition_Between, // 发牌到中间
  24. LotPokerPosition_Right, // 发牌到最右边
  25. };
  26. @interface GoldFlowView()
  27. @end
  28. @implementation GoldFlowView
  29. - (void)dealloc
  30. {
  31. [[NSNotificationCenter defaultCenter] removeObserver:self];
  32. [self closeGameAboutTimer];
  33. if (_showPokerTimer) {
  34. [_showPokerTimer invalidate];
  35. _showPokerTimer = nil;
  36. }
  37. }
  38. - (instancetype)initWithFrame:(CGRect)frame withBetArray:(NSArray *)betArray withIsHost:(BOOL ) isHost
  39. {
  40. if (self = [super initWithFrame:frame]) {
  41. _httpManager = [NetHttpsManager manager];
  42. _BuguLive = [GlobalVariables sharedInstance];
  43. [self updateCoinWithID:nil];
  44. // self.backgroundColor = kGrayTransparentColor4_1;
  45. self.backgroundColor = [UIColor clearColor];
  46. _isHost = isHost;
  47. if (!_coinMoveArray) {
  48. _coinMoveArray = [[NSMutableArray alloc]init];
  49. _coinBtnArray = [[NSMutableArray alloc]init];
  50. _coinBeignArray = [[NSMutableArray alloc]init];
  51. _betViewArray = [[NSMutableArray alloc]init];
  52. _breathImgArray = [[NSMutableArray alloc]init];
  53. _betMoneyLabArray = [[NSMutableArray alloc]init];
  54. self.betOptionArray = betArray;
  55. }
  56. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateCoin) name:@"updateCoin" object:nil];
  57. _animationIMG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20+2*kPokerH+15)];
  58. // _animationIMG.image = [UIImage imageNamed:@"gm_bet_tables"];
  59. _animationIMG.backgroundColor = kGrayTransparentColor4_1;
  60. if (_isHost)
  61. {
  62. _animationIMG.userInteractionEnabled = NO;
  63. }
  64. [self addSubview:_animationIMG];
  65. [self createCoinView];
  66. _isStartOpenCard = NO;//是否开牌赋初始值
  67. _isStopAnimation = NO;
  68. _canCloseGame = YES;
  69. }
  70. return self;
  71. }
  72. - (void)setIsArc:(BOOL)isArc
  73. {
  74. _isArc = isArc;
  75. NSString * imageStr = isArc ? @"gm_game_arcBtn" : @"gm_game_mrcBtn";
  76. [_arcOrMrcGameView.betBtn setBackgroundImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
  77. }
  78. #pragma mark -- 游戏准备
  79. - (void)gameToPrepareTypeGoldenFlowerOrBull:(NSString *)type card:(NSArray *)card{
  80. NSLog(@"%@",type);
  81. [self creatPokerhiden:YES gameType:type card:card];//炸金花or斗牛,德州扑克
  82. [self creatBetAmount:YES type:type];
  83. [self beAbleToLicensingType:type];
  84. }
  85. #pragma mark -- 即将发牌等待中
  86. - (void)beAbleToLicensingType:(NSString *)type{
  87. //隐藏遮罩
  88. self.firstView.hidden = YES;
  89. self.secondView.hidden = YES;
  90. self.thirdView.hidden = YES;
  91. if (!_willStartIMG) {
  92. _willStartIMG = [UIImageView new];
  93. }
  94. _willStartIMG.frame = CGRectMake(80, 40, [UIScreen mainScreen].bounds.size.width - 160, 26);
  95. [self.animationIMG addSubview:_willStartIMG];
  96. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  97. [self licensingGameTypeGoldenFlowerOrBull:type];
  98. });
  99. }
  100. - (void)createCoinView
  101. {
  102. if (!_coinView)
  103. {
  104. _coinView = [CoinView EditNibFromXib];
  105. //_coinView.gameRechargeView.userInteractionEnabled = YES;
  106. _coinView.frame = CGRectMake(0, 20+2*kPokerH+15, kScreenW, 40);
  107. _coinView.backgroundColor = kGrayTransparentColor5;
  108. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(recharge)];
  109. [_coinView.gameRechargeView.backGroundView addGestureRecognizer:tap];
  110. [self addSubview:_coinView];
  111. // 金币余额的中心位置
  112. _coinPoint = CGPointMake(17.5, 40+2*kPokerH);
  113. }
  114. [self createBetView];
  115. }
  116. #pragma mark 创建押注金额视图
  117. - (void)createBetView
  118. {
  119. //押注的金额视图
  120. if (!_isHost) {
  121. if (!_betView) {
  122. for (int i = 0; i < self.betOptionArray.count; i++) {
  123. _betView = [BetView EditNibFromXib];
  124. _betView.delegate = self;
  125. _betView.backgroundColor = [UIColor clearColor];
  126. _betView.frame = CGRectMake((kScreenW -180) + i*(betButtonInterval +betButtonWidth), 0, 40, 40);
  127. _betView.betBtn.tag = i+200;
  128. if (_betOptionArray.count > 0)
  129. {
  130. [_betView.betBtn setTitle:[NSString stringWithFormat:@"%@",[self.betOptionArray objectAtIndex:i]] forState:UIControlStateNormal];
  131. }
  132. [_betView.betBtn setBackgroundImage:[UIImage imageNamed:@"gm_selectedBet"] forState:UIControlStateNormal];
  133. [_betView.betBtn setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  134. if (i == 0) {
  135. //获取betView在当前视图的位置
  136. _amountPoint = [_coinView convertPoint:_betView.center toView:self];
  137. _betMoney = [NSString stringWithFormat:@"%@",[self.betOptionArray objectAtIndex:0]];
  138. [_betView.betBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
  139. // //加上呼吸灯动画
  140. // _betView.breathImg.image = [UIImage imageNamed:@"gm_coin_breath"];
  141. // [_betView.breathImg.layer addAnimation:[CAAnimation AlphaLight:1.0f fromValue:1.0f toValue:0.4f] forKey:@"alpha"];
  142. }
  143. else if (i == 1)
  144. {
  145. [_betView.betBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
  146. }
  147. else if (i == 2)
  148. {
  149. [_betView.betBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:9]];
  150. }
  151. else
  152. {
  153. [_betView.betBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:8]];
  154. }
  155. // _betView.betBtn.userInteractionEnabled = NO;
  156. // _betView.betBtn.alpha = 0.3;
  157. BOOL isSelected = i == _betCount ? YES : NO;
  158. [self setBetBtnWithIsSelected:isSelected andBtn:_betView.betBtn];
  159. //将控件存入数组中
  160. [_coinBtnArray addObject:_betView.betBtn];
  161. [_breathImgArray addObject:_betView.breathImg];
  162. [_betViewArray addObject:_betView];
  163. //将押注的开始位置保存起来
  164. [_coinBeignArray addObject:[NSValue valueWithCGPoint:_betView.center]];
  165. [_coinView addSubview:_betView];
  166. }
  167. }
  168. }
  169. //历史记录
  170. if (!_historyView) {
  171. _historyView = [BetView EditNibFromXib];
  172. _historyView.delegate = self;
  173. if (_isHost) {
  174. _historyView.frame = CGRectMake((kScreenW - 180)+3*(betButtonInterval +betButtonWidth), 0, 40, 40);
  175. }
  176. else
  177. {
  178. _historyView.frame = CGRectMake((kScreenW - 180)+4*(betButtonInterval +betButtonWidth), 0, 40, 40);
  179. }
  180. _historyView.betBtn.tag = 204;
  181. [_historyView.betBtn setBackgroundImage:[UIImage imageNamed:@"gm_history"] forState:UIControlStateNormal];
  182. [_coinView addSubview:_historyView];
  183. //将控件存入入数组中
  184. [_coinBtnArray addObject:_historyView.betBtn];
  185. [_breathImgArray addObject:_historyView.breathImg];
  186. [_betViewArray addObject:_historyView];
  187. }
  188. if (_isHost) {
  189. //游戏结束
  190. if (!_gameOverView) {
  191. _gameOverView = [BetView EditNibFromXib];
  192. _gameOverView.delegate = self;
  193. _gameOverView.frame = CGRectMake((kScreenW -180)+4*(betButtonInterval +betButtonWidth), 0, 40, 40);
  194. _gameOverView.betBtn.tag = 205;
  195. [_gameOverView.betBtn setBackgroundImage:[UIImage imageNamed:@"gm_game_closeBtn"] forState:UIControlStateNormal];
  196. [_coinView addSubview:_gameOverView];
  197. //将控件存入入数组中
  198. [_coinBtnArray addObject:_gameOverView.betBtn];
  199. [_breathImgArray addObject:_gameOverView.breathImg];
  200. [_betViewArray addObject:_gameOverView];
  201. }
  202. //手动发牌与自动发牌
  203. if (!_arcOrMrcGameView && kSupportArcGame) {
  204. _arcOrMrcGameView = [BetView EditNibFromXib];
  205. _arcOrMrcGameView.delegate = self;
  206. _arcOrMrcGameView.frame = CGRectMake((kScreenW -180)+2*(betButtonInterval +betButtonWidth), 0, 40, 40);
  207. _arcOrMrcGameView.betBtn.tag = 206;
  208. [_arcOrMrcGameView.betBtn setBackgroundImage:[UIImage imageNamed:@"gm_game_mrcBtn"] forState:UIControlStateNormal];
  209. [_coinView addSubview:_arcOrMrcGameView];
  210. //将控件存入入数组中
  211. [_coinBtnArray addObject:_arcOrMrcGameView.betBtn];
  212. [_breathImgArray addObject:_arcOrMrcGameView.breathImg];
  213. [_betViewArray addObject:_arcOrMrcGameView];
  214. }
  215. }
  216. }
  217. - (void)setBetBtnWithIsSelected:(BOOL )isSelected andBtn:(UIButton *)button
  218. {
  219. if (isSelected) {
  220. [button setBackgroundImage:[UIImage imageNamed:@"gm_selectedBet"] forState:UIControlStateNormal];
  221. [button setTitleColor:kColorWithStr(@"fbeda5") forState:UIControlStateNormal];
  222. }
  223. else
  224. {
  225. [button setBackgroundImage:[UIImage imageNamed:@"gm_normalBet"] forState:UIControlStateNormal];
  226. [button setTitleColor:kWhiteColor forState:UIControlStateNormal];
  227. }
  228. }
  229. #pragma mark -------------------------发牌动画----------------------------
  230. #pragma mark -- 正在发牌中
  231. - (void)licensingGameTypeGoldenFlowerOrBull:(NSString *)type{
  232. _movingIMG.hidden = NO;//显示下面发牌的位置
  233. [self.pokerArray removeAllObjects];
  234. [self.animationArray removeAllObjects];
  235. _count = 0;
  236. if (_isHost == NO) {
  237. _canBet = NO;
  238. _animationIMG.userInteractionEnabled = _canBet;
  239. }
  240. //发牌方法一
  241. // 将九扑克加到数组中(咋金花)
  242. if ([type isEqualToString:@"1"]) {
  243. for (int i=0; i<3; ++i){
  244. [self.pokerArray addObject:[self.smallArray[i] pokerOne]];
  245. [self.pokerArray addObject:[self.smallArray[i] pokerTwo]];
  246. [self.pokerArray addObject:[self.smallArray[i] pokerThree]];
  247. }
  248. for (int i=0; i<self.pokerArray.count; ++i) {
  249. [self playVoiceWithNumber:1.5];
  250. [self.animationArray addObject:[self drawTrajectoryWithPokerView:self.smallArray[i/3] imageView:self.pokerArray[i] andBeginTime:i*0.2]];
  251. }
  252. }else if ([type isEqualToString:@"2"]){// 将15扑克加到数组中(斗牛)
  253. for (int i=0; i<3; i++) {
  254. [self.pokerArray addObject:[self.smallArray[i] BullPokerOne]];
  255. [self.pokerArray addObject:[self.smallArray[i] BullPokerTwo]];
  256. [self.pokerArray addObject:[self.smallArray[i] BullPokerThree]];
  257. [self.pokerArray addObject:[self.smallArray[i] BullPokerFour]];
  258. [self.pokerArray addObject:[self.smallArray[i] BullPokerFive]];
  259. }
  260. for (int i=0; i<self.pokerArray.count; ++i) {
  261. [self playVoiceWithNumber:2.5];
  262. [self.animationArray addObject:[self drawTrajectoryWithPokerView:self.smallArray[i/5] imageView:self.pokerArray[i] andBeginTime:i*0.2]];
  263. }
  264. }else if ([type isEqualToString:@"3"]){//德州扑克
  265. for (int i=0; i<3; i++) {
  266. if (i==0) {
  267. [self.pokerArray addObject:[self.smallArray[i] texasLeftAndRightOne]];
  268. [self.pokerArray addObject:[self.smallArray[i] texasLeftAndRightTwo]];
  269. }else if (i==1){
  270. [self.pokerArray addObject:[self.smallArray[i] texasPokerOne]];
  271. [self.pokerArray addObject:[self.smallArray[i] texasPokerTwo]];
  272. [self.pokerArray addObject:[self.smallArray[i] texasPokerThree]];
  273. [self.pokerArray addObject:[self.smallArray[i] texasPokerFour]];
  274. [self.pokerArray addObject:[self.smallArray[i] texasPokerFive]];
  275. }else if (i==2){
  276. [self.pokerArray addObject:[self.smallArray[i] texasLeftAndRightOne]];
  277. [self.pokerArray addObject:[self.smallArray[i] texasLeftAndRightTwo]];
  278. }
  279. }
  280. for (int i=0; i<self.pokerArray.count; ++i) {
  281. [self playVoiceWithNumber:1.5];
  282. if (i<2) {//左边两张牌的动画
  283. [self.animationArray addObject:[self drawTrajectoryWithPokerView:self.smallArray[0] imageView:self.pokerArray[i] andBeginTime:i*0.2]];
  284. }else if (i >= 2 && i < 7){//中间的五张牌
  285. [self.animationArray addObject:[self drawTrajectoryWithPokerView:self.smallArray[1] imageView:self.pokerArray[i] andBeginTime:i*0.2]];
  286. }else if (i >= 7){//右边的两张牌
  287. [self.animationArray addObject:[self drawTrajectoryWithPokerView:self.smallArray[2] imageView:self.pokerArray[i] andBeginTime:i*0.2]];
  288. }
  289. }
  290. }
  291. //发牌方法二
  292. // for (int i=0; i<3; ++i) {
  293. // if (i== 0) {
  294. // for (int j=0; j<3; ++j) {
  295. // [self.pokerArray addObject:[self.smallArray[j] pokerOne]];
  296. // }
  297. // }
  298. // else if (i== 1) {
  299. // for (int j=0; j<3; ++j) {
  300. // [self.pokerArray addObject:[self.smallArray[j] pokerTwo]];
  301. // }
  302. // }
  303. // else if (i== 2)
  304. // {
  305. // for (int j=0; j<3; ++j) {
  306. // [self.pokerArray addObject:[self.smallArray[j] pokerThree]];
  307. // }
  308. // }
  309. // }
  310. // for (int i=0; i<self.pokerArray.count; ++i) {
  311. // //添加发牌音效
  312. // NSString *filePath = [[NSBundle mainBundle]pathForResource:@"dealsound" ofType:@"mp3"];
  313. // NSURL *url= [NSURL URLWithString:filePath];
  314. // _audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
  315. // _audioPlayer.numberOfLoops = 4;
  316. // [_audioPlayer play];
  317. // [self.animationArray addObject:[self drawTrajectoryWithPokerView:self.smallArray[i%3] imageView:self.pokerArray[i] andBeginTime:i*0.2]];
  318. // }
  319. _groupAntimation = [CAAnimationGroup animation];
  320. _groupAntimation.animations = self.animationArray;
  321. _groupAntimation.duration = 0.2*self.animationArray.count;
  322. _groupAntimation.delegate = self;
  323. [_groupAntimation setValue:@"groupAnimation" forKey:@"animationName"];
  324. [_movingIMG.layer addAnimation:_groupAntimation forKey:nil];
  325. if (_prokerTimer == nil) {
  326. _prokerTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(closeHide) userInfo:nil repeats:YES];
  327. }
  328. }
  329. #pragma mark -- 发牌音效
  330. - (void)playVoiceWithNumber:(float) number{
  331. //添加发牌音效
  332. NSString *filePath = [[NSBundle mainBundle]pathForResource:@"dealsound" ofType:@"mp3"];
  333. NSURL *url= [NSURL URLWithString:filePath];
  334. _audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
  335. _audioPlayer.numberOfLoops = number;
  336. [_audioPlayer play];
  337. }
  338. #pragma mark -- 关闭发牌音效
  339. - (void)closeVideo{
  340. [_audioPlayer pause];
  341. }
  342. - (void)closeHide
  343. {
  344. if (_count>self.pokerArray.count-1) {
  345. [_prokerTimer invalidate];
  346. _prokerTimer = nil;
  347. _groupAntimation = nil;
  348. return;
  349. }
  350. UIImageView * proker = self.pokerArray[_count];
  351. proker.hidden = NO;
  352. _count++;
  353. }
  354. - (void)endAnmination
  355. {
  356. [_animationIMG.layer removeAllAnimations];
  357. if (_groupAntimation) {
  358. _groupAntimation = nil;
  359. }
  360. [self closeVideo];
  361. if (_prokerTimer) {
  362. [_prokerTimer invalidate];
  363. _prokerTimer = nil;
  364. }
  365. for (UIImageView * poker in _pokerArray) {
  366. poker.hidden = NO;
  367. }
  368. }
  369. #pragma mark -- 画发牌的运动轨迹
  370. -(CAAnimationGroup *)drawTrajectoryWithPokerView:(PokerView *)pokerView imageView:(UIImageView *)imageView andBeginTime:(float) antionBegintime{
  371. //获取发牌的起始位置
  372. PokerDownView *pokerDownView = [self.animationIMG viewWithTag:LotPokerPosition_Between];
  373. //动态计算开始位置与起始位置
  374. CGRect pokerOneFrame = CGRectMake(imageView.frame.origin.x + pokerView.frame.origin.x, imageView.frame.origin.y + pokerView.frame.origin.y,imageView.frame.size.width, imageView.frame.size.height) ;
  375. CGRect movingIMGFrame = CGRectMake(_movingIMG.frame.origin.x + pokerDownView.frame.origin.x, _movingIMG.frame.origin.y + pokerDownView.frame.origin.y, _movingIMG.frame.size.height, _movingIMG.frame.size.width);
  376. //移动横向位置
  377. CABasicAnimation *basicAnimationx = [CABasicAnimation animationWithKeyPath: @"position.x"];
  378. basicAnimationx.fromValue = @(_movingIMG.frame.origin.x);
  379. basicAnimationx.toValue = @(pokerOneFrame.origin.x - movingIMGFrame.origin.x);
  380. //移动纵向位置
  381. CABasicAnimation *basicAnimationy = [CABasicAnimation animationWithKeyPath: @"position.y"];
  382. basicAnimationy.fromValue = @(_movingIMG.frame.origin.y);
  383. basicAnimationy.toValue = @(pokerOneFrame.origin.y - movingIMGFrame.origin.y + 45);
  384. //移动中的放大过程
  385. CAKeyframeAnimation *scaleFrom = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
  386. scaleFrom.values = @[@990];
  387. //添加组动画
  388. CAAnimationGroup * group = [CAAnimationGroup animation];
  389. group.beginTime = antionBegintime;
  390. group.fillMode = kCAFillModeForwards;
  391. group.removedOnCompletion = NO;
  392. group.duration = 0.2;
  393. group.animations = @[scaleFrom,basicAnimationx,basicAnimationy];
  394. return group;
  395. }
  396. #pragma mark -- 发牌结束操作
  397. //主播
  398. - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
  399. if (flag){
  400. NSString *animationName = [anim valueForKey:@"animationName"];
  401. if ([animationName isEqualToString:@"groupAnimation"])
  402. {
  403. PokerDownView *pokerDownView = self.betImageArray[1];
  404. pokerDownView.lotPokerIMG.hidden = YES;
  405. pokerDownView.amountBetLable.hidden = NO;
  406. _willStartIMG.hidden = _isHost ? YES : NO;
  407. _willStartIMG.image = [UIImage imageNamed:@"gm_xzxyqy"];
  408. _isStopAnimation = YES;
  409. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  410. _timeLable.hidden = NO;//显示倒计时控件
  411. _alarmClock.hidden = NO;
  412. _willStartIMG.hidden = YES;
  413. if (!_isHost && !_banker)
  414. {
  415. _animationIMG.userInteractionEnabled = YES;
  416. }
  417. else if (!_isHost && _banker)
  418. {
  419. _animationIMG.userInteractionEnabled = NO;
  420. }
  421. });
  422. }
  423. }
  424. }
  425. #pragma mark -------------------------开牌倒计时----------------------------
  426. #pragma mark -- 倒计时(观众与主播通过getVideo接口获取游戏信息时调用)
  427. - (void)timeCountDown:(int)time{
  428. PokerDownView *pokerDownView = [_animationIMG viewWithTag:LotPokerPosition_Between];
  429. pokerDownView.lotPokerIMG.hidden = YES;
  430. pokerDownView.amountBetLable.hidden = NO;
  431. _willStartIMG.hidden = _isHost ? YES : NO;
  432. _willStartIMG.image = [UIImage imageNamed:@"gm_xzxyqy"];
  433. _timeLable.hidden = NO;//显示倒计时控件
  434. _alarmClock.hidden = NO;
  435. _timeLable.text = [NSString stringWithFormat:@"%02d",time];
  436. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  437. _willStartIMG.hidden = YES;
  438. [self overPokerKJTime:time];
  439. });
  440. }
  441. #pragma mark -- 发牌结束进入倒计时操作(主播端)
  442. - (void)overPokerKJTime:(int)time{
  443. _timeLable.text = [NSString stringWithFormat:@"%02d",time];
  444. __block int timeout = time; //倒计时时间的设定秒数
  445. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  446. _gameTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
  447. dispatch_source_set_timer(_gameTimer,dispatch_walltime(NULL, 0),1.0 *NSEC_PER_SEC, 0); //每秒执行
  448. dispatch_source_set_event_handler(_gameTimer, ^{
  449. if(timeout <= 0){ //倒计时结束,关闭
  450. [self cancelTimer];
  451. }else{
  452. dispatch_async(dispatch_get_main_queue(), ^{
  453. timeout--;
  454. if (timeout == 1) {
  455. _compareImg = [[UIImageView alloc]initWithFrame:CGRectMake(_animationIMG.frame.size.width / 2 - 60, _animationIMG.frame.size.height / 3, 120, 20)];//比牌开始控件
  456. _compareImg.hidden = YES;
  457. [_animationIMG addSubview:_compareImg];
  458. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  459. _compareImg.hidden = NO;
  460. self.compareImg.image = [UIImage imageNamed:@"gm_bpks"];
  461. [UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.1 initialSpringVelocity:10 options: UIViewAnimationOptionCurveLinear animations:^{
  462. self.compareImg.center = CGPointMake(self.compareImg.center.x, self.compareImg.center.y + 20);
  463. } completion:^(BOOL finished) {
  464. self.compareImg.center = CGPointMake(self.compareImg.center.x, self.compareImg.center.y - 20);
  465. self.compareImg.hidden = YES;
  466. }];
  467. });
  468. }
  469. //小于1秒的时候
  470. if (timeout < 1) {
  471. if (!_isHost) {
  472. _animationIMG.userInteractionEnabled = NO;
  473. }
  474. _isStartOpenCard = YES;//开牌比较大小
  475. _timeLable .hidden = YES;//当倒计时为1时候隐藏倒计时的控件,否则显示该控件
  476. _alarmClock.hidden = YES;;
  477. [self addTimer];
  478. }else{
  479. _timeLable.text = [NSString stringWithFormat:@"%02d",timeout];
  480. }
  481. });
  482. }
  483. });
  484. dispatch_resume(_gameTimer);
  485. }
  486. - (void)cancelTimer
  487. {
  488. dispatch_source_cancel(_gameTimer);
  489. _gameTimer = nil;
  490. dispatch_async(dispatch_get_main_queue(), ^{
  491. });
  492. }
  493. - (void)closeGameAboutTimer
  494. {
  495. if (_prokerTimer) {
  496. [_prokerTimer invalidate];
  497. _prokerTimer = nil;
  498. }
  499. if (_gameTimer) {
  500. dispatch_source_cancel(_gameTimer);
  501. _gameTimer = nil;
  502. dispatch_async(dispatch_get_main_queue(), ^{
  503. });
  504. }
  505. }
  506. - (void)addTimer
  507. {
  508. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  509. if (_delegate && [_delegate respondsToSelector:@selector(reloadGameData)]) {
  510. [_delegate reloadGameData];
  511. }
  512. });
  513. }
  514. #pragma mark -------------------------比较大小----------------------------
  515. #pragma mark -- 开牌比较大小(进入直播间,已经开牌的情况)
  516. - (void)startOpenCard2:(NSDictionary *)leftdic between2:(NSDictionary *)betweendic rigth2:(NSDictionary *)rigthdic andResult:(NSInteger )result{
  517. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  518. [self startOpenCard:leftdic andPokerView:self.smallArray[0]];
  519. [self startOpenCard:betweendic andPokerView:self.smallArray[1]];
  520. [self startOpenCard:rigthdic andPokerView:self.smallArray[2]];
  521. if (![self.game_id isEqualToString:@"3"]) {
  522. [self winOrLoseWithReultInt:result];//显示输赢的遮罩
  523. }
  524. //每次比牌结束清空下注数据
  525. [self.betArr removeAllObjects];
  526. [self.userBetArr removeAllObjects];
  527. });
  528. }
  529. - (void)showPokerWithData:(NSArray *)dataPoker andResult:(NSString * )result
  530. {
  531. _dic = @{@"dataPoker":dataPoker,@"pokerResult":result};
  532. if (_showPokerTimer) {
  533. [_showPokerTimer invalidate];
  534. _showPokerTimer = nil;
  535. }
  536. _showPokerTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showPokerQuicklyWithPokerData) userInfo:nil repeats:NO];
  537. }
  538. - (void)showPokerQuicklyWithPokerData
  539. {
  540. _showPokerTimer = nil;
  541. if (self.gameAction == 4)
  542. {
  543. [self startOpenCard:_dic[@"dataPoker"][0] andPokerView:self.smallArray[0]];
  544. [self startOpenCard:_dic[@"dataPoker"][1] andPokerView:self.smallArray[1]];
  545. [self startOpenCard:_dic[@"dataPoker"][2] andPokerView:self.smallArray[2]];
  546. }
  547. if (![self.game_id isEqualToString:@"3"])
  548. {
  549. [self winOrLoseWithReultInt:[_dic toInt:@"pokerResult"]];//显示输赢的遮罩
  550. }
  551. //每次比牌结束清空下注数据
  552. [self.betArr removeAllObjects];
  553. [self.userBetArr removeAllObjects];
  554. }
  555. #pragma mark -- 开牌比较大小
  556. - (void)startOpenCard:(NSDictionary *)leftdic between:(NSDictionary *)betweendic rigth:(NSDictionary *)rigthdic andResult:(NSInteger )result gameId:(id)gameid{
  557. // if ([gameid isEqualToString:@"3"]) {
  558. //
  559. // }
  560. //第一副牌的显示
  561. if (self.gameAction == 4)
  562. {
  563. [self startOpenCard:leftdic andPokerView:self.smallArray[0]];
  564. }
  565. //第二副牌的显示
  566. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  567. if (self.gameAction == 4)
  568. {
  569. [self startOpenCard:betweendic andPokerView:self.smallArray[1]];
  570. }
  571. });
  572. //第三副牌显示
  573. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  574. if (self.gameAction == 4)
  575. {
  576. [self startOpenCard:rigthdic andPokerView:self.smallArray[2]];
  577. }
  578. });
  579. //显示三副牌的遮罩效果
  580. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  581. if (![gameid isEqualToString:@"3"])
  582. {
  583. [self winOrLoseWithReultInt:result];//显示输赢的遮罩
  584. }
  585. //每次比牌结束清空下注数据
  586. [self.betArr removeAllObjects];
  587. [self.userBetArr removeAllObjects];
  588. });
  589. }
  590. #pragma mark -- 比较大小,输赢牌的遮罩
  591. - (void)winOrLoseWithReultInt:(NSInteger )result
  592. {
  593. if (self.gameAction == 4) {
  594. if (result == 1) {
  595. self.firstView.hidden = YES;
  596. }else{
  597. self.firstView.hidden = NO;
  598. }
  599. if (result == 2) {
  600. self.secondView.hidden = YES;
  601. }else{
  602. self.secondView.hidden = NO;
  603. }
  604. if (result == 3) {
  605. self.thirdView.hidden = YES;
  606. }else{
  607. self.thirdView.hidden = NO;
  608. }
  609. }
  610. else
  611. {
  612. self.firstView.hidden = YES;
  613. self.secondView.hidden = YES;
  614. self.thirdView.hidden = YES;
  615. }
  616. }
  617. #pragma mark -- 直接展示全部牌
  618. - (void)openCardWith:(NSArray *)gameDataArray
  619. {
  620. if (gameDataArray.count == self.smallArray.count ) {
  621. for (int i=0; i<gameDataArray.count; ++i) {
  622. [self startOpenCard:gameDataArray[i] andPokerView:self.smallArray[i]];
  623. }
  624. }
  625. }
  626. #pragma mark -- 比较大小
  627. - (void)startOpenCard:(NSDictionary *)dic andPokerView:(id)pokerView
  628. {
  629. NSArray * arr = dic[@"cards"];
  630. if (arr.count>0) {
  631. NSString *pokerType =[PokerStr exchanegeGoldFlowerOrBullResultFromResultType:[dic[@"type"] intValue] goldFlowerOrBull:pokerView];//显示这张牌的类型
  632. [PokerStr aboutClassOfPokerOrBullPoker:pokerView dict:dic typeIMG:pokerType];
  633. }
  634. }
  635. #pragma mark -------------------------炸金花/斗牛/德州扑克视图创建----------------------------
  636. #pragma mark -- 创建扑克牌视图(炸金花or斗牛type:1炸金花,2斗牛)
  637. - (void)creatPokerhiden:(BOOL)hiden gameType:(NSString *)type card:(NSArray *)card{
  638. [self.smallArray removeAllObjects];
  639. [self.animationIMG.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  640. for (int i = 0; i < 3; i ++) {
  641. if ([type isEqualToString:@"1"]) {//炸金花判断
  642. [self creatFolwerGoldenPoker:i hiden:hiden];
  643. }else if ([type isEqualToString:@"2"]){//斗牛判断
  644. [self creatBullPoker:i hiden:hiden];
  645. }else if ([type isEqualToString:@"3"]){//德州扑克
  646. [self creatTexasPoker:i hiden:hiden card:card];
  647. }
  648. }
  649. //倒计时显示设置
  650. _alarmClock = [[UIImageView alloc]init];
  651. _alarmClock.image = [UIImage imageNamed:@"gm_clock"];
  652. _alarmClock.frame = CGRectMake((kScreenW-41)/2.0, kPokerH-20 , 41, 41);
  653. [self.animationIMG addSubview:_alarmClock];
  654. _alarmClock.hidden = YES;
  655. _timeLable = [[UILabel alloc]initWithFrame:CGRectMake(8, 10, 25,25)];
  656. _timeLable.textAlignment = NSTextAlignmentCenter;
  657. _timeLable.layer.masksToBounds = YES;
  658. _timeLable.layer.cornerRadius = 25.0 / 2;
  659. _timeLable.hidden = YES;//隐藏显示的倒计时
  660. _timeLable.textColor = kColorWithStr(@"fff3e1");
  661. //_timeLable.font = [UIFont fontWithName:@"GillSans-Bold" size:17];
  662. _timeLable.font = [UIFont systemFontOfSize:15];
  663. [_alarmClock addSubview: _timeLable];
  664. }
  665. #pragma mark -- 炸金花
  666. - (void)creatFolwerGoldenPoker:(int)a hiden:(BOOL)hiden{
  667. _pokerView = [[NSBundle mainBundle]loadNibNamed:@"PokerView" owner:self options:nil].lastObject;
  668. _pokerView.frame = CGRectMake(10 * (a + 1) + pokerW * a, pokerY, pokerW, kPokerH);
  669. [_pokerView hidenPoker:hiden];//隐藏所有的牌
  670. [self.animationIMG addSubview:_pokerView];
  671. [self.smallArray addObject:_pokerView];
  672. }
  673. #pragma mark -- 斗牛
  674. - (void)creatBullPoker:(int)a hiden:(BOOL)hiden{
  675. _bullPokerView = [[NSBundle mainBundle]loadNibNamed:@"BullPoker" owner:self options:nil].lastObject;
  676. _bullPokerView.frame = CGRectMake(10 * (a + 1) + pokerW * a, pokerY, pokerW, kPokerH);
  677. [_bullPokerView hidenBullPoker:hiden];//隐藏所有的牌
  678. [self.animationIMG addSubview:_bullPokerView];
  679. [self.smallArray addObject:_bullPokerView];
  680. }
  681. #pragma mark -- 德州扑克
  682. - (void)creatTexasPoker:(int)a hiden:(BOOL)hiden card:(NSArray *)card{
  683. if (a == 0) {//德州扑克左边两张牌
  684. _texasLR = [[NSBundle mainBundle]loadNibNamed:@"TexasPokerLeftAndRight" owner:self options:nil].lastObject;
  685. _texasLR.frame = CGRectMake(10 * (a + 1) + kTexasSmallWidth * a, pokerY, kTexasSmallWidth, kPokerH);
  686. [_texasLR hidenTexasPoker:hiden];
  687. [self.animationIMG addSubview:_texasLR];
  688. [self.smallArray addObject:_texasLR];
  689. }else if (a == 1){//德州扑克中间5张牌
  690. _texasBetween = [[NSBundle mainBundle]loadNibNamed:@"TexasPokerBetween" owner:self options:nil].lastObject;
  691. _texasBetween.frame = CGRectMake(10 * (a + 1) + kTexasSmallWidth, pokerY, KtexasBigWidth, kPokerH);
  692. [_texasBetween hidenTexasPoker:hiden];//隐藏所有的牌
  693. [self.animationIMG addSubview:_texasBetween];
  694. [self.smallArray addObject:_texasBetween];
  695. if (card.count > 0) {
  696. // _bullPokerView.playingCardView = [[NSBundle mainBundle]loadNibNamed:@"PlayingCardView" owner:self options:nil].lastObject;
  697. // _bullPokerView.playingCardView.frame = CGRectMake(0, 0, _bullPokerView.pokWidth, _bullPokerView.pokHeight);
  698. // [_bullPokerView.BullPokerOne addSubview:_bullPokerView.playingCardView];
  699. // NSString *oneNumStr = [PokerStr exchangePokerNumberFromSuit:[card.firstObject intValue]andNumber:[card.lastObject intValue]];
  700. // NSString *oneSmallSuit = [PokerStr exchangePokerSmallSuit:[card.firstObject intValue]];
  701. // NSString *oneBigSuit = [PokerStr exchangePokerBigSuitFromSuit:[card.firstObject intValue] andNumber:[card.lastObject intValue]];
  702. // _bullPokerView.playingCardView.numberOfCard.image = [UIImage imageNamed:oneNumStr];
  703. // _bullPokerView.playingCardView.smallSuit.image = [UIImage imageNamed:oneSmallSuit];
  704. // _bullPokerView.playingCardView.bigSuit.image = [UIImage imageNamed:oneBigSuit];
  705. for (int i= 0; i<card.count; ++i) {
  706. _texasBetween.playingCardView = [[NSBundle mainBundle]loadNibNamed:@"PlayingCardView" owner:self options:nil].lastObject;
  707. _texasBetween.playingCardView.frame = CGRectMake(0, 0, _bullPokerView.pokWidth, _bullPokerView.pokHeight);
  708. _texasBetween.playingCardView.layer.cornerRadius = 5.0;
  709. _texasBetween.playingCardView.layer.masksToBounds = YES;
  710. _texasBetween.playingCardView.layer.borderWidth = 2.0;
  711. _texasBetween.playingCardView.layer.borderColor = kGoldFolwerColor.CGColor;
  712. NSArray * cardArray = card[i];
  713. NSString *oneNumStr = [PokerStr exchangePokerNumberFromSuit:[cardArray.firstObject intValue]andNumber:[cardArray.lastObject intValue]];
  714. NSString *oneSmallSuit = [PokerStr exchangePokerSmallSuit:[cardArray.firstObject intValue]];
  715. NSString *oneBigSuit = [PokerStr exchangePokerBigSuitFromSuit:[cardArray.firstObject intValue] andNumber:[cardArray.lastObject intValue]];
  716. _texasBetween.playingCardView.numberOfCard.image = [UIImage imageNamed:oneNumStr];
  717. _texasBetween.playingCardView.smallSuit.image = [UIImage imageNamed:oneSmallSuit];
  718. _texasBetween.playingCardView.bigSuit.image = [UIImage imageNamed:oneBigSuit];
  719. // if (i == 0) {
  720. // _texasBetween.texasPokerOne.hidden = NO;
  721. // [_texasBetween.texasPokerOne addSubview: _bullPokerView.playingCardView];
  722. // }
  723. // else if (i == 1)
  724. // {
  725. // _texasBetween.texasPokerTwo.hidden = NO;
  726. // [_texasBetween.texasPokerTwo addSubview: _bullPokerView.playingCardView];
  727. // }
  728. // else if (i == 2)
  729. // {
  730. // _texasBetween.texasPokerThree.hidden = NO;
  731. // [_texasBetween.texasPokerThree addSubview: _bullPokerView.playingCardView];
  732. // }
  733. // else if (i == 3 )
  734. // {
  735. // _texasBetween.texasPokerFour.hidden = NO;
  736. // [_texasBetween.texasPokerFour addSubview: _bullPokerView.playingCardView];
  737. // }
  738. // else if (i == 4)
  739. // {
  740. // _texasBetween.texasPokerFive.hidden = NO;
  741. // [_texasBetween.texasPokerFive addSubview: _bullPokerView.playingCardView];
  742. // }
  743. }
  744. }
  745. }else if (a == 2){//德州扑克右边两张牌
  746. _texasLR = [[NSBundle mainBundle]loadNibNamed:@"TexasPokerLeftAndRight" owner:self options:nil].lastObject;
  747. _texasLR.frame = CGRectMake(10 * (a + 1) + kTexasSmallWidth+ KtexasBigWidth, pokerY, kTexasSmallWidth, kPokerH);
  748. [_texasLR hidenTexasPoker:hiden];
  749. [self.animationIMG addSubview:_texasLR];
  750. [self.smallArray addObject:_texasLR];
  751. }
  752. }
  753. #pragma mark -- 创建押注视图
  754. - (void)creatBetAmount:(BOOL)hiden type:(NSString *)type{
  755. [self.betImageArray removeAllObjects];
  756. [self.betLabelArr removeAllObjects];
  757. [self.userBetLabelArr removeAllObjects];
  758. for (int i = 0; i < 3; i ++) {
  759. _pokerDownView = [[NSBundle mainBundle]loadNibNamed:@"PokerDownView" owner:self options:nil].lastObject;
  760. _pokerDownView.frame = CGRectMake(10 * (i + 1) + pokerW * i,23+kPokerH, pokerW, kPokerH+7);
  761. _pokerDownView.betPersonLable.textColor = kAppGrayColor1;
  762. if (i == 0) {
  763. // if ([type isEqualToString:@"3"]) {
  764. // _pokerDownView.frame = CGRectMake(10 * (i + 1) + kTexasSmallWidth * i, 23+kPokerH, kTexasSmallWidth, kPokerH+7);
  765. // }
  766. _pokerDownView.tag = LotPokerPosition_Left;
  767. }else if (i == 1){
  768. // _movingIMG = [[UIImageView alloc]initWithFrame:CGRectMake(0 , 0,( _pokerDownView.lotPokerIMG.frame.size.width / 3 + 10) / 10000, (_pokerDownView.lotPokerIMG.frame.size.height / 3 + 20) / 10000)];
  769. // if ([type isEqualToString:@"3"]) {
  770. // _pokerDownView.frame = CGRectMake(10 * (i + 1) + kTexasSmallWidth , 23+kPokerH, KtexasBigWidth, kPokerH+7);
  771. // }
  772. _movingIMG = [[UIImageView alloc]initWithFrame:CGRectMake(_pokerDownView.lotPokerIMG.frame.size.width / 2 , _pokerDownView.lotPokerIMG.frame.size.height / 2,( _pokerDownView.lotPokerIMG.frame.size.width / 3 + 10) / 990, (_pokerDownView.lotPokerIMG.frame.size.height / 3 + 20) / 990)];
  773. [_pokerDownView.lotPokerIMG addSubview:_movingIMG];
  774. [self judgeImage:type];
  775. _movingIMG.hidden = hiden;
  776. _pokerDownView.tag = LotPokerPosition_Between;//发牌的起始位置
  777. }else if (i == 2){
  778. // if ([type isEqualToString:@"3"]) {
  779. // _pokerDownView.frame = CGRectMake(10 * (i + 1) + kTexasSmallWidth + KtexasBigWidth, 23+kPokerH, kTexasSmallWidth, kPokerH+7);
  780. // }
  781. _pokerDownView.tag = LotPokerPosition_Right;
  782. }
  783. if (hiden) {
  784. if (i == 1) {
  785. _pokerDownView.amountBetLable.hidden = YES;
  786. _pokerDownView.lotPokerIMG.hidden = NO;
  787. }
  788. }
  789. //将押注的坐标保存起来(方便获取金币移动的位置)
  790. [_coinMoveArray addObject:[NSValue valueWithCGPoint:_pokerDownView.center]];
  791. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(coinMove:)];
  792. [_pokerDownView addGestureRecognizer:tap];
  793. [self.animationIMG addSubview:_pokerDownView];
  794. [self.betImageArray addObject:_pokerDownView];
  795. [_betMoneyLabArray addObject:_pokerDownView.betPersonLable];
  796. }
  797. for (int i= 0; i<3; ++i) {
  798. if ([type integerValue] == 1) {
  799. if (i== 0) {
  800. // UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(6, 20+kPokerH, (kPokerH+10)*103.0/150.0, kPokerH+10)];
  801. UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(4, 17+kPokerH, (kPokerH+13)*103.0/150.0, kPokerH+13)];
  802. imageV.image = [UIImage imageNamed:@"gm_stake_one"];
  803. [self.animationIMG addSubview:imageV];
  804. }
  805. else if (i==1)
  806. {
  807. // UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(16+pokerW, 20+kPokerH, (kPokerH+10)*126.0/172.0, kPokerH+10)];
  808. UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(14+pokerW, 15+kPokerH, (kPokerH+15)*126.0/172.0, kPokerH+15)];
  809. imageV.image = [UIImage imageNamed:@"gm_stake_two"];
  810. [self.animationIMG addSubview:imageV];
  811. }
  812. else if (i==2)
  813. {
  814. // UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(26+2*pokerW, 20+kPokerH, (kPokerH+10)*133.0/176.0, kPokerH+10)];
  815. UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(24+2*pokerW, 13+kPokerH, (kPokerH+17)*133.0/176.0, kPokerH+17)];
  816. imageV.image = [UIImage imageNamed:@"gm_stake_three"];
  817. [self.animationIMG addSubview:imageV];
  818. }
  819. }
  820. else if ([type integerValue] == 2 || [type integerValue] == 3)
  821. {
  822. if (i== 0) {
  823. UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(4, 17+kPokerH, (kPokerH+13)*105.0/133.0, kPokerH+13)];
  824. imageV.image = [UIImage imageNamed:@"gm_bull_stake_one"];
  825. [self.animationIMG addSubview:imageV];
  826. }
  827. else if (i==1)
  828. {
  829. UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(14+pokerW, 17+kPokerH, (kPokerH+13)*105.0/133.0, kPokerH+13)];
  830. imageV.image = [UIImage imageNamed:@"gm_bull_stake_two"];
  831. [self.animationIMG addSubview:imageV];
  832. }
  833. else if (i==2)
  834. {
  835. UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(24+2*pokerW, 17+kPokerH, (kPokerH+13)*94.0/129.0, kPokerH+13)];
  836. imageV.image = [UIImage imageNamed:@"gm_bull_stake_three"];
  837. [self.animationIMG addSubview:imageV];
  838. }
  839. }
  840. CGFloat userBetLabelheight = (kPokerH+7)*40.0/143.0;
  841. THLabel * betLabel = [[THLabel alloc] initWithFrame:CGRectMake(10 * (i + 1) + pokerW * i, 23+kPokerH+(kPokerH+7-userBetLabelheight-30)/2.0, pokerW, 30)];
  842. // if ([type integerValue] == 3) {
  843. // if (i == 0) {
  844. // betLabel.frame = CGRectMake(10 * (i + 1) + kTexasSmallWidth * i, 23+kPokerH+(kPokerH+7-userBetLabelheight-30)/2.0, kTexasSmallWidth, 30);
  845. // }
  846. // else if (i == 1) {
  847. // betLabel.frame = CGRectMake(10 * (i + 1) + kTexasSmallWidth * i, 23+kPokerH+(kPokerH+7-userBetLabelheight-30)/2.0, KtexasBigWidth, 30);
  848. // }
  849. // else if (i == 2) {
  850. // betLabel.frame = CGRectMake(10 * (i + 1) + kTexasSmallWidth + KtexasBigWidth, 23+kPokerH+(kPokerH+7-userBetLabelheight-30)/2.0, kTexasSmallWidth, 30);
  851. // }
  852. // }
  853. betLabel.textAlignment = NSTextAlignmentCenter;
  854. betLabel.textColor = [UIColor whiteColor];
  855. betLabel.font = [UIFont systemFontOfSize:23];
  856. betLabel.strokeColor = [UIColor blackColor];
  857. betLabel.strokeSize = 1.0;
  858. [self.betLabelArr addObject:betLabel];
  859. [self.animationIMG addSubview:betLabel];
  860. UILabel * userBetLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * (i + 1) + pokerW * i, 30+2*kPokerH-userBetLabelheight, pokerW, userBetLabelheight)];
  861. // if ([type integerValue] == 3) {
  862. // if (i == 0) {
  863. // userBetLabel.frame = CGRectMake(10 * (i + 1) + kTexasSmallWidth * i, 30+2*kPokerH-userBetLabelheight, kTexasSmallWidth, userBetLabelheight);
  864. // }
  865. // else if (i == 1) {
  866. // userBetLabel.frame = CGRectMake(10 * (i + 1) + kTexasSmallWidth * i, 30+2*kPokerH-userBetLabelheight, KtexasBigWidth, userBetLabelheight);
  867. // }
  868. // else if (i == 2) {
  869. // userBetLabel.frame = CGRectMake(10 * (i + 1) + kTexasSmallWidth + KtexasBigWidth, 30+2*kPokerH-userBetLabelheight, kTexasSmallWidth, userBetLabelheight);
  870. // }
  871. // }
  872. userBetLabel.textColor = [UIColor flatYellowColor];
  873. userBetLabel.font = [UIFont systemFontOfSize:15];
  874. userBetLabel.textAlignment = NSTextAlignmentCenter;
  875. [self.userBetLabelArr addObject:userBetLabel];
  876. [self.animationIMG addSubview:userBetLabel];
  877. // [self.animationIMG bringSubviewToFront:[_betImageArray[i] amountBetLable]];
  878. }
  879. }
  880. #pragma mark -- 判断发牌图片及底牌图片
  881. - (void)judgeImage:(NSString *)type{
  882. if ([type isEqualToString:@"1"] ||[type isEqualToString:@"3"]) {
  883. _movingIMG.image = [UIImage imageNamed:@"gm_poker_back_goldflower"];
  884. _pokerDownView.lotPokerIMG.image = [UIImage imageNamed:@"gm_img_goldflower"];
  885. }else if ([type isEqualToString:@"2"]){
  886. _movingIMG.image = [UIImage imageNamed:@"gm_poker_back_niuniu"];
  887. _pokerDownView.lotPokerIMG.image = [UIImage imageNamed:@"gm_img_niuniu"];
  888. }
  889. }
  890. - (void)recharge
  891. {
  892. if (_delegate && [_delegate respondsToSelector:@selector(clickRecharge)]) {
  893. [_delegate clickRecharge];
  894. }
  895. }
  896. #pragma mark ------------------------------------网络请求--------------------------------------
  897. #pragma mark -- 押注发送请求
  898. - (void)postBetMoneyStr:(NSString *)str withTag:(NSInteger)tag
  899. {
  900. NSMutableDictionary *parmDict = [[NSMutableDictionary alloc]init];
  901. [parmDict setObject:@"games" forKey:@"ctl"];
  902. [parmDict setObject:@"bet" forKey:@"act"];
  903. [parmDict setObject:str forKey:@"id"];
  904. [parmDict setObject:_betMoney forKey:@"money"];
  905. [parmDict setObject:[NSString stringWithFormat:@"%ld",(long)_bet] forKey:@"bet"];
  906. [_httpManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  907. if ([responseJson toInt:@"status"] == 1)
  908. {
  909. NSDictionary *dataDic = [responseJson objectForKey:@"data"];
  910. NSDictionary *dic = [dataDic objectForKey:@"game_data"];
  911. if (_BuguLive.appModel.open_diamond_game_module == 1)
  912. {
  913. _currentMoney = [[IMAPlatform sharedInstance].host getDiamonds];
  914. }
  915. else
  916. {
  917. _currentMoney = [[IMAPlatform sharedInstance].host getUserCoin];
  918. }
  919. //更新押注信息
  920. if ([dic[@"bet"] isKindOfClass:[NSArray class]]&& [dic[@"user_bet"] isKindOfClass:[NSArray class]])
  921. {
  922. [self loadBetDataWithBetArray:dic[@"bet"] andUserBetArray:dic[@"user_bet"]];
  923. }
  924. //更新金币
  925. if (_currentMoney >= 0 && _currentMoney >= [_betMoney integerValue])
  926. {
  927. _currentMoney -= [_betMoney integerValue];
  928. _coinView.gameRechargeView.accountLabel.text = [NSString stringWithFormat:@"%ld",(long)_currentMoney];
  929. if (_BuguLive.appModel.open_diamond_game_module == 1)
  930. {
  931. //存入本地
  932. [[IMAPlatform sharedInstance].host setDiamonds:[NSString stringWithFormat:@"%ld",(long)_currentMoney]];
  933. }
  934. else
  935. {
  936. //存入本地
  937. [[IMAPlatform sharedInstance].host setUserCoin:[NSString stringWithFormat:@"%ld",(long)_currentMoney]];
  938. }
  939. }
  940. [self coinBreathMove:_currentMoney];
  941. [self judgmentBetView:[_coinView.gameRechargeView.accountLabel.text integerValue]];
  942. }
  943. } FailureBlock:^(NSError *error) {
  944. }];
  945. }
  946. #pragma mark -- 更新余额
  947. - (void)updateCoinWithID:(NSString *)ID
  948. {
  949. NSMutableDictionary *parmDict = [[NSMutableDictionary alloc]init];
  950. [parmDict setObject:@"games" forKey:@"ctl"];
  951. [parmDict setObject:@"userDiamonds" forKey:@"act"];
  952. if (ID != nil) {
  953. [parmDict setObject:ID forKey:@"id"];
  954. }
  955. [_httpManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  956. if ([responseJson toInt:@"status"] == 1)
  957. {
  958. GameGainModel * gainModel = [GameGainModel mj_objectWithKeyValues:responseJson];
  959. NSInteger gainInt = [responseJson toInt:@"gain"];
  960. if (_BuguLive.appModel.open_diamond_game_module == 1)
  961. {
  962. _currentMoney = [[responseJson toString:@"user_diamonds"] integerValue];
  963. //存入钻石
  964. [[IMAPlatform sharedInstance].host setDiamonds:[responseJson toString:@"user_diamonds"]];
  965. }
  966. else
  967. {
  968. _currentMoney = [[responseJson toString:@"coin"] integerValue];
  969. //存入游戏币
  970. [[IMAPlatform sharedInstance].host setUserCoin:[responseJson toString:@"coin"]];
  971. }
  972. if (ID != nil) {
  973. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  974. _coinView.gameRechargeView.accountLabel.text = [NSString stringWithFormat:@"%ld",(long)_currentMoney];
  975. //押注按钮颜色变化
  976. if (!_isHost) {
  977. [self judgmentBetView:[_coinView.gameRechargeView.accountLabel.text integerValue]];
  978. }
  979. });
  980. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  981. if (gainInt > 0) {
  982. if (_delegate && [_delegate respondsToSelector:@selector(displayGameWinWithGainModel:)]) {
  983. [_delegate displayGameWinWithGainModel:gainModel];
  984. }
  985. }
  986. });
  987. }else{
  988. _coinView.gameRechargeView.accountLabel.text = [NSString stringWithFormat:@"%ld",(long)_currentMoney];
  989. //押注按钮颜色变化
  990. if (!_isHost) {
  991. [self judgmentBetView:[_coinView.gameRechargeView.accountLabel.text integerValue]];
  992. }
  993. }
  994. }
  995. } FailureBlock:^(NSError *error) {
  996. }];
  997. }
  998. #pragma mark 主播结束游戏
  999. - (void)gameOver
  1000. {
  1001. NSMutableDictionary *parmDict = [[NSMutableDictionary alloc]init];
  1002. [parmDict setObject:@"games" forKey:@"ctl"];
  1003. [parmDict setObject:@"stop" forKey:@"act"];
  1004. [_httpManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  1005. _canCloseGame = YES;
  1006. if ([responseJson toInt:@"status"] == 1)
  1007. {
  1008. //关闭游戏声音
  1009. [self closeVideo];
  1010. [[NSNotificationCenter defaultCenter]postNotificationName:@"closeGame" object:nil];
  1011. }
  1012. } FailureBlock:^(NSError *error) {
  1013. _canCloseGame = YES;
  1014. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"关闭游戏失败")];
  1015. }];
  1016. }
  1017. #pragma mark 更新余额
  1018. - (void)updateCoin
  1019. {
  1020. [self updateCoinWithID:nil];
  1021. }
  1022. #pragma mark -----------------------------------押注相关--------------------------------
  1023. #pragma mark 点击押注
  1024. - (void)coinMove:(UITapGestureRecognizer *)tap
  1025. {
  1026. if (!_isHost)
  1027. {
  1028. if ([_coinView.gameRechargeView.accountLabel.text integerValue] >= [[self.betOptionArray objectAtIndex:0] integerValue])
  1029. {
  1030. [self betProcessing:tap.view.tag];
  1031. }
  1032. else
  1033. {
  1034. [SVProgressHUD showErrorWithStatus:ASLocalizedString(@"金额不足,请充值")];
  1035. }
  1036. }
  1037. }
  1038. #pragma mark 押注进行中
  1039. - (void)betProcessing:(NSInteger)tag
  1040. {
  1041. _bet = tag;
  1042. //发送请求
  1043. [self postBetMoneyStr:_game_log_id withTag:tag -1];
  1044. // //余额减少
  1045. // NSInteger coinInt = [_coinView.personCoinLab.text integerValue] - [_betMoney integerValue];
  1046. // _coinView.personCoinLab.text = [NSString stringWithFormat:@"%d",coinInt];
  1047. //金币移动
  1048. CGPoint imagePoint = [[_coinMoveArray objectAtIndex:tag -1] CGPointValue];
  1049. [self coinMoveWithBegin:_amountPoint WithEnd:imagePoint];
  1050. }
  1051. #pragma mark 选择押注金额或游戏记录
  1052. - (void)selectAmount:(UIButton *)sender
  1053. {
  1054. if (_isHost) {
  1055. //(tag==204 代表游戏记录按钮)
  1056. if (sender.tag == 204) {
  1057. _betView = [_betViewArray objectAtIndex:0];
  1058. if (_delegate && [_delegate respondsToSelector:@selector(displayGameHistory)]) {
  1059. [_delegate displayGameHistory];
  1060. }
  1061. }
  1062. else if (sender.tag == 206)
  1063. {
  1064. if (_betViewArray.count>2) {
  1065. _betView = [_betViewArray objectAtIndex:2];
  1066. }
  1067. if (_delegate && [_delegate respondsToSelector:@selector(choseArcOrMrcGameWithView:)]) {
  1068. [_delegate choseArcOrMrcGameWithView:self];
  1069. }
  1070. }
  1071. else{
  1072. if (_betViewArray.count>1) {
  1073. _betView = [_betViewArray objectAtIndex:1];
  1074. }
  1075. if (_canCloseGame)
  1076. {
  1077. FWWeakify(self)
  1078. [FanweMessage alert:nil message:ASLocalizedString(@"是否确定结束游戏?")destructiveAction:^{
  1079. FWStrongify(self)
  1080. self.canCloseGame = NO;
  1081. //主播结束游戏
  1082. [self gameOver];
  1083. } cancelAction:^{
  1084. }];
  1085. }
  1086. else
  1087. {
  1088. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"关闭游戏中,请稍后!")];
  1089. }
  1090. }
  1091. }
  1092. else
  1093. {
  1094. _betView = [_betViewArray objectAtIndex:sender.tag-200];
  1095. if (sender.tag != 204) {
  1096. _isClick = !_isClick;
  1097. _betCount = sender.tag-200;
  1098. //为什么不行~_~!!!!!
  1099. //[_coinBtnArray makeObjectsPerformSelector:@selector(removeBreathAnimation:) withObject:sender];
  1100. for (BetView * betView in _betViewArray) {
  1101. if (![betView isEqual:_historyView]) {
  1102. [self setBetBtnWithIsSelected:[betView isEqual:_betView] andBtn:betView.betBtn];
  1103. }
  1104. }
  1105. [self getCoinBreathAndPoint:sender.tag-200];
  1106. }
  1107. else
  1108. {
  1109. if (_delegate && [_delegate respondsToSelector:@selector(displayGameHistory)]) {
  1110. [_delegate displayGameHistory];
  1111. }
  1112. }
  1113. }
  1114. //加入抖动动画
  1115. [_betView.layer addAnimation:[CAAnimation jitterAnimation] forKey:@"jitter"];
  1116. }
  1117. #pragma mark 押注按钮颜色变暗(金额不足时)
  1118. - (void)judgmentBetView:(NSInteger)coin
  1119. {
  1120. if (self.betOptionArray.count > 0 && self.betOptionArray.count < self.coinBtnArray.count) {
  1121. [self.betOptionArray enumerateObjectsUsingBlock:^(NSString *betOptionStr, NSUInteger idx, BOOL * _Nonnull stop) {
  1122. NSInteger betOptionInt = [betOptionStr integerValue];
  1123. UIButton *btn= (UIButton *)_coinBtnArray[idx];
  1124. if (coin >= betOptionInt) {
  1125. btn.userInteractionEnabled = YES;
  1126. btn.alpha = 1;
  1127. }
  1128. else
  1129. {
  1130. btn.userInteractionEnabled = NO;
  1131. btn.alpha = 0.3;
  1132. }
  1133. }];
  1134. }
  1135. }
  1136. #pragma mark 判断呼吸灯位置(金额减少时)
  1137. - (void)coinBreathMove:(NSInteger)currentGold
  1138. {
  1139. if (currentGold >= 0 && currentGold < [_betMoney integerValue])
  1140. {
  1141. if (currentGold >=[[self.betOptionArray objectAtIndex:2]integerValue])
  1142. {
  1143. _betCount = 2;
  1144. }
  1145. else if (currentGold >= [[self.betOptionArray objectAtIndex:1]integerValue])
  1146. {
  1147. _betCount = 1;
  1148. }
  1149. else
  1150. {
  1151. _betCount = 0;
  1152. }
  1153. [self getCoinBreathAndPoint:_betCount];
  1154. }
  1155. }
  1156. #pragma mark 加入呼吸灯和获取金币移动的起始位置
  1157. - (void)getCoinBreathAndPoint:(NSInteger)tag
  1158. {
  1159. //获取押注金额
  1160. if (_betOptionArray.count > 0) {
  1161. _betMoney = [_betOptionArray objectAtIndex:tag];
  1162. }
  1163. // //移除呼吸灯动画
  1164. // for (UIImageView *imageView in _breathImgArray) {
  1165. // imageView.image = [UIImage imageNamed:@""];
  1166. // [imageView.layer removeAnimationForKey:@"alpha"];
  1167. // }
  1168. // //加入呼吸灯动画
  1169. // UIImageView *img = [_breathImgArray objectAtIndex:tag];
  1170. // img.image = [UIImage imageNamed:@"gm_coin_breath"];
  1171. // [img.layer addAnimation:[CAAnimation AlphaLight:1.0f
  1172. // fromValue:1.0f
  1173. // toValue:0.4f]
  1174. // forKey:@"alpha"];
  1175. //获取金币开始动画的位置
  1176. CGPoint point = [[_coinBeignArray objectAtIndex:tag] CGPointValue];
  1177. _amountPoint = [_coinView convertPoint:point toView:self];
  1178. }
  1179. #pragma mark -----------------------------------金币相关动画-----------------------------------
  1180. #pragma mark 金币移动动画(传入起始位置和终点位置)
  1181. - (void)coinMoveWithBegin:(CGPoint)begin WithEnd:(CGPoint)end
  1182. {
  1183. UIImageView *breathImg = [[UIImageView alloc]init];
  1184. breathImg.width = 25;
  1185. breathImg.height = 25;
  1186. if (!_isClick && NSStringFromCGPoint(_winCoinPoint).length == 0) {
  1187. breathImg.center = _amountPoint;
  1188. }
  1189. else
  1190. {
  1191. breathImg.center = begin;
  1192. }
  1193. breathImg.image = [UIImage imageNamed:@"gm_selectedBet"];
  1194. [self addSubview:breathImg];
  1195. if (!_isClick) {
  1196. [breathImg.layer addAnimation:[CAAnimation coinMoveAntimationWithBegin:breathImg.center
  1197. WithEnd:end
  1198. andMoveTime:kMoveAnimationDuration
  1199. andNarrowTime:kNarrowAnimationDuration
  1200. andNarrowFromValue:1.0f
  1201. andNarrowToValue:0.0f]
  1202. forKey:@"moveWithNarrow"];
  1203. }
  1204. else
  1205. {
  1206. [breathImg.layer addAnimation:[CAAnimation coinMoveAntimationWithBegin:begin
  1207. WithEnd:end
  1208. andMoveTime:kMoveAnimationDuration
  1209. andNarrowTime:kNarrowAnimationDuration
  1210. andNarrowFromValue:1.0f
  1211. andNarrowToValue:0.0f]
  1212. forKey:@"moveWithNarrow"];
  1213. }
  1214. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kCoinMoveAnimationDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1215. if (breathImg) {
  1216. [breathImg removeFromSuperview];
  1217. }
  1218. });
  1219. }
  1220. #pragma mark ---------------------------------加载押注数据等------------------------------------
  1221. #pragma mark 加载更新押注数据
  1222. - (void)loadBetDataWithBetArray:(NSArray *)betArray andUserBetArray:(NSArray *)userBetArray
  1223. {
  1224. if (betArray.count == self.betImageArray.count ) {
  1225. if (self.betArr.count == 0 ) {
  1226. NSMutableArray * arr = [NSMutableArray arrayWithArray:betArray];
  1227. //每局游戏第一次加载下注情况时对总下注情况用数组进行记录
  1228. self.betArr = arr;
  1229. for (int i=0; i<betArray.count; ++i) {
  1230. //总投注数,第一次加载下注情况时进循环,如果为0则不显示出来
  1231. if ([betArray[i] integerValue]>0) {
  1232. [self loadBetDesDataWithBetLabel:_betLabelArr[i] andBetNumber:betArray[i]];
  1233. }
  1234. }
  1235. }
  1236. else
  1237. {
  1238. for (int i=0; i<betArray.count; ++i) {
  1239. //如果不是第一次加载下注情况,则通过之前存的下注情况与现在的下注情况进行对比
  1240. if ([betArray[i] integerValue]>[self.betArr[i] integerValue]) {
  1241. self.betArr[i] = betArray[i];
  1242. [self loadBetDesDataWithBetLabel:_betLabelArr[i] andBetNumber:betArray[i]];
  1243. }
  1244. }
  1245. }
  1246. }
  1247. if (userBetArray != nil) {
  1248. if (userBetArray.count == self.betImageArray.count) {
  1249. //每局游戏第一次加载下注情况时对玩家下注情况用数组进行记录
  1250. if (self.userBetArr.count == 0 ) {
  1251. NSMutableArray * arr = [NSMutableArray arrayWithArray:userBetArray];
  1252. self.userBetArr = arr;
  1253. for (int i=0; i<userBetArray.count; ++i) {
  1254. //玩家投注数,第一次加载下注情况时进循环,如果为0则不显示出来
  1255. if ([userBetArray[i] integerValue] >0) {
  1256. [self loadUserBetDesDataWithLabel:_userBetLabelArr[i] andUserBetNumber:userBetArray[i]];
  1257. }
  1258. }
  1259. }
  1260. else
  1261. {
  1262. //玩家投注数
  1263. for (int i=0; i<userBetArray.count; ++i) {
  1264. //如果不是第一次加载下注情况,则通过之前存的下注情况与现在的下注情况进行对比
  1265. if ([userBetArray[i] integerValue]>[self.userBetArr[i] integerValue]) {
  1266. self.userBetArr[i] = userBetArray[i];
  1267. [self loadUserBetDesDataWithLabel:_userBetLabelArr[i] andUserBetNumber:userBetArray[i]];
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. }
  1274. #pragma mark 加载总下注数据的实现
  1275. - (void)loadBetDesDataWithBetLabel:(THLabel *)betLabel andBetNumber:(id)betNumber
  1276. {
  1277. if ([betNumber integerValue]>=10000) {
  1278. float bet = [betNumber integerValue]/10000.0;
  1279. betLabel.text = [NSString stringWithFormat:ASLocalizedString(@"%.1f万"),bet];
  1280. }
  1281. else
  1282. {
  1283. betLabel.text = [NSString stringWithFormat:@"%@",betNumber];
  1284. }
  1285. }
  1286. #pragma mark 加载玩家下注数据的实现
  1287. - (void)loadUserBetDesDataWithLabel:(UILabel *)userBetLabel andUserBetNumber:(id)userBetNumber
  1288. {
  1289. if ([userBetNumber integerValue]>=10000) {
  1290. float userBet = [userBetNumber integerValue]/10000.0;
  1291. userBetLabel.text = [NSString stringWithFormat:ASLocalizedString(@"%.1f万"),userBet];
  1292. }
  1293. else
  1294. {
  1295. userBetLabel.text = [NSString stringWithFormat:@"%@",userBetNumber];
  1296. }
  1297. }
  1298. #pragma mark 加载押注倍率
  1299. - (void)loadOptionArray:(NSArray *)optionArray
  1300. {
  1301. if (optionArray.count == self.betImageArray.count ) {
  1302. for (int i=0; i<optionArray.count; ++i) {
  1303. PokerDownView * betView = _betImageArray[i];
  1304. //押注倍率
  1305. betView.betMultiple.text = [NSString stringWithFormat:ASLocalizedString(@"%@倍"),optionArray[i]];
  1306. }
  1307. }
  1308. }
  1309. #pragma mark 观众是否能够进行押注
  1310. - (void)whetherBet:(BOOL)isBet
  1311. {
  1312. if (!_isHost) {
  1313. _animationIMG.userInteractionEnabled = isBet;
  1314. }
  1315. }
  1316. #pragma mark -- 懒加载
  1317. - (NSMutableArray *) betImageArray
  1318. {
  1319. if (_betImageArray == nil) {
  1320. _betImageArray = [NSMutableArray array];
  1321. }
  1322. return _betImageArray;
  1323. }
  1324. - (NSMutableArray *) pokerArray
  1325. {
  1326. if (_pokerArray == nil) {
  1327. _pokerArray = [NSMutableArray array];
  1328. }
  1329. return _pokerArray;
  1330. }
  1331. - (NSMutableArray *)animationArray
  1332. {
  1333. if (_animationArray == nil) {
  1334. _animationArray = [NSMutableArray array];
  1335. }
  1336. return _animationArray;
  1337. }
  1338. - (NSMutableArray *)smallArray
  1339. {
  1340. if (_smallArray == nil) {
  1341. _smallArray = [NSMutableArray array];
  1342. }
  1343. return _smallArray;
  1344. }
  1345. - (UIView *)firstView{
  1346. if (!_firstView) {
  1347. //第一副牌的遮罩
  1348. self.firstView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW / 3, self.frame.size.height - _coinView.frame.size.height)];
  1349. self.firstView.backgroundColor = [UIColor blackColor];
  1350. self.firstView.alpha = 0.4;
  1351. self.firstView.hidden = YES;
  1352. [self addSubview:self.firstView];
  1353. }
  1354. return _firstView;
  1355. }
  1356. - (UIView *)secondView{
  1357. if (!_secondView) {
  1358. //第一副牌的遮罩
  1359. self.secondView = [[UIView alloc]initWithFrame:CGRectMake(kScreenW / 3, 0, kScreenW / 3, self.frame.size.height - _coinView.frame.size.height)];
  1360. self.secondView.backgroundColor = [UIColor blackColor];
  1361. self.secondView.hidden = YES;
  1362. self.secondView.alpha = 0.4;
  1363. [self addSubview:self.secondView];
  1364. }
  1365. return _secondView;
  1366. }
  1367. - (UIView *)thirdView{
  1368. if (!_thirdView) {
  1369. //第一副牌的遮罩
  1370. self.thirdView = [[UIView alloc]initWithFrame:CGRectMake(2 * kScreenW / 3, 0, kScreenW / 3, self.frame.size.height - _coinView.frame.size.height)];
  1371. self.thirdView.backgroundColor = [UIColor blackColor];
  1372. self.thirdView.hidden = YES;
  1373. self.thirdView.alpha = 0.4;
  1374. [self addSubview:self.thirdView];
  1375. }
  1376. return _thirdView;
  1377. }
  1378. //总押注数据
  1379. - (NSMutableArray *)betArr
  1380. {
  1381. if (_betArr == nil) {
  1382. _betArr = [NSMutableArray array];
  1383. }
  1384. return _betArr;
  1385. }
  1386. //用户本人押注数据
  1387. - (NSMutableArray *)userBetArr
  1388. {
  1389. if (_userBetArr == nil) {
  1390. _userBetArr = [NSMutableArray array];
  1391. }
  1392. return _userBetArr;
  1393. }
  1394. //总押注数据label
  1395. - (NSMutableArray *)betLabelArr
  1396. {
  1397. if (_betLabelArr == nil) {
  1398. _betLabelArr = [NSMutableArray array];
  1399. }
  1400. return _betLabelArr;
  1401. }
  1402. //用户押注数据label
  1403. - (NSMutableArray *)userBetLabelArr
  1404. {
  1405. if (_userBetLabelArr == nil) {
  1406. _userBetLabelArr = [NSMutableArray array];
  1407. }
  1408. return _userBetLabelArr;
  1409. }
  1410. @end