Guest User

Untitled

a guest
Feb 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main()
  6. {
  7. int player,point[6],total[32767],choiesLorS; /*玩家,骰子點[],比大小,得分[]*/
  8. int i=1,j=0,k=0; /*擲骰子的計算迴圈變數*/
  9. int x=0,y,z; /*氣泡排列變數*/
  10. int ti,max,index=0; /*比輸贏迴圈變數,最大值,玩家位置*/
  11. int min=12;
  12.  
  13. srand( time(NULL) );
  14.  
  15. printf( "請輸入玩家人數:" );
  16. scanf( "%d" , &player );
  17.  
  18. printf( "請選擇點數要 1.比大 2.比小 3.離開遊戲:" );
  19. scanf ( "%d" , &choiesLorS );
  20.  
  21. switch(choiesLorS)
  22. {
  23.  
  24. /*比誰的點數大模式*/
  25.  
  26. case 1:
  27. {
  28. for ( i=1 ; i<=player ; i++ ) /*玩家N擲點數迴圈*/
  29. {
  30. for ( j=0 ; i<4 ; j++ ) /*擲點數中*/
  31. {
  32. point[j] = rand()%6 +1;
  33. }
  34.  
  35. /*氣泡排列,方便計算...*/
  36.  
  37. for( x=0 ; x<3 ; x++ )
  38. {
  39. for( y=x+1 ; y<4 ; y++ )
  40. {
  41. if( point[x]>point[y] )
  42. {
  43. z = point[x];
  44. point[x] = point[y];
  45. point[y] = z;
  46. }
  47. }
  48. }
  49.  
  50. /*氣泡排列結束*/
  51.  
  52. printf( "玩家%d的點數為:%d %d %d %d\n" , i , point[0] , point[1] , point[2] , point[3] );
  53.  
  54. /*CHECK是否四顆點數都不同*/
  55.  
  56. for ( k=0 ; k<3 ; k++)
  57. {
  58. if( point[k] == point[k+1])
  59. {
  60. point[k]=0;
  61. point[k+1]=0;
  62. if ( point[k] == point[k+2] )
  63. {
  64. point[k]=0;
  65. point[k+2]=0;
  66. if ( point[k] == point[k+3] )
  67. {
  68. point[k]=0;
  69. point[k+3]=0;
  70. }
  71. }
  72. }
  73. else
  74. {
  75. i--;
  76. j=0;
  77. printf( "玩家%d因骰子點數都不同,重擲一次\n" );
  78. }
  79.  
  80. }
  81.  
  82. /*check完畢,將相同的點數歸0,因為相同的點數不算分*/
  83.  
  84. total[i] = point[0] + point[1] + point[2] + point[3]; /*把玩家i的總點數存進total[]裡*/
  85.  
  86. }
  87.  
  88. /*擲骰子結束,開始比大*/
  89.  
  90. for ( ti=0 ; ti<player ; ti++ )
  91. {
  92. if ( total[ti]> max )
  93. {
  94. max = total[ti];
  95. index = index;
  96. }
  97. }
  98.  
  99. printf( "玩家%d點數最大!恭喜玩家%d獲勝!\n\n" , index , index );
  100.  
  101. i=1,j=0,k=0;
  102. x,y,z=0;
  103. ti,max,index=0;
  104. break;
  105. }
  106.  
  107. /*比誰的點數小模式*/
  108.  
  109. case 2:
  110. {
  111. for ( i=1 ; i<=player ; i++ ) /*玩家N擲點數迴圈*/
  112. {
  113. for ( j=0 ; i<4 ; j++ ) /*擲點數中*/
  114. {
  115. point[j] = rand()%6 +1;
  116. }
  117.  
  118. /*氣泡排列,方便計算...*/
  119.  
  120. for( x=0 ; x<3 ; x++ )
  121. {
  122. for( y=x+1 ; y<4 ; y++ )
  123. {
  124. if( point[x]>point[y] )
  125. {
  126. z = point[x];
  127. point[x] = point[y];
  128. point[y] = z;
  129. }
  130. }
  131. }
  132.  
  133. /*氣泡排列結束*/
  134.  
  135. printf( "玩家%d的點數為:%d %d %d %d\n" , i , point[0] , point[1] , point[2] , point[3] );
  136.  
  137. /*CHECK是否四顆點數都不同*/
  138.  
  139. for ( k=0 ; k<3 ; k++)
  140. {
  141. if( point[k] == point[k+1])
  142. {
  143. point[k]=0;
  144. point[k+1]=0;
  145. if ( point[k] == point[k+2] )
  146. {
  147. point[k]=0;
  148. point[k+2]=0;
  149. if ( point[k] == point[k+3] )
  150. {
  151. point[k]=0;
  152. point[k+3]=0;
  153. }
  154. }
  155. }
  156. else
  157. {
  158. i--;
  159. j=0;
  160. printf( "玩家%d因骰子點數都不同,重擲一次\n" );
  161. }
  162.  
  163. }
  164.  
  165. /*check完畢,將相同的點數歸0,因為相同的點數不算分*/
  166.  
  167. total[i] = point[0] + point[1] + point[2] + point[3]; /*把玩家i的總點數存進total[]裡*/
  168.  
  169. }
  170.  
  171. /*擲骰子結束,開始比小*/
  172.  
  173. for ( ti=0 ; ti<player ; ti++ )
  174. {
  175. if ( total[ti]< min )
  176. {
  177. max = total[ti];
  178. index = index;
  179. }
  180. }
  181.  
  182. printf( "玩家%d點數最小!恭喜玩家%d獲勝!\n\n" , index , index );
  183.  
  184. i=1,j=0,k=0;
  185. x,y,z=0;
  186. ti,max,index=0;
  187. break;
  188. }
  189.  
  190. /*離開遊戲*/
  191.  
  192. case 3:
  193. break;
  194.  
  195. /*沒有這個模式*/
  196.  
  197. default:
  198. printf("\n無此選項,請重新選擇。");
  199. break;
  200. }
  201.  
  202. system("PAUSE");
  203. return 0;
  204. }
Add Comment
Please, Sign In to add comment