Add to Favorites    Make Home Page 1324 Online  
 Language Categories  
 Our Services  

Home » C++ Home » Games Home » The First Card Game in C++


Search Projects & Source Codes:

Title The First Card Game in C++
Author Anand.T.S
Author Email ianandpoonu [at]
Description Animated card play. User friendly interface.
Support 3 players - two cpu and one human player.
Category C++ » Games
Hits 55396
Code Select and Copy the Code
#include<iostream.h> #include<dos.h> #include<conio.h> #include<dos.h> #include<graphics.h> #include<stdlib.h> #include<stdio.h> #include<string.h> void*image1; void*image; float a[51],bp[40],cp[40],dp[40]; int key,car=5,var,next,esc,taken,chum,remark,bli=3,k,number,q,marksum,mon,kal= 0,jai[3],sub,symb,dont,chance=2,repe=0,repeat=0; int shuf,player=1,guess,remain=0,count=0,mark[3]; float play[3],greatest,great=232,small,remai,in1[3],in2[3],in3[3]; char wini[4][35]={" You have done it man. Well done"," You are cool man"," a wonderful game"," you are the best"}; char losi[4][35]={" You should improve your play"," Show me a better game next time"," I didn't feel any competition"," Better luck next time"}; char uttar='n'; char egg,help[39],place[3][10]={"player","cpu2","cpu1"}; int get_scancode() { union REGS inregs, outregs ; while( !kbhit( ) ) ; inregs.h.ah = 0 ; int86(22, &inregs, &outregs) ; return ( outregs.h.ah ) ; } void drawbox(char z[120]) { setcolor(15); setviewport(0,0,639,75,1); clearviewport(); setviewport(0,0,639,479,1); rectangle(0,0,639,75); outtextxy(10,10,"message box:-"); outtextxy(30,25,z); } class board { int bk,x1,y1,x2,y2; public: board(void) { x1=0; y1=76; x2=639; y2=376; } void draw(void) { setcolor(15); setbkcolor(BLACK); rectangle(0,377,639,479); rectangle(260,455,314,475); rectangle(324,455,378,475); setfillstyle(1,GREEN); floodfill(2,379,15); outtextxy(270,463,"PLAY"); outtextxy(334,463,"TAKE"); outtextxy(10,387,"Your Hand -"); rectangle(0,76,639,376); rectangle(0,150,20,250); rectangle(615,150,639,250); rectangle(269,376,369,359); settextstyle(0,1,2); outtextxy(20,160,"CPU 1"); outtextxy(639,160,"CPU 2"); settextstyle(0,0,1); outtextxy(290,365,"YOURSELF"); settextstyle(0,0,0); setfillstyle(1,BLUE); floodfill(300,300,15); } void play1(float,int); }plai; void board::play1(float ax,int cx) { int x,y,no; switch(cx) { case 1:{ x=71; y=210; no=210; }break; case 2:{ x=310; y=307; no=50; }break; case 3:{ x=560; y=190; no=230; }break; } int sym=int((ax*10 -int(ax)*10)+0.1); char symb[2]; symb[0]=char(sym); symb[1]='<no;i++) { for(long double j=0;j<9999;j++); putimage(x-50,y-50,image1,0); if(cx==1) x+=1; else if(cx==2) y-=1; else if(cx==3) x-=1; } } void drawplayer(void) { int x=20,y=410; char cy[3],by[1]; setviewport(10,400,629,450,1); clearviewport(); setviewport(0,0,639,479,1); setfillstyle(1,GREEN); floodfill(11,401,GREEN); for(int i=0;i<40;i++) { switch(int(bp[i])) { case 13:strcpy(cy,"A ");break; case 10:strcpy(cy,"J ");break; case 11:strcpy(cy,"Q ");break; case 12:strcpy(cy,"K ");break; case 9:strcpy(cy,"10");break; case 0:strcpy(cy," ");break; default:{ cy[0]=char(49+int(bp[i]+.01)); cy[1]='<=9999999;ro++); sub=symb; great=13.5; poony: if(repe==1) { if(sub<6) sub=sub+1; else if(sub==6) sub=3; } great=0; for(i=0;i<40;i++) { if((op==1)&&(sub==int((cp[i]-int(cp[i])+0.0001)*10))) { great=great>cp[i]?great:cp[i]; } if((op==2)&&(sub==int((dp[i]-int(dp[i])+0.0001)*10))) { great=great>dp[i]?great:dp[i]; } } if((great==0)&&(repe==1)) goto poony; if((great==0)&&(repe!=1)) { for(i=0;i<40;i++) { if((cp[i]==0)&&(op==1)) break; if((dp[i]==0)&&(op==2)) break; } if(op==1) cp[i]=a[number]; else dp[i]=a[number]; a[number]=0; mark[op]++; if(number==50) number=0; else number++; goto poony; } small=great; taken=mark[op]-taken; if(taken>0) { if(op==1) help[3]='2'; else if(op==2) help[3]='1'; if(taken>9) { help[15]=char(48+(taken/10)); taken=taken-10; } help[16]=char(48+taken); drawbox(help); delay(2000); } for(i=0;i<40;i++) { if((op==1)&&(symb==int((cp[i]-int(cp[i])+0.0001)*10))) { small= cp[i]<small?cp[i]:small; } if((op==2)&&(symb==int((dp[i]-int(dp[i])+0.0001)*10))) { small= dp[i]<small?dp[i]:small; } } if(op==1) i=2; else i=1; if((great<play[0])||(great<play[i])) play[op]=small; else play[op]=great; i=1; if(op==1) i=3; plai.play1(play[op],i); for(i=0;i<40;i++) { if((op==1)&&(float((int(play[op])*10)+(int((play[op]-int(play[op])+0.01)*1 0)))/10)==(float((int(cp[i])*10)+(int((cp[i]-int(cp[i])+0.01)*10)))/10)) cp[i]=0; if((op==2)&&(float((int(play[op])*10)+(int((play[op]-int(play[op])+0.01)*1 0)))/10)==(float((int(dp[i])*10)+(int((dp[i]-int(dp[i])+0.01)*10)))/10)) dp[i]=0; } symb=sub; mark[op]--; } void main() { int bgi=DETECT,vga,flag,ex; initgraph(&bgi,&vga,""); do { out: if(ex==1) break; if(uttar=='n') { clearviewport(); image=malloc(imagesize(71-50,200-50,71+50,200+50)); image1=malloc(imagesize(71-50,200-50,71+50,200+50)); setbkcolor(RED); setcolor(BLUE); rectangle(71-50,200-50,71+50,200+50); setfillstyle(1,15); floodfill(71,200,BLUE); getimage(71-50,200-50,71+50,200+50,image); } for(int i=0;i<78;i++) a[i]=0; for(i=0;i<40;i++) { bp[i]=0.0; cp[i]=0.0; dp[i]=0.0; } for(i=0;i<4;i++) { in1[i]=0; in2[i]=0; in3[i]=0; } for(i=0;i<3;i++) { mark[i]=7; jai[i]=0; play[i]=0; } kal=0;number=21;player=1;mon=0;chance=1;bli=3; repe=0;repeat=0;great=232;play[0]=0;play[1]=0;play[2]=0; ex=0;remain=0; strcpy(help,"cpu has drawn card(s) from the deck"); cleardevice(); setcolor(15); setbkcolor(8); rectangle(0,0,639,479); setcolor(15); rectangle(50,150,589,170); rectangle(10,275,629,470); settextstyle(0,0,1); outtextxy(40,292,"We have a complete deck of cards and 3 players(yourself,cpu1 and cpu2)."); outtextxy(25,307,"The 52 cards are shuffled and dealed, with each player having 7 cards each"); outtextxy(30,322,"and the rest of the cards are kept at the middle and is refered as 'deck'."); outtextxy(25,337,"Whoever finishes their hand first wins. In each round, every player has to"); outtextxy(17,352,"play a card of same symbol as played by the first player. If all the players"); outtextxy(26,367,"were able to play a card of the required symbol the round is over and the"); outtextxy(16,382,"played cards are added to the bottom of the 'deck'. Else if a player doesnot"); outtextxy(23,397,"have a card of the required symbol then he has to start drawing cards from"); outtextxy(17,412,"the 'deck' until he gets a card of the required symbol and then he plays the"); outtextxy(22,427,"card and the round continues. And now the keys used are: arrow keys to move"); outtextxy(33,442,"left and right, enter to select and esc to exit."); settextstyle(1,0,2); outtextxy(272,50,"MONKI"); settextstyle(0,0,1); outtextxy(280,140,"LOADING..."); settextstyle(3,0,1); outtextxy(10,250,"How to Play!"); do { shuf=-1; remain=0; count=0; do { if(player<3) { do { do { remain=1900; randomize(); guess=int(rand()%98); remain=guess%14; }while(remain==0); shuf=543; guess=random(98); shuf=guess%4; switch(shuf) { case 0 :{ remai=remain+.3; }break; case 1 :{ remai=remain+.4; }break; case 2 :{ remai=remain+.5; }break; case 3 :{ remai=remain+.6; }break; } flag=0; for(i=0;i<51;i++) { if(a[i]==remai) flag=1; } }while(flag==1); } else { do { if(shuf<=2) shuf++; else shuf=0; if(remain<=12) remain++; else remain=1; switch(shuf) { case 0 :{ remai=remain+.3; }break; case 1 :{ remai=remain+.4; }break; case 2 :{ remai=remain+.5; }break; case 3 :{ remai=remain+.6; }break; } flag=0; for(i=0;i<51;i++) { if(a[i]==remai) flag=1; } }while((remain>13)||(flag==1)); } count++; if(((17*(player-1))+count)==51) { setcolor(8); for(i=275;i<370;i++) line(i,138,i,147); settextstyle(0,0,1); setcolor(15); outtextxy(150,140,"LOADING COMPLETE- press any key to continue"); } setcolor(7); for(i=1;i<=10;i++) line(40+10*((17*(player-1))+count)+i,151,40+10*((17*(player-1))+count)+i,1 69); switch(player) { case 1:{ a[count-1]=remai; }break; case 2:{ a[(count+16)]=remai; }break; case 3:{ a[(count+33)]=remai; }break; } }while(count<17); player++; }while(player<4); for(i=550;i<589;i++) line(i,151,i,169); for(i=0;i<7;i++) { dp[i]=a[14+i]; a[14+i]=0; bp[i]=a[i]; a[i]=0; cp[i]=a[7+i]; a[7+i]=0; } getch(); do { repeat++;play[0]=0;play[1]=0;play[2]=0; repe=0; kal=0; clearviewport(); plai.draw(); drawbox(""); drawplayer(); do { repe++; switch(chance) { case 1:{ if(mark[0]==-1) break; for(int r=0;r<40;r++) { if(bp[r]!=0) { bli=r; break; } } staet: drawplayer(); kal=0; if(repe!=1) { for(i=0;i<40;i++) { chum=int((bp[i]+.03)*10)-int(bp[i])*10; if(chum==symb) kal=1; } } else kal=1; key=77; var=2; next=0; if(kal==1) { while(key!=28) { switch(key) { case 75:{ setfillstyle(1,0); floodfill(332,463,15); setfillstyle(1,RED); floodfill(268,463,15); var=1; }break; case 77:{ setfillstyle(1,RED); floodfill(332,463,15); setfillstyle(1,0); floodfill(268,463,15); var=2; }break; } setcolor(0); outtextxy(270,463,"PLAY"); outtextxy(334,463,"TAKE"); key=get_scancode(); if(key==1) { drawbox(" exiting......!"); for(long double ld=0;ld<49999999;ld++); ex=1;goto out; } } } else { drawbox("cards till the required symbol from the deck has been added to your hand");var=2;} if(var==1) { again: car=5; while(car!=28) { drawplayer(); rectangle(19+bli*30,400+next*20,45+bli*30,420+next*20); car=get_scancode(); if(car==1) { drawbox(" exiting......!"); for(long double ld=0;ld<49999999;ld++); ex=1;goto out; } if(((next*20+bli)<39)&&(car==77)) { for(i=(next*20+bli+1);i<39;i++) { if(bp[i]>1.0) break; } if(bp[i]>1.0) { if(i>19) { next=1; bli=i-20; } else bli=i; } } else if(((next*20+bli)>0)&&(car==75)) { for(i=(next*20+bli-1);i>0;i--) { if(bp[i]>1.0) break; } if(bp[i]>1.0) { if(i<20) { next=0; bli=i; } else bli=i-20; } } } if((int((bp[next*20+bli]-int(bp[next*20+bli])+0.001)*10)!=symb)&&(repe!=1) ) { drawbox("WRONG SYMBOL!!"); goto again; } play[0]=bp[next*20+bli]; plai.play1(play[0],2); } else if(var==2) { for(int add=0;add<40;add++) { if(bp[add]==0) break; } bp[add]=a[number]; a[number]=0; mark[0]++; if(number==50) number=0; else number++; goto staet; } for(i=0;i<40;i++) if((float((int(play[0])*10)+(int((play[0]-int(play[0])+0.01)*10)))/10)==(f loat((int(bp[i])*10)+(int((bp[i]-int(bp[i])+0.01)*10)))/10)) bp[i]=0.0; kal=0; mark[0]--; }break; case 2:{ if(mark[1]==-1) { break; } cpp(1); }break; case 3:{ if(mark[2]==-1) { break; } cpp(2); }break; } if(repe==1) { if(chance==1) symb=int((play[0]*10 -int(play[0])*10)+0.1); else if(chance==2) symb=int((play[1]*10 -int(play[1])*10)+0.1); else if(chance==3) symb=int((play[2]*10 -int(play[2])*10)+0.1); } if(chance==1) { chance=2; } else if(chance==2) { chance=3; } else if(chance==3) { chance=1; } }while(repe<3); greatest=play[0]>play[1]?play[0]:play[1]; greatest=greatest>play[2]?greatest:play[2]; if(mark[0]==0) { play[0]=0; mark[0]=-1; jai[mon]=1; mon++; } if(mark[1]==0) { play[1]=0; mark[1]=-1; jai[mon]=2; mon++; } if(mark[2]==0) { play[2]=0; mark[2]=-1; jai[mon]=3; mon++; } marksum=mark[0]+mark[1]+mark[2]+2; if((mark[0]==marksum)||(mark[1]==marksum)||(mark[2]==marksum)||(mark[0]==- 1)) drawbox("press any key to know the score! "); else drawbox("press esc to exit or press any key to start the next round "); esc=getche(); for(i=0;a[i]!=0.0;i++); a[i]=play[0]; for(i=0;a[i]!=0.0;i++); a[i]=play[1]; for(i=0;a[i]!=0.0;i++); a[i]=play[2]; if(esc==27) { drawbox(" exiting......!"); for(long double ld=0;ld<49999999;ld++); ex=1;goto out; } if((greatest==play[0])&&(mark[0]!=-1)) { chance=1; } if((greatest==play[1])&&(mark[1]!=-1)) { chance=2; } if((greatest==play[2])&&(mark[2]!=-1)) { chance=3; } clrscr(); }while((mark[0]!=marksum)&&(mark[1]!=marksum)&&(mark[2]!=marksum)&&(mark [0]!=-1)); if(mark[0]==-1) { if((mark[1]>=mark[2])&&(jai[0]==1)) { jai[1]=2; jai[2]=3; } else if((mark[1]<mark[2])&&(jai[0]==1)) { jai[1]=3; jai[2]=2; } else if((jai[1]==1)&&(jai[0]==2)) { jai[2]=3; } else if((jai[1]==1)&&(jai[0]==3)) { jai[2]=2; } else if((jai[0]!=1)&&(jai[1]!=1)) { jai[2]=1; } } else jai[2]=1; clearviewport(); setcolor(15); rectangle(0,0,639,479); setfillstyle(1,6); floodfill(150,150,15); outtextxy(180,150,"Winners on the basis of completion"); outtextxy(225,175,"First - "); outtextxy(325,175,place[(jai[0])-1]); outtextxy(225,200,"Second - "); outtextxy(325,200,place[(jai[1])-1]); outtextxy(225,225,"Third - "); outtextxy(325,225,place[(jai[2])-1]); randomize(); remark=int(rand()%4); if(jai[0]==1) outtextxy(100,275,wini[remark]); else if(jai[0]==2) outtextxy(100,275,losi[remark]); else if(jai[0]==3) outtextxy(100,275,losi[remark]); outtextxy(150,350,"Want to try again (y/n) ?"); cin>>uttar; }while(uttar=='Y'||uttar=='y'); clearviewport(); outtextxy(80,150,"This game is developed by Anand ts. Watch out! coming soon"); outtextxy(170,175,"from the same developer `The Gunman'!"); for(long double mas=0;mas<=99999999;mas++); exit(0); getch(); }

Related Source Codes

Script Name Author
Moving ball screen saver karlmarx
The Classic Game of Snake & Ladder Lakshmi Narayana .A
Railway seat reservation question which comes in sapient VyomWorld
To calculate percentile Ravi Mathur
Send to folder ANIMESH SAHU
Analog clock and calendar Nazia & Rida
Data structure (stack Implimentation) Swapnil B Adsure
Memory Game AnirudhSanyal
Easy Calc Anirudh Sanyal
GK Quiz Anirudh Sanyal
Hangman Game Manish Jain
Snakeman Manish Jain
Full month Calendar Nigi
Cursor shapes nigi


Google Groups Subscribe to SourceCodesWorld - Techies Talk

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!

ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page


Google Search


Source Codes is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions
Copyright ©2003-2017, All Rights Reserved.
Page URL:

Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review