Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main()
- {
- int player,point[6],total[32767],choiesLorS; /*玩家,骰子點[],比大小,得分[]*/
- int i=1,j=0,k=0; /*擲骰子的計算迴圈變數*/
- int x=0,y,z; /*氣泡排列變數*/
- int ti,max,index=0; /*比輸贏迴圈變數,最大值,玩家位置*/
- int min=12;
- srand( time(NULL) );
- printf( "請輸入玩家人數:" );
- scanf( "%d" , &player );
- printf( "請選擇點數要 1.比大 2.比小 3.離開遊戲:" );
- scanf ( "%d" , &choiesLorS );
- switch(choiesLorS)
- {
- /*比誰的點數大模式*/
- case 1:
- {
- for ( i=1 ; i<=player ; i++ ) /*玩家N擲點數迴圈*/
- {
- for ( j=0 ; i<4 ; j++ ) /*擲點數中*/
- {
- point[j] = rand()%6 +1;
- }
- /*氣泡排列,方便計算...*/
- for( x=0 ; x<3 ; x++ )
- {
- for( y=x+1 ; y<4 ; y++ )
- {
- if( point[x]>point[y] )
- {
- z = point[x];
- point[x] = point[y];
- point[y] = z;
- }
- }
- }
- /*氣泡排列結束*/
- printf( "玩家%d的點數為:%d %d %d %d\n" , i , point[0] , point[1] , point[2] , point[3] );
- /*CHECK是否四顆點數都不同*/
- for ( k=0 ; k<3 ; k++)
- {
- if( point[k] == point[k+1])
- {
- point[k]=0;
- point[k+1]=0;
- if ( point[k] == point[k+2] )
- {
- point[k]=0;
- point[k+2]=0;
- if ( point[k] == point[k+3] )
- {
- point[k]=0;
- point[k+3]=0;
- }
- }
- }
- else
- {
- i--;
- j=0;
- printf( "玩家%d因骰子點數都不同,重擲一次\n" );
- }
- }
- /*check完畢,將相同的點數歸0,因為相同的點數不算分*/
- total[i] = point[0] + point[1] + point[2] + point[3]; /*把玩家i的總點數存進total[]裡*/
- }
- /*擲骰子結束,開始比大*/
- for ( ti=0 ; ti<player ; ti++ )
- {
- if ( total[ti]> max )
- {
- max = total[ti];
- index = index;
- }
- }
- printf( "玩家%d點數最大!恭喜玩家%d獲勝!\n\n" , index , index );
- i=1,j=0,k=0;
- x,y,z=0;
- ti,max,index=0;
- break;
- }
- /*比誰的點數小模式*/
- case 2:
- {
- for ( i=1 ; i<=player ; i++ ) /*玩家N擲點數迴圈*/
- {
- for ( j=0 ; i<4 ; j++ ) /*擲點數中*/
- {
- point[j] = rand()%6 +1;
- }
- /*氣泡排列,方便計算...*/
- for( x=0 ; x<3 ; x++ )
- {
- for( y=x+1 ; y<4 ; y++ )
- {
- if( point[x]>point[y] )
- {
- z = point[x];
- point[x] = point[y];
- point[y] = z;
- }
- }
- }
- /*氣泡排列結束*/
- printf( "玩家%d的點數為:%d %d %d %d\n" , i , point[0] , point[1] , point[2] , point[3] );
- /*CHECK是否四顆點數都不同*/
- for ( k=0 ; k<3 ; k++)
- {
- if( point[k] == point[k+1])
- {
- point[k]=0;
- point[k+1]=0;
- if ( point[k] == point[k+2] )
- {
- point[k]=0;
- point[k+2]=0;
- if ( point[k] == point[k+3] )
- {
- point[k]=0;
- point[k+3]=0;
- }
- }
- }
- else
- {
- i--;
- j=0;
- printf( "玩家%d因骰子點數都不同,重擲一次\n" );
- }
- }
- /*check完畢,將相同的點數歸0,因為相同的點數不算分*/
- total[i] = point[0] + point[1] + point[2] + point[3]; /*把玩家i的總點數存進total[]裡*/
- }
- /*擲骰子結束,開始比小*/
- for ( ti=0 ; ti<player ; ti++ )
- {
- if ( total[ti]< min )
- {
- max = total[ti];
- index = index;
- }
- }
- printf( "玩家%d點數最小!恭喜玩家%d獲勝!\n\n" , index , index );
- i=1,j=0,k=0;
- x,y,z=0;
- ti,max,index=0;
- break;
- }
- /*離開遊戲*/
- case 3:
- break;
- /*沒有這個模式*/
- default:
- printf("\n無此選項,請重新選擇。");
- break;
- }
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment