From 4e0f6d1836b621a177436574b8c0d376be014a56 Mon Sep 17 00:00:00 2001 From: shikha <69755719+creater-shikha@users.noreply.github.com> Date: Fri, 14 Oct 2022 19:55:35 +0530 Subject: [PATCH] created class based RockPaperScissor code --- RockPaperScissor/main1.cpp | 127 +++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 RockPaperScissor/main1.cpp diff --git a/RockPaperScissor/main1.cpp b/RockPaperScissor/main1.cpp new file mode 100644 index 0000000..cd61a69 --- /dev/null +++ b/RockPaperScissor/main1.cpp @@ -0,0 +1,127 @@ +#include +#include +using namespace std; +class rock{ + +public: + + +int winner(int uc,int a[],string b[]){ +int w; + int cc = a[(rand() % 3)]-1; + print(uc,cc,b); + if(a[uc-1] == 1) + { + if(a[cc] == 3) + { + w = 1; + } + else if(a[cc] == 2) + { + w = 0; + } + else + { + w = -1; + } + } + else if(a[uc-1] == 2) + { + if(a[cc] == 1) + { + w = 1; + } + else if(a[cc] == 3) + { + w = 0; + } + else + { + w = -1; + } + } + else + { + if(a[cc] == 2) + { + w = 1; + } + else if(a[cc] == 1) + { + w = 0; + } + else + { + w = -1; + } + } + +return w;} + + + + +void print(int uc,int cc,string b[]){ + cout<<"You chose: "<>uc; + rock obj; + w=obj.winner(uc,a,b); + if(w == 1) + { + cout<<"You won!\n"; + } + else if(w == 0) + { + cout<<"You lose!\n"; + } + else + { + cout<<"Tie!\n"; + } + cout<<"Do you want to play again?\n"; + cout<<"Enter 1 for YES.\n"; + cout<<"Enter 2 for NO.\n"; + cin>>c; + + if(c == 2) + { + cout<<"Session being terminated...\n"; + exit(0); + } + else if(c != 1) + { + cout<<"Wrong choice! Session being terminated...\n"; + exit(0); + } + else + { + cout<<"\e[1;1H\e[2J"; + cc=0; + uc=0; + } + + + } + + + + return 0; +}