PokerStr.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. //
  2. // PokerStr.m
  3. // GoldenFlowerDemo
  4. //
  5. // Created by 王珂 on 16/11/23.
  6. // Copyright © 2016年 zcd. All rights reserved.
  7. //
  8. #import "PokerStr.h"
  9. #import "PokerView.h"
  10. #import "BullPoker.h"
  11. #import "TexasPokerLeftAndRight.h"
  12. #import "TexasPokerBetween.h"
  13. #import "PlayingCardView.h"
  14. #import "TexasPokerLeftAndRight.h"
  15. @implementation PokerStr
  16. +(NSString *)exchangePokerNumberFromSuit:(int)suit andNumber:(int)pokerNumber
  17. {
  18. NSString * colorPoker = suit%2 >0 ? @"red" :@"black";//根据牌的花色判断牌的点数的颜色
  19. if (pokerNumber >10)
  20. {
  21. if (pokerNumber == 11)
  22. {
  23. return [NSString stringWithFormat:@"gm_img_poker_jack_%@",colorPoker];
  24. }
  25. else if (pokerNumber == 12)
  26. {
  27. return [NSString stringWithFormat:@"gm_img_poker_queen_%@",colorPoker];
  28. }
  29. else if (pokerNumber == 13)
  30. {
  31. return [NSString stringWithFormat:@"gm_img_poker_king_%@",colorPoker];
  32. }
  33. }
  34. else if (pokerNumber <= 10)
  35. {
  36. if (pokerNumber == 1)
  37. {
  38. return [NSString stringWithFormat:@"gm_img_poker_ace_%@",colorPoker];
  39. }
  40. else
  41. {
  42. return [NSString stringWithFormat:@"gm_img_poker_%d_%@",pokerNumber,colorPoker];
  43. }
  44. }
  45. return @"error";
  46. }
  47. +(NSString *)exchangePokerSmallSuit:(int)suit
  48. {
  49. if (suit == 0)
  50. return @"gm_poker_spade";//黑桃
  51. else if (suit == 1)
  52. return @"gm_poker_heart";//红桃
  53. else if (suit == 2)
  54. return @"gm_poker_club";//梅花
  55. else if (suit == 3)
  56. return @"gm_poker_diamond";//方块
  57. else
  58. return @"";
  59. }
  60. +(NSString *)exchangePokerBigSuitFromSuit:(int)suit andNumber:(int)pokerNumber
  61. {
  62. NSString * suitStr ;//花色
  63. if (suit == 0)
  64. suitStr = @"gm_poker_spade";//黑桃
  65. else if (suit == 1)
  66. suitStr = @"gm_poker_heart";//红桃
  67. else if (suit == 2)
  68. suitStr = @"gm_poker_club";//梅花
  69. else if (suit == 3)
  70. suitStr = @"gm_poker_diamond";//方块
  71. // else
  72. // suitStr = @"";
  73. if (pokerNumber >10)
  74. {
  75. if (pokerNumber == 11)
  76. {
  77. return [NSString stringWithFormat:@"%@_j",suitStr];
  78. }
  79. else if (pokerNumber ==12)
  80. {
  81. return [NSString stringWithFormat:@"%@_k",suitStr];
  82. }
  83. else if (pokerNumber ==13)
  84. {
  85. return [NSString stringWithFormat:@"%@_q",suitStr];
  86. }
  87. }
  88. else if(pokerNumber <=10)
  89. {
  90. return suitStr;
  91. }
  92. return @"error";
  93. }
  94. +(NSString *)exchanegeGoldFlowerOrBullResultFromResultType:(int)type goldFlowerOrBull:(id)poker
  95. {
  96. if ([poker isKindOfClass:[PokerView class]])
  97. {//判断炸金花牌型
  98. if (type==0)
  99. return @"gm_is_bao_zi";
  100. else if (type==1)
  101. return @"gm_is_tong_hua_shun";
  102. else if (type==2)
  103. return @"gm_is_tong_hua";
  104. else if (type==3)
  105. return @"gm_is_shun_zi";
  106. else if (type==4)
  107. return @"gm_is_dui_zi";
  108. else if (type==5)
  109. return @"gm_is_normal";
  110. return @"";
  111. }
  112. else if ([poker isKindOfClass:[BullPoker class]])
  113. {//判断斗牛牌型
  114. if (type==0)
  115. return @"gm_ico_bull_wxn";
  116. else if (type==1)
  117. return @"gm_ico_bull_zd";
  118. else if (type==2)
  119. return @"gm_ico_bull_whn";
  120. else if (type==3)
  121. return @"gm_ico_bull_shn";
  122. else if (type==4)
  123. return @"gm_ico_bull_nn";
  124. else if (type==5)
  125. return @"gm_ico_bull_n9";
  126. else if (type==6)
  127. return @"gm_ico_bull_n8";
  128. else if (type==7)
  129. return @"gm_ico_bull_n7";
  130. else if (type==8)
  131. return @"gm_ico_bull_n6";
  132. else if (type == 9)
  133. return @"gm_ico_bull_n5";
  134. else if (type == 10)
  135. return @"gm_ico_bull_n4";
  136. else if (type == 11)
  137. return @"gm_ico_bull_n3";
  138. else if (type == 12)
  139. return @"gm_ico_bull_n2";
  140. else if (type == 13)
  141. return @"gm_ico_bull_n1";
  142. else if (type == 14)
  143. return @"gm_ico_bull_mn";
  144. return @"";
  145. }
  146. else if ([poker isKindOfClass:[TexasPokerLeftAndRight class]])
  147. {//判断德州扑克的牌型
  148. if (type==0)
  149. return @"gm_tonghuasun";
  150. else if (type == 1)
  151. return @"gm_tonghua";
  152. else if (type == 2)
  153. return @"gm_sitiao";
  154. else if (type == 3)
  155. return @"gm_hulu";
  156. else if (type == 4)
  157. return @"gm_tonghua";
  158. else if (type == 5)
  159. return @"gm_sz";
  160. else if (type == 6)
  161. return @"gm_santiao";
  162. else if (type == 7)
  163. return @"gm_liangdui";
  164. else if (type == 8)
  165. return @"gm_yidui";
  166. else if (type == 9)
  167. return @"gm_gaopai";
  168. }
  169. return @"";
  170. }
  171. + (void)aboutClassOfPokerOrBullPoker:(id)poker dict:(NSDictionary *)dic typeIMG:(NSString *)typeIMG{
  172. if ([poker isKindOfClass:[PokerView class]])
  173. {//判断单张炸金花牌的结果
  174. PokerView *pokerView = (PokerView *)poker;
  175. pokerView.pokerResultView.hidden = NO;
  176. pokerView.pokerResultView.image = [UIImage imageNamed:typeIMG];
  177. NSArray *cardsArr = [dic valueForKey:@"cards"];
  178. if (cardsArr.count == 3)
  179. {
  180. for (int i=0; i<3; ++i)
  181. {
  182. NSArray * cardArray = cardsArr[i];
  183. pokerView.playingCardView = [[NSBundle mainBundle]loadNibNamed:@"PlayingCardView" owner:self options:nil].lastObject;
  184. pokerView.playingCardView.frame = CGRectMake(0, 0, pokerView.pokWidth, pokerView.pokHeight);
  185. pokerView.playingCardView.layer.cornerRadius = 5.0;
  186. pokerView.playingCardView.layer.masksToBounds = YES;
  187. pokerView.playingCardView.layer.borderWidth = 2.0;
  188. pokerView.playingCardView.layer.borderColor = kGoldFolwerColor.CGColor;
  189. NSString * numberStr = [self exchangePokerNumberFromSuit:[cardArray.firstObject intValue] andNumber:[cardArray.lastObject intValue]];
  190. NSString * suitStr = [self exchangePokerSmallSuit:[cardArray.firstObject intValue]];
  191. NSString * bigSuitStr = [self exchangePokerBigSuitFromSuit:[cardArray.firstObject intValue] andNumber:[cardArray.lastObject intValue]];
  192. pokerView.playingCardView.numberOfCard.image = [UIImage imageNamed:numberStr];
  193. pokerView.playingCardView.smallSuit.image = [UIImage imageNamed:suitStr];
  194. pokerView.playingCardView.bigSuit.image = [UIImage imageNamed:bigSuitStr];
  195. if (i== 0)
  196. {
  197. [pokerView.pokerOne addSubview:pokerView.playingCardView];
  198. }
  199. else if (i==1)
  200. {
  201. [pokerView.pokerTwo addSubview:pokerView.playingCardView];
  202. }
  203. else if (i==2)
  204. {
  205. [pokerView.pokerThree addSubview:pokerView.playingCardView];
  206. }
  207. }
  208. }
  209. }
  210. else if ([poker isKindOfClass:[BullPoker class]])
  211. {//判断单张斗牛牌的结果
  212. BullPoker *pokerView = (BullPoker *)poker;
  213. pokerView.pokerResultView.hidden = NO;
  214. pokerView.pokerResultView.image = [UIImage imageNamed:typeIMG];
  215. NSArray *cardsArr = [dic valueForKey:@"cards"];
  216. NSLog(@"cardsArr--------%@",cardsArr);
  217. if (cardsArr.count == 5)
  218. {
  219. for (int i=0; i<5; ++i)
  220. {
  221. NSArray * cardArrayBull = cardsArr[i];
  222. pokerView.playingCardView = [[NSBundle mainBundle]loadNibNamed:@"PlayingCardView" owner:self options:nil].lastObject;
  223. pokerView.playingCardView.frame = CGRectMake(0, 0, pokerView.pokWidth, pokerView.pokHeight);
  224. pokerView.playingCardView.layer.cornerRadius = 5.0;
  225. pokerView.playingCardView.layer.masksToBounds = YES;
  226. pokerView.playingCardView.layer.borderWidth = 2.0;
  227. pokerView.playingCardView.layer.borderColor = kBullPokerColor.CGColor;
  228. NSString * numberStr = [self exchangePokerNumberFromSuit:[cardArrayBull.firstObject intValue] andNumber:[cardArrayBull.lastObject intValue]];
  229. NSString * suitStr = [self exchangePokerSmallSuit:[cardArrayBull.firstObject intValue]];
  230. NSString * bigSuitStr = [self exchangePokerBigSuitFromSuit:[cardArrayBull.firstObject intValue] andNumber:[cardArrayBull.lastObject intValue]];
  231. pokerView.playingCardView.numberOfCard.image = [UIImage imageNamed:numberStr];
  232. pokerView.playingCardView.smallSuit.image = [UIImage imageNamed:suitStr];
  233. pokerView.playingCardView.bigSuit.image = [UIImage imageNamed:bigSuitStr];
  234. if (i== 0)
  235. {
  236. [pokerView.BullPokerOne addSubview:pokerView.playingCardView];
  237. }
  238. else if (i==1)
  239. {
  240. [pokerView.BullPokerTwo addSubview:pokerView.playingCardView];
  241. }
  242. else if (i==2)
  243. {
  244. [pokerView.BullPokerThree addSubview:pokerView.playingCardView];
  245. }
  246. else if (i==3)
  247. {
  248. [pokerView.BullPokerFour addSubview:pokerView.playingCardView];
  249. }
  250. else if (i==4)
  251. {
  252. [pokerView.BullPokerFive addSubview:pokerView.playingCardView];
  253. }
  254. }
  255. }
  256. }
  257. else if([poker isKindOfClass:[TexasPokerLeftAndRight class]])
  258. {//德州扑克(左右两张扑克牌)
  259. TexasPokerLeftAndRight *pokerView = (TexasPokerLeftAndRight *)poker;
  260. pokerView.pokerResultView.hidden = NO;
  261. pokerView.pokerResultView.image = [UIImage imageNamed:typeIMG];
  262. NSArray *cardsArr = [dic valueForKey:@"cards"];
  263. if (cardsArr.count == 2)
  264. {
  265. for (int i=0; i<2; ++i)
  266. {
  267. NSArray * cardArray = cardsArr[i];
  268. pokerView.playingCardView = [[NSBundle mainBundle]loadNibNamed:@"PlayingCardView" owner:self options:nil].lastObject;
  269. pokerView.playingCardView.frame = CGRectMake(0, 0, pokerView.pokWidth, pokerView.pokHeight);
  270. pokerView.playingCardView.layer.cornerRadius = 5.0;
  271. pokerView.playingCardView.layer.masksToBounds = YES;
  272. pokerView.playingCardView.layer.borderWidth = 2.0;
  273. pokerView.playingCardView.layer.borderColor = [UIColor grayColor].CGColor;
  274. NSString * numberStr = [self exchangePokerNumberFromSuit:[cardArray.firstObject intValue] andNumber:[cardArray.lastObject intValue]];
  275. NSString * suitStr = [self exchangePokerSmallSuit:[cardArray.firstObject intValue]];
  276. NSString * bigSuitStr = [self exchangePokerBigSuitFromSuit:[cardArray.firstObject intValue] andNumber:[cardArray.lastObject intValue]];
  277. pokerView.playingCardView.numberOfCard.image = [UIImage imageNamed:numberStr];
  278. pokerView.playingCardView.smallSuit.image = [UIImage imageNamed:suitStr];
  279. pokerView.playingCardView.bigSuit.image = [UIImage imageNamed:bigSuitStr];
  280. if (i== 0)
  281. {
  282. [pokerView.texasLeftAndRightOne addSubview:pokerView.playingCardView];
  283. }
  284. else if (i==1)
  285. {
  286. [pokerView.texasLeftAndRightTwo addSubview:pokerView.playingCardView];
  287. }
  288. }
  289. }
  290. }
  291. else if ([poker isKindOfClass:[TexasPokerBetween class]]){
  292. ///德州扑克(中间一副扑克牌)
  293. TexasPokerBetween *pokerView = (TexasPokerBetween *)poker;
  294. // pokerView.pokerResultView.hidden = NO;
  295. // pokerView.pokerResultView.image = [UIImage imageNamed:typeIMG];
  296. NSArray *cardsArr = [dic valueForKey:@"cards"];
  297. if (cardsArr.count == 5)
  298. {
  299. for (int i=0; i<5; ++i)
  300. {
  301. NSArray * cardArray = cardsArr[i];
  302. pokerView.playingCardView = [[NSBundle mainBundle]loadNibNamed:@"PlayingCardView" owner:self options:nil].lastObject;
  303. pokerView.playingCardView.frame = CGRectMake(0, 0, pokerView.pokWidth, pokerView.pokHeight);
  304. pokerView.playingCardView.layer.cornerRadius = 5.0;
  305. pokerView.playingCardView.layer.masksToBounds = YES;
  306. pokerView.playingCardView.layer.borderWidth = 2.0;
  307. pokerView.playingCardView.layer.borderColor = [UIColor grayColor].CGColor;
  308. NSString * numberStr = [self exchangePokerNumberFromSuit:[cardArray.firstObject intValue] andNumber:[cardArray.lastObject intValue]];
  309. NSString * suitStr = [self exchangePokerSmallSuit:[cardArray.firstObject intValue]];
  310. NSString * bigSuitStr = [self exchangePokerBigSuitFromSuit:[cardArray.firstObject intValue] andNumber:[cardArray.lastObject intValue]];
  311. pokerView.playingCardView.numberOfCard.image = [UIImage imageNamed:numberStr];
  312. pokerView.playingCardView.smallSuit.image = [UIImage imageNamed:suitStr];
  313. pokerView.playingCardView.bigSuit.image = [UIImage imageNamed:bigSuitStr];
  314. if (i == 0)
  315. {
  316. [pokerView.texasPokerOne addSubview:pokerView.playingCardView];
  317. }
  318. else if (i == 1)
  319. {
  320. [pokerView.texasPokerTwo addSubview:pokerView.playingCardView];
  321. }
  322. else if (i == 2)
  323. {
  324. [pokerView.texasPokerThree addSubview:pokerView.playingCardView];
  325. }
  326. else if (i == 3)
  327. {
  328. [pokerView.texasPokerFour addSubview:pokerView.playingCardView];
  329. }
  330. else if (i == 4)
  331. {
  332. [pokerView.texasPokerFive addSubview:pokerView.playingCardView];
  333. }
  334. }
  335. }
  336. }
  337. }
  338. @end