Guest User

Untitled

a guest
Jun 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. /*********************************************************************
  2. *
  3. * main.c
  4. *
  5. ********************************************************************/
  6.  
  7. #include "myLib.h"
  8. #include "texttile.h"
  9. #include <stdio.h>
  10.  
  11. #define MAXWIDTH 239
  12. #define MAXHEIGHT 159
  13. int i;
  14. int voff = 0;
  15. int hoff = 0;
  16. int dice1 =0;
  17. int bank =100;
  18. int bet=0;
  19. int dice2=0;
  20. int diceTotal=0;
  21. int diceCounter=0;
  22. int diceCounter2=0;
  23. int win=0;
  24. int lose=0;
  25. int point=0;
  26. int pass=0;
  27. int npass=0;
  28. char MoneyB[30];
  29. char MoneyC[30];
  30.  
  31. typedef enum { TITLE, BET, ROLL1,POINT,WIN,LOSE} STATE;
  32. int main(void)
  33. {
  34. u16 lastButtons;
  35. STATE gameState = TITLE;
  36.  
  37. unsigned short myScreenMap[1024] = {
  38. 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
  39. 16,17,18,19,20,21,22,23,24,25,26,27,28,29,0,0,
  40.  
  41. 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,
  42. 46,47,48,49,50,51,52,53,54,55,56,57,58,59,0,0,
  43.  
  44. 60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,
  45. 76,77,78,79,80,81,82,83,84,85,86,87,88,89,0,0,
  46.  
  47. 90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,
  48. 106,107,108,109,110,111,112,113,114,115,116,117,118,119,0,0,
  49.  
  50. 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,
  51. 136,137,138,139,140,141,142,143,144,145,146,147,148,149,0,0,
  52.  
  53. 150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,
  54. 166,167,168,169,170,171,172,173,174,175,176,177,178,179,0,0,
  55.  
  56. 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,
  57. 196,197,198,199,200,201,202,203,204,205,206,207,208,209,0,0,
  58.  
  59. 210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,
  60. 226,227,228,229,230,231,232,233,234,235,236,237,238,239,0,0,
  61.  
  62. 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
  63.  
  64. };
  65.  
  66. u16 myPalette[] = {BLACK, BLUE, GREEN, RED};
  67.  
  68. for(i=0; i<16384/4; i++)
  69. {
  70. CHARBLOCKBASE[0].tileimg[i] = fontdata_8x8[i*4] | (fontdata_8x8[i*4+1]<<4) |
  71. (fontdata_8x8[i*4+2]<<8) | (fontdata_8x8[i*4+3]<<12);
  72. }
  73.  
  74. /* for(i=0; i < 1024; i++)
  75. {
  76. SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[i];
  77. }*/
  78.  
  79.  
  80. for(i=0; i<4; i++)
  81. {
  82. PALETTE[i] = myPalette[i];
  83. }
  84. PALETTE[16] = BLACK;
  85. PALETTE[17] = YELLOW;
  86. PALETTE[32] = GREEN;
  87. PALETTE[33] = RED;
  88.  
  89. REG_DISPCTL = MODE0 | BG0_ENABLE;
  90. REG_BG0HOFS = 0;
  91. REG_BG0VOFS = 0;
  92.  
  93. REG_BG0CNT = BG_SIZE0 | SBB(31) | CBB(0);
  94.  
  95.  
  96. while(1)
  97. {
  98. lastButtons=BUTTONS;
  99. switch (gameState) {
  100. case TITLE:
  101. putText(10,5,"Craps in my pants",1);
  102. putText(15,5,"Press Start to continue",2);
  103. if(KEY_DOWN_NOW(BUTTON_START))
  104. {
  105. gameState=BET;
  106. for(i=0; i < 1024; i++)
  107. {
  108. SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
  109. }
  110. }
  111. break;
  112. case BET:
  113.  
  114. waitForVblank();
  115. sprintf(MoneyB, "Balance is $: %d", bank);
  116. putText(8,1,MoneyB,1);
  117. putText(12,1,"Press up and down to ",1);
  118. putText(13,1,"adjust bet money max 9",1);
  119. putText(15,1,"Press A:Pass B:NoPass",1);
  120. sprintf(MoneyC, "Bet: $ %d", bet);
  121. putText (18,1,MoneyC,2);
  122. //setTile(18,7,myScreenMap[numberC]);
  123.  
  124.  
  125. if(KEY_DOWN_NOW(BUTTON_DOWN)&&(lastButtons & BUTTON_DOWN))
  126. {
  127. bet--;
  128. }
  129. if(bet<0)
  130. {
  131. bet=0;
  132. }
  133.  
  134. if(KEY_DOWN_NOW(BUTTON_UP)&&(lastButtons & BUTTON_UP))
  135. {
  136.  
  137. bet++;
  138. }
  139. if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A))
  140. {
  141. gameState=ROLL1;
  142. pass++;
  143. for(i=0; i < 1024; i++)
  144. {
  145. SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
  146. }
  147. }
  148. if(KEY_DOWN_NOW(BUTTON_B)&&(lastButtons & BUTTON_B))
  149. {
  150. gameState=ROLL1;
  151. npass++;
  152. for(i=0; i < 1024; i++)
  153. {
  154. SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
  155. }
  156. }
  157. if(bet>9)bet=9;
  158.  
  159.  
  160. break;
  161. case ROLL1:
  162. putText(12,1,"Press A to roll ",1);
  163. if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A))
  164. {
  165. char MoneyB[30];
  166. dice1=rand()%6 + 1;
  167. dice2=rand()%6 + 1;
  168. diceTotal=dice1+dice2;
  169. if(diceTotal<10)setTile(8,22,myScreenMap[0]);
  170. setTile(5,7,myScreenMap[dice1]);
  171. setTile(5,10,myScreenMap[dice2]);
  172. diceCounter++;
  173. }
  174. if(pass>0&&diceCounter>0)
  175. {
  176. if(diceTotal==7||diceTotal==11)
  177. {
  178. sprintf(MoneyB, "You win! You rolled %d", diceTotal);
  179. putText(8,1,MoneyB,1);
  180. putText(10,1,"Press B to continue",2);
  181. point=diceTotal;
  182. if(KEY_DOWN_NOW(BUTTON_B)&&(lastButtons & BUTTON_B))
  183. {
  184. gameState=WIN;
  185. for(i=0; i < 1024; i++)
  186. {
  187. SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
  188. }
  189. }
  190.  
  191. }
  192. if(diceTotal==2||diceTotal==3||diceTotal==12)
  193. {
  194. sprintf(MoneyB, "You Lose! You rolled %d", diceTotal);
  195. putText(8,1,MoneyB,1);
  196. putText(10,1,"Press A",1);
  197. point=diceTotal;
  198. if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A))
  199. {
  200. gameState=LOSE;
  201. for(i=0; i < 1024; i++)
  202. {
  203. SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
  204. }
  205. }
  206. }
  207. if(diceTotal==4||diceTotal==5||diceTotal==6||diceTotal==8||diceTotal==9||diceTotal==10)
  208. {
  209. sprintf(MoneyB, "Point is %d roll again", diceTotal);
  210. putText(8,1,MoneyB,1);
  211. putText(10,1,"Press B dude",1);
  212. point=diceTotal;
  213. if(KEY_DOWN_NOW(BUTTON_B)&&(lastButtons & BUTTON_B))
  214. {
  215. for(i=0; i < 1024; i++)
  216. {
  217. SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
  218. }
  219. diceTotal=0;
  220. gameState=POINT;
  221.  
  222. }
  223.  
  224. }
  225.  
  226. }
  227. break;
  228.  
  229. case POINT:
  230. putText(12,1,"Press A to roll ",1);
  231. if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A)&&diceCounter2==0)
  232. {
  233. char MoneyB[30];
  234. dice1=rand()%6 + 1;
  235. dice2=rand()%6 + 1;
  236. diceTotal=dice1+dice2;
  237. if(diceTotal<10)setTile(8,22,myScreenMap[0]);
  238. setTile(5,7,myScreenMap[dice1]);
  239. setTile(5,10,myScreenMap[dice2]);
  240. }
  241. if(pass>0&&point==diceTotal)
  242. {
  243. sprintf(MoneyB, "You win! %d= Pointer", diceTotal);
  244. putText(8,1,MoneyB,1);
  245. putText(9,1,"Press B to continue ",1);
  246. diceCounter2++;
  247. if(KEY_DOWN_NOW(BUTTON_B)&&(lastButtons & BUTTON_B))
  248. {
  249. gameState=WIN;
  250. for(i=0; i < 1024; i++)
  251. {
  252. SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
  253. }
  254. }
  255. }
  256. if(pass>0&&point==7)
  257. {
  258. sprintf(MoneyB, "You lose! u rolled %d", diceTotal);
  259. putText(8,1,MoneyB,1);
  260. diceCounter2++;
  261. }
  262.  
  263. break;
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. case WIN:
  271. putText(10,1,"Good job, money added to bank",1);
  272. putText(11,1,"Press A to play again",1);
  273. if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A))
  274. {
  275. for(i=0; i < 1024; i++)
  276. {
  277. SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
  278. }
  279. bank+=bet;
  280. reset();
  281. gameState=BET;
  282. }
  283. break;
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290. }
  291.  
  292. return 0;
  293. }
  294.  
  295.  
  296. void reset()
  297. {
  298. int bet=0;
  299. int dice2=0;
  300. int diceTotal=0;
  301. int diceCounter=0;
  302. int win=0;
  303. int lose=0;
  304. int point=0;
  305. }
Add Comment
Please, Sign In to add comment