Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

1St YEAR C PROJECT

CIT, COIMBATORE
“STONE PAPER SCISSOR SPOCK AND
LIZARD GAME”

R.ADHAVAN

2004054

ECE SECTION 2

BATCH 2020 - 2024


INDEX

1. AIM
2. SOFTWARE / PLATFORM USED
3. ALGORITHM
4. FLOWCHART
5. PROGRAM – SOURCE CODE
6. SNIPS OF OUTPUT
7. INFERENCE
8. RESULT
AIM:-
To write a C program to build stone paper scissor spock and lizard game and
project the score of the user .

PLATFORM USED:-

*MinGW C COMPILER

* https://www.programiz.com/c-programming/online-compiler/

ALGORITHM FOR CONTROLLER: -


1.START
2. Get the username and the input move.
3. Compare the users input with the computer’s random
move.
4.Ask if user wants to continue, if yes repeat step 2 and 3,
else go to step 5.
5.Print the respective username and the score.
6. STOP
FLOWCHART

START
Start

Ask user for their name.


store as username.

Ask for their choice and store


as user

Computer makes a random


choice and divide it by 3 and
store as comp

Does YES
user=co Display “This
round is a Tie”
pm
If user=rock
Display “computer won the
and
game”
comp=paper

Display “user won the game”


If user=rock
and
comp=scisso
r

If
Display “computer won the
user=paper
game”
and
comp=scisso
r

If Display “ user won the game”


user=paper
and
comp=rock
Display “computer won the
If
game”
user=scissor
and
comp=rock

If Display “user won the game”


user=scissor
and
comp=paper

If Display “user won the game”


user=spock
and
comp=snake

If
user=snake Display computer won the
and game”
comp=sock
Display “user won the game”
If user=spock
and
comp=paper

Display “computer won the


game”
If
user=paper
and
comp=spock

If Display “user won the game”


user=spock
and
comp=rock

If user=rock
and Display “computer won the
comp=spock game”
If Display “computer won the
user=spock game”
and
comp=lizard

If
Display “computer won the
user=lizard
game”
and
comp=spock

If
Display “user won the game”
user=lizard
and
comp=stone

Display “user won the game”


If
user=stone
and
comp=lizard
Display “computer won the
If game”
user=paper
and
comp=lizard

If
user=lizard Display “user won the game”
and
comp=paper

If
user=lizard Display “computer won the
and game”
comp=rock

If user=rock Display “user won the game”


and
comp=lizard
Display do you want to
continue

NO

Display result

Stop
SOURCE CODE: -
#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#define SIZE 20

#define S 5

struct game

char name[SIZE];

int points;

};

char *rString() {

char *str = malloc(100);

strcpy(str, "\n---' _)\n ()\n ()\n ()\n---.()\n");

return str;

char *pString() {

char *str = malloc(100);

strcpy(str, "\n---' )\n __)\n __)\n __)\n---.__)\n");

return str;

char *sString() {

char *str = malloc(100);

strcpy(str, " \n---' )\n __)\n ___)\n (_)\n---.()\n");

return str;

char *kString() {
char *str = malloc(100);

strcpy(str, "\n---' )\n ___)\n )\n _)\n---.___)\n");

return str;

char *lString() {

char *str = malloc(100);

strcpy(str, "\n|\n|\n|\n|__\n");

return str;

int main()

struct game g;

FILE *fp,*fp1;

int random;

char c,cp;

int n, opt;

int user=0,comp=0;

char arr[S];

arr [0]='r';

arr[1]='p';

arr[2] = 's';

arr[3] = 'k';

arr[4] = 'l';

char *rptr = rString();

char *pptr = pString();

char *sptr = sString();


char *kptr = kString();

char *lptr = lString();

char d='y';

fp=fopen("gamefile", "w");

if(fp==NULL){

return 1;

printf("\n\t\t\t\t*****");

printf("\n\t\t\t\t GAME STARTS (EACH PLAYER GETS ONE CHANCE!!!)");

printf("\n\t\t\t\t*****");

do{

printf("\n Enter username: ");

scanf("%s",g.name);

printf("Enter 0 for rock(r):%sEnter 1 for paper(p):%sEnter 2 for scissor(s):%sEnter 3 for spock(k):%sEnter


4 for lizard(l):%s", rptr,pptr,sptr,kptr,lptr);

scanf("%d",&n);

c=arr[n];

random = rand()%5;

cp=arr[random];

printf("you took:%c\ncomputer took:%c", c,cp);

if (c==cp){

user++;

comp++;

printf("\n This round is a Tie.");

}
else if (c== 'r' && cp == 'p')

printf("\n Computer won this round.");

comp++;

else if (c== 'r' && cp == 's')

printf("\n User won this round.");

user++;

else if (c=='p' && cp == 's')

printf("\n Computer won this round.");

comp++;

else if (c=='p' && cp == 'r'){

printf("\n User won this round.");

user++;

else if (c == 's' && cp == 'r')

printf("\n Computer won this round.");

comp++;

else if (c == 's' && cp == 'p')

printf("\n User won this round.");

user++;

}
else if (c == 'k' && cp == 's')

printf("\n User won this round.");

user++;

else if (c == 's' && cp == 'k')

printf("\n Computer won this round.");

comp++;

else if (c == 'k' && cp == 'p')

printf("\n Computer won this round.");

comp++;

else if (c == 'p' && cp == 'k')

printf("\n User won this round.");

user++;

else if (c == 'k' && cp == 'r')

printf("\n User won this round.");

user++;

else if (c == 'r' && cp == 'k')

printf("\n Computer won this round.");

comp++;
}

else if (c == 'k' && cp == 'l')

printf("\n Computer won this round.");

comp++;

else if (c == 'l' && cp == 'k')

printf("\n User won this round.");

user++;

else if (c == 'l' && cp == 's')

printf("\n computer won this round.");

comp++;

else if (c == 's' && cp == 'l')

printf("\n User won this round.");

user++;

else if (c == 'l' && cp == 'p')

printf("\n User won this round.");

user++;

else if (c == 'p' && cp == 'l')

printf("\n Computer won this round.");


comp++;

else if (c == 'l' && cp == 'r')

printf("\n Computer won this round.");

comp++;

else if (c == 'r' && cp == 'l')

printf("\n User won this round.");

user++;

g.points=user;

fwrite(&g, sizeof(g),1,fp);

user=0, comp=0;

printf("\n-------------------------------------------------------------------------------------------");

printf("\n Next round ?(y/n)");

scanf("%c",&d);

d=getchar();

}while(d== 'y');

fclose(fp);

printf("\n Press 2 to display the details of the match: ");

scanf("%d",&opt);

if(opt==2)

fp1=fopen("gamefile","r");

if(fp1==NULL)

{
return 1;

printf("\nUsername\tpoints");

while (fread(&g, sizeof(g),1, fp1)>0)

printf("\n%s\t\t%d",g.name,g.points);

fclose(fp1);

printf("\n");

--------------------------------------------------------------------------------------------------------------------------------------------------

OUTPUT: -
REFERENCE: -
Stack overflow

Quora

MsMarsovac
RESULT: -
The C program to built a stone paper scissor spock and lizard game and
project the score of the user is performed and verified.

You might also like