1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
clrscr();
int play,input,comp,tie,score=0,cscore=0;
for(int a=8;a<19;a++)
{
gotoxy(40,a);
printf("*");
}
for(int b=22;b<35;b++)
{
gotoxy(40,b);
printf("*");
}
gotoxy(20,9);
printf("YOU");
gotoxy(56,9);
printf("COMPUTER");
gotoxy(40,20);
printf("VS");
for(play=1;play<=3;play++)
{
gotoxy(69,5);
printf(" ");
gotoxy(35,3);
printf("JACK AND POY GAME");
gotoxy(20,5);
printf("Enter your choice (1)Rock (2)Paper (3)Scissors: ");
scanf("%d",&input);
while(input<1||input>3)
{
gotoxy(27,6);
printf("%d is not a valid number!\n",input);
gotoxy(17,7);
printf("Please select 1 for Rock, 2 for Paper, and 3 for Scissors:");
scanf("%d",&input);
gotoxy(17,7);
printf(" ");
gotoxy(27,6);
printf(" ");
gotoxy(69,5);
printf(" ");
}
if(input==1){
gotoxy(20,20);
printf(" ROCK ");
}
else if(input==2){
gotoxy(20,20);
printf(" PAPER ");
}
else if(input==3){
gotoxy(20,20);
printf("SCISSORS");
}
comp=1+rand() % 3;
srand(time(0));
if(comp==1){
gotoxy(55,20);
printf(" ROCK ");
tie=1;
}
else if(comp==2){
gotoxy(55,20);
printf(" PAPER ");
tie=2;
}
else if(comp==3){
gotoxy(55,20);
printf("SCISSORS");
tie=3;
}
if(input==tie){
gotoxy(25,40);
printf("You and the computer are tied");}
else if(input==1&&tie==2){
gotoxy(25,40);
printf(" Computer won ");
cscore++;
}
else if(input==1&&tie==3){
gotoxy(25,40);
printf(" You won ");
score++;
}
else if(input==2&&tie==1){
gotoxy(25,40);
printf(" You won ");
score++;
}
else if(input==2&&tie==3){
gotoxy(25,40);
printf(" Computer won ");
cscore++;
}
else if(input==3&&tie==1){
gotoxy(25,40);
printf(" Computer won ");
cscore++;
}
else if(input==3&&tie==2){
gotoxy(25,40);
printf(" You won ");
score++;
}
gotoxy(20,12);
printf("Score:%d",score);
gotoxy(56,12);
printf("Score:%d",cscore);
}
if(score>cscore){
gotoxy(32,42);
printf("YOU WON THE GAME!");
}
else if(score<cscore){
gotoxy(32,42);
printf("YOU LOOSE THE GAME!");
}
else if(score==cscore){
gotoxy(39,42);
printf("DRAW!");}
getch();
}
|