/****************************/ /* solitare game */ /* programmed by */ /* group dolphin */ /* h/w: pII266 64mb ram */ /* o/s: Win95 */ /* compiler: Turbo C */ /****************************/ #include #include #include #include struct queue { char *face[10]; char *suit[10]; }que ; /* decleration of only que of left up corner */ struct stak { char *face[10]; char *suit[10]; int dene; }moth,fin1,fin2,fin3,fin4,temp1,temp2,temp3,temp4,temp5,temp6,temp7; /* Struct is used for all stacks */ /* there is an error here when i remove int dene */ int eleman=0,d=1,tmp1=0,tmp2=0,tmp3=0,tmp4=0,tmp5=0,tmp6=0,tmp7=0,fn1=0,fn2=0,fn3=0,fn4=0; /* After errors of dene on stack ive used this */ struct Card { char *face; char *suit; }; typedef struct Card card; /* Stack for main directory of cards i ve used only one */ /* deck so there will be only one cards on game */ void fillDeck(card *,char *[], char *[]); /*function for assign of cards */ void shuffle(card *); /* function to mix cards */ void assgn (card *); /* function to assign cards to stacks */ void shov (void); /*function to print interface */ void deal(void); /* function to print cards */ void komand (void); /* function for command line */ void oyun (void); /* function to play game by move command */ main() { card deck[52]; char *face[] = {"ace","Deuce","three","four","five","six","seven" ,"eight","nine","ten","jack","queen","king"}; char *suit[]= {"hearts","diamonds","clubs","spades"}; srand (time(NULL)); while (d!=0) { fillDeck(deck,face,suit); shuffle(deck); shov(); assgn (deck); deal(); if (eleman==25) eleman=0; while (d!=0) { if((fn1 == 13)&&(fn2 == 13)&&(fn3 == 13)&&(fn4 == 13)) { d=0; } komand(); shov(); deal(); } gotoxy(1,20); textcolor(9); printf ("Do you want to play again? (0:exit ; 1:play again)\n"); scanf("%d",&d); } return 0; } void fillDeck(card *wdeck, char *wface[], char *wsuit[]) { int i; for (i=0;i<52;i++) { wdeck[i].face=wface[i%13]; wdeck[i].suit=wsuit[i/13]; } /* eoloop for */ } /* eofunction */ void shuffle(card *wdeck) { int i,j; card temp; for (i=0;i<52;i++) { j=rand() %52; temp=wdeck[i]; wdeck[i]=wdeck[j]; wdeck[j]=temp; } /* eoloop for */ } /* eofunction */ void assgn(card *wdeck) { int i=1; for (i=0;i<1;i++) { temp1.suit[tmp1]=wdeck[i].suit; temp1.face[tmp1]=wdeck[i].face; tmp1++; } /* eoloop for */ for (i=1;i<3;i++) { temp2.suit[tmp2]=wdeck[i].suit; temp2.face[tmp2]=wdeck[i].face; tmp2++; } /* eoloop for */ for (i=3;i<6;i++) { temp3.suit[tmp3]=wdeck[i].suit; temp3.face[tmp3]=wdeck[i].face; tmp3++; } /* eoloop for */ for (i=6;i<10;i++) { temp4.suit[tmp4]=wdeck[i].suit; temp4.face[tmp4]=wdeck[i].face; tmp4++; } /* eoloop for */ for (i=10;i<15;i++) { temp5.suit[tmp5]=wdeck[i].suit; temp5.face[tmp5]=wdeck[i].face; tmp5++; } /* eoloop for */ for (i=15;i<21;i++) { temp6.suit[tmp6]=wdeck[i].suit; temp6.face[tmp6]=wdeck[i].face; tmp6++; } /* eoloop for */ for (i=21;i<28;i++) { temp7.suit[tmp7]=wdeck[i].suit; temp7.face[tmp7]=wdeck[i].face; tmp7++; } /* eoloop for */ for (i=28;i<52;i++) { que.suit[eleman]=wdeck[i].suit; que.face[eleman]=wdeck[i].face; eleman++; } /* eoloop for */ } /* eofunction */ void shov(void) { clrscr(); textcolor(2); printf(" ********** ********** ********** ********** **********\n"); printf(" * * * * * * * * * *\n"); printf(" * * * * * * * * * *\n"); printf(" * * * * * * * * * *\n"); printf(" * * * * * * * * * *\n"); printf(" ********** ********** ********** ********** **********\n"); printf("\n\n"); printf("\t\t Solitare 1.0 programmed by dolphin \n\n"); printf("********** ********** ********** ********** ********** ********** **********\n"); printf("* * * * * * * * * * * * * *\n"); printf("* * * * * * * * * * * * * *\n"); printf("* * * * * * * * * * * * * *\n"); printf("* * * * * * * * * * * * * *\n"); printf("********** ********** ********** ********** ********** ********** **********\n"); textcolor(15); } /* eofunction */ void deal(void) /*card *wdeck*/ { gotoxy(5,3); printf ("%s",que.face[eleman-1]); gotoxy(5,4); printf ("%s",que.suit[eleman-1]); gotoxy(21,3); printf ("%s",fin1.face[fn1-1]); gotoxy(21,4); printf ("%s",fin1.suit[fn1-1]); gotoxy(33,3); printf ("%s",fin2.face[fn2-1]); gotoxy(33,4); printf ("%s",fin2.suit[fn2-1]); gotoxy(45,3); printf ("%s",fin3.face[fn3-1]); gotoxy(45,4); printf ("%s",fin3.suit[fn3-1]); gotoxy(57,3); printf ("%s",fin4.face[fn4-1]); gotoxy(57,4); printf ("%s",fin4.suit[fn4-1]); gotoxy(3,13); printf("%s",temp1.face[tmp1-1]); gotoxy(3,14); printf("%s",temp1.suit[tmp1-1]); gotoxy(14,13); printf("%s",temp2.face[tmp2-1]); gotoxy(14,14); printf("%s",temp2.suit[tmp2-1]); gotoxy(25,13); printf("%s",temp3.face[tmp3-1]); gotoxy(25,14); printf("%s",temp3.suit[tmp3-1]); gotoxy(36,13); printf("%s",temp4.face[tmp4-1]); gotoxy(36,14); printf("%s",temp4.suit[tmp4-1]); gotoxy(47,13); printf("%s",temp5.face[tmp5-1]); gotoxy(47,14); printf("%s",temp5.suit[tmp5-1]); gotoxy(58,13); printf("%s",temp6.face[tmp6-1]); gotoxy(58,14); printf("%s",temp6.suit[tmp6-1]); gotoxy(69,13); printf("%s",temp7.face[tmp7-1]); gotoxy(69,14); printf("%s",temp7.suit[tmp7-1]); } /* eofunction */ void komand (void) { char komut; gotoxy(1,20); textcolor(9); printf ("Please enter your command (?:help) > "); scanf("%c",&komut); if (komut == '?') { shov(); gotoxy(21,3); printf ("f"); gotoxy(21,4); printf ("1"); gotoxy(33,3); printf ("f"); gotoxy(33,4); printf ("2"); gotoxy(45,3); printf ("f"); gotoxy(45,4); printf ("3"); gotoxy(57,3); printf ("f"); gotoxy(57,4); printf ("4"); gotoxy(5,3); printf ("q "); gotoxy(5,4); printf ("1 "); gotoxy(3,13); printf("t1 "); gotoxy(3,14); printf("t1 "); gotoxy(14,13); printf("t2 "); gotoxy(14,14); printf("t2 "); gotoxy(25,13); printf("t3 "); gotoxy(25,14); printf("t3 "); gotoxy(36,13); printf("t4 "); gotoxy(36,14); printf("t4 "); gotoxy(47,13); printf("t5 "); gotoxy(47,14); printf("t5 "); gotoxy(58,13); printf("t6 "); gotoxy(58,14); printf("t6 "); gotoxy(69,13); printf("t7 "); gotoxy(69,14); printf("t7 "); gotoxy(2,17); textcolor(7); printf ("\n During the game you can move by simply writing source stack and target stack\n"); printf ("by using a space between them \n"); printf ("you can use command : m : to move cards \n"); printf ("you can use command : e : to exit game \n"); printf ("you can use command : ? : for this screen\n"); getch(); } /* eo if */ else if (komut == 'e') { printf ("bye\n"); getch(); d=0; } /* eo else if */ else if(komut == 'p') { printf("games start\n"); } /* eo else if */ else if(komut == 'm') { shov(); deal(); oyun(); } /* eo else if */ else printf ("eror in command !!!!!!!!!"); textcolor(15); } /* eofunction */ void oyun(void) { char *handface,*handsuit; char sournam,targnam; int sournum,targnum; gotoxy(1,20); printf("Please enter the name of group you want to take card from >"); sournam = getch(); printf("\nPlease enter the number of source stack >"); scanf("%d",&sournum); printf("\nPlease enter the name of group you want to put car >"); targnam = getch(); printf("\nPlease enter the number of target stack >"); scanf("%d",&targnum); if ((sournam=='q')&&(sournum==1)) { handface=que.face[eleman-1]; handsuit=que.suit[eleman-1]; eleman--; } /* eo if */ else if ((sournam=='t')&&(sournum==1)) { handface=temp1.face[tmp1-1]; handsuit=temp1.suit[tmp1-1]; tmp1--; } /* eo if */ else if ((sournam=='t')&&(sournum==2)) { handface=temp2.face[tmp2-1]; handsuit=temp2.suit[tmp2-1]; tmp2--; } /* eo else if */ else if ((sournam=='t')&&(sournum==3)) { handface=temp3.face[tmp3-1]; handsuit=temp3.suit[tmp3-1]; tmp3--; } /* eo else if */ else if ((sournam=='t')&&(sournum==4)) { handface=temp4.face[tmp4-1]; handsuit=temp4.suit[tmp4-1]; tmp4--; } /* eo else if */ else if ((sournam=='t')&&(sournum==5)) { handface=temp5.face[tmp5-1]; handsuit=temp5.suit[tmp5-1]; tmp5--; } /* eo else if */ else if ((sournam=='t')&&(sournum==6)) { handface=temp6.face[tmp6-1]; handsuit=temp6.suit[tmp6-1]; tmp6--; } /* eo else if */ else if ((sournam=='t')&&(sournum==7)) { handface=temp7.face[tmp7-1]; handsuit=temp7.suit[tmp7-1]; tmp7--; } /* eo else if */ else { printf("errous entrance on source\n"); getch(); getch(); } /* eo else */ if ((targnam=='t')&&(targnum==1)) { temp1.face[tmp1]=handface; temp1.suit[tmp1]=handsuit; tmp1++; } /* eo if */ else if ((targnam=='t')&&(targnum==2)) { temp2.face[tmp2]=handface; temp2.suit[tmp2]=handsuit; tmp2++; } /* eo else if */ else if ((targnam=='t')&&(targnum==3)) { temp3.face[tmp3]=handface; temp3.suit[tmp3]=handsuit; tmp3++; } /* eo else if */ else if ((targnam=='t')&&(targnum==4)) { temp4.face[tmp4]=handface; temp4.suit[tmp4]=handsuit; tmp4++; } /* eo else if */ else if ((targnam=='t')&&(targnum==5)) { temp5.face[tmp5]=handface; temp5.suit[tmp5]=handsuit; tmp5++; } /* eo else if */ else if ((targnam=='t')&&(targnum==6)) { temp6.face[tmp6]=handface; temp6.suit[tmp6]=handsuit; tmp6++; } /* eo else if */ else if ((targnam=='t')&&(targnum==7)) { temp7.face[tmp7]=handface; temp7.suit[tmp7]=handsuit; tmp7++; } /* eo else if */ else if ((targnam=='f')&&(targnum==1)) { fin1.face[fn1]=handface; fin1.suit[fn1]=handsuit; fn1++; } /* eo else if */ else if ((targnam=='f')&&(targnum==2)) { fin2.face[fn2]=handface; fin2.suit[fn2]=handsuit; fn2++; } /* eo else if */ else if ((targnam=='f')&&(targnum==3)) { fin3.face[fn3]=handface; fin3.suit[fn3]=handsuit; fn1++; } /* eo else if */ else if ((targnam=='f')&&(targnum==4)) { fin4.face[fn4]=handface; fin4.suit[fn4]=handsuit; fn1++; } /* eo else if */ else { printf ("you have an errouse enter for taget \n"); getch();getch(); } }