警告!!下列程式碼非常.....嗯你懂的!!
為遊戲十點半的程式碼
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
struct card {
char *face;
char *color;
double point;
};
typedef struct card Card;
void fill_Deck( Card * , char *[] , char *[] );
void shift_card( Card * );
void print_the_game( Card * , Card * , int * , double * , int );
int deil_Card( Card * , Card * , int , int * );
int the_money( int * , double * , int );
int main( ){
Card card[52];
Card player[10];
Card house[10];
int how_many[2] = { 0 , 0 };
double point[2] = { 0 , 0 };
int card_number = 52;
int pay_money , own_money = 2000;
int chose = 1;
int p_house = 0;
int give_house = 1;
int no = 1;
char none;
int changepage;
char *color[4] = { { "Spade" } , { "Heart" } , { "Diamond" } , { "Club" } };
char *face[13] = { { "Ace" } , { "Two" } , { "Three" } , { "Four" } , { "Five" } , { "Six" } , { "Seven" } , { "Eight" } , { "Nine" } , { "Ten" } , { "Jack" } , { "Queen" } , { "King" } };
srand( time(NULL) );
fill_Deck( card , face , color );
shift_card( card );
card_number = deil_Card( card , house , card_number , &how_many[0] );
card_number = deil_Card( card , player , card_number , &how_many[1] );
point[0] += house[how_many[0] - 1].point;
while( 1 ){
while( no ){
printf("You have %d dolors to join this game\n" , own_money );
printf("Whw much do you want fo pay?? ");
scanf("%d" , &pay_money);
while( pay_money > own_money ){
printf("You don't have so much money\n");
printf("How much do ypu want to pay?? ");
scanf("%d" , &pay_money);
}
no = 0;
}
print_the_game( house , player , how_many , point , p_house );
do{
printf("0.)Restart the game \n");
printf("1.)Give me one more card \n");
printf("2.)Finish\n");
printf("3.)Forfeit this game \n");
printf("4.)EXIT!!!\n");
printf("Chose??");
scanf(" %d" , &chose );
}while( chose < 0 || chose > 4 );
switch( chose ){
case 0:
for( changepage = 50 ; changepage > 0 ; --changepage )
printf("\n");
printf("%c" , 13 );
main();
break;
case 1:
for( changepage = 50 ; changepage > 0 ; --changepage )
printf("\n");
card_number = deil_Card( card , player , card_number , &how_many[1]);
if( point[0] < 10.5 && how_many[0] < 4 && give_house ){
if( point[0] <= 5 ){
card_number = deil_Card( card , house , card_number , &how_many[0]);
point[0] += house[how_many[0] - 1].point;
}
else if( ( point[0] > 4 ) && ( point[0] <= 7 ) && ( rand() % 2 == 0 ) ){
card_number = deil_Card( card , house , card_number , &how_many[0]);
point[0] += house[how_many[0] - 1].point;
}
else if( ( point[0] > 7 ) && ( point[0] < 9 ) && ( rand() % 10 == 0 ) ){
card_number = deil_Card( card , house , card_number , &how_many[0]);
point[0] += house[how_many[0] - 1].point;
}
else if( ( point[0] >=9 ) && ( rand() %100 == 0 ) ){
card_number = deil_Card( card , house , card_number , &how_many[0]);
point[0] += house[how_many[0] - 1].point;
}
if( how_many[1] != how_many[0] )
give_house = 0;
}
break;
case 2:
for( changepage = 50 ; changepage > 0 ; --changepage )
printf("\n");
while( point[0] < 10.5 && how_many[0] < 4 && give_house ){
if( point[0] <= 4 ){
card_number = deil_Card( card , house , card_number , &how_many[0]);
point[0] += house[how_many[0] - 1].point;
}
else if( ( point[0] > 4 ) && ( point[0] <= 7 ) && ( rand() % 2 == 0 ) ){
card_number = deil_Card( card , house , card_number , &how_many[0]);
point[0] += house[how_many[0] - 1].point;
}
else if( ( point[0] > 7 ) && ( point[0] < 9 ) && ( rand() % 10 == 0 ) ){
card_number = deil_Card( card , house , card_number , &how_many[0]);
point[0] += house[how_many[0] - 1].point;
}
else if( ( point[0] >=9 ) && ( rand() %100 == 0 ) ){
card_number = deil_Card( card , house , card_number , &how_many[0]);
point[0] += house[how_many[0] - 1].point;
}
if( how_many[1] != how_many[0] )
give_house = 0;
}
p_house = 1;
print_the_game( house , player , how_many , point , p_house );
pay_money = the_money( how_many , point , pay_money );
own_money -= pay_money;
if( pay_money < 0 )
printf(" you %s %d !!\n\n\n" , pay_money < 0 ? "WIN" : "LOST" , pay_money * -1 );
else
printf(" you %s %d !!\n\n\n" , pay_money < 0 ? "WIN" : "LOST" , pay_money );
if( own_money <= 0 ){
printf("You hove no money so \nYOU LOST!!\nPress any key to restart!");
scanf("%d" , &none );
for( changepage = 50 ; changepage > 0 ; --changepage )
printf("\n");
main();
}
how_many[0] = 0;
how_many[1] = 0;
point[0] = 0.0;
point[1] = 0.0;
p_house = 0;
no = 1;
give_house = 1;
card_number = deil_Card( card , house , card_number , &how_many[0] );
card_number = deil_Card( card , player , card_number , &how_many[1] );
point[0] += house[how_many[0] - 1].point;
break;
case 3:
for( changepage = 50 ; changepage > 0 ; --changepage )
printf("\n");
how_many[0] = 0;
how_many[1] = 0;
point[0] = 0.0;
point[1] = 0.0;
no = 1;
own_money -= pay_money;
card_number = deil_Card( card , house , card_number , &how_many[0] );
card_number = deil_Card( card , player , card_number , &how_many[1] );
point[0] += house[how_many[0] - 1].point;
give_house = 1;
break;
case 4:
return 0;
break;
}//switch( chose )
}//while( 1 )
}//main
void fill_Deck( Card *card , char *face[] , char *color[] ){
for ( int a = 0 ; a <= 51 ; ++a ) {
card[ a ].face = face[ a % 13 ];
card[ a ].color = color[ a / 13 ];
if( ( a % 13 ) <= 9 )
card[a].point = ( a % 13 ) + 1;
else
card[a].point = 0.5;
}
}
void shift_card( Card *card ){
int a;
Card temp;
for ( int b = 0; b <= 51; ++b ) {
a = rand() % 52;
temp = card[ a ];
card[ a ] = card[ b ];
card[ b ] = temp;
}
}
int deil_Card( Card *card , Card *hold , int card_number , int *how_many ){
hold[*how_many] = card[card_number - 1];
++(*how_many);
return ( card_number -= 1 );
}
void print_the_game( Card *house , Card *player , int *how_many , double *point , int p_house ){
printf("\n%5s %s %5s %6s %s %6s \n", " " , "computer" , " " , " " , "player" , " " );
point[1] = 0.0;
if( how_many[0] >= how_many[1] ){
for( int a = 0 ; a < how_many[0] ; ++a ){
if( a < how_many[0])
printf("%7s %10s " , p_house ? house[a].color : '\0' , p_house ? house[a].face : '\0' );
else
printf("%7s %10s " , " " , " " );
if( a < how_many[1]){
printf("%15s %10s \n" , player[a].color , player[a].face );
point[1] += ( player[a].point );
}
else
printf("%15s %10s \n" , " " , " " );
}//for
}//if
else{
for( int b = 0 ; b < how_many[1] ; ++b ){
if( b < how_many[0])
printf("%7s %10s " , p_house ? house[b].color : '\0' , p_house ? house[b].face : '\0' );
else
printf("%7s %10s " , " " , " " );
if( b < how_many[1] ){
printf("%15s %10s \n" , player[b].color , player[b].face );
point[1] += ( player[b].point );
}
else
printf("%7s %10s \n" , " " , " " );
}//for
}//else
if( p_house )
printf("\n%15s%2g %17s%2g\n\r" , "Point of house:" , point[0] , "Point of player:" , point[1]);
else
printf("\n%15s%2s %17s%2g\n\r" , "Point of house:" , " " , "Point of player:" , point[1]);
}
int the_money( int * how_many , double *point , int pay_money ){
if( ( how_many[1] == 2 ) && ( point[1] == 10.5 ) )
return pay_money *= ( -3 );
else if( how_many[1] == 5 ){
if( point[1] == 10.5 )
return ( pay_money *= ( -4 ) );
else if( point[1] < 10.5 )
return ( pay_money *= ( -3 ) );
}
else if( point[1] > 10.5 )
return pay_money;
else if ( ( how_many[0] == 5 ) && ( point[0] <= 10.5 ) && ( point[1] <= 10.5 ) )
return pay_money;
else if( ( point[0] <= 10.5 ) && ( point[1] <= 10.5 ) ){
if( point[0] >= point[1] )
return ( pay_money *= 2 );
else
return ( pay_money *= ( -2 ));
}
else
return ( pay_money * ( -2 ) );
}
2007年4月28日 星期六
2007年4月17日 星期二
2007年4月11日 星期三
訂閱:
文章 (Atom)