Hello I'm trying to code a pattern game, but the problem is I don't know how to keep track of the previous input of the user, so whenever a new game starts, you cannot input the previous letter. Is there a way to code this?
Example would be like :
Round 1 :
User: inputs -> A
(New Game)
User : inputs -> A // again
Invalid.
Round 2 :
User : inputs -> A
(New Game)
User : inputs -> B
Valid
Round 3 :
User : inputs -> A
(New Game)
User : inputs -> A
Invalid
The code is here :
#include <stdio.h>
#include <string.h>
int main ()
{
int i=0;
int roundCount = 1;
int pos = 0;
int over = 0;
int f = 1;
char G[2];
printf("Game Start!\n");
do
{
printf("Round %d!\n", roundCount++);
printf("Input selection upon prompt.\n");
printf("Player 1: ");
scanf(" %c", &G[0] );
printf("Player 2: ");
scanf(" %c", &G[1]);
if((G[0] == 'L' && G[1] == 'V') || (G[0] == 'V' && G[1] == 'S') || (G[0] == 'S' && G[1] == 'P') || (G[0] == 'P' && G[1] == 'R') || (G[0] == 'R' && G[1] == 'L') || (G[0] == 'R' && G[1] == 'S') || (G[0] == 'P' && G[1] == 'V') || (G[0] == 'S' && G[1] == 'L') || (G[0] == 'V' && G[1] == 'R') || (G[0] == 'L' && G[1] == 'P') )
{
f++;
pos--;
printf("Uno Wins! Pos[%d]\n\n", pos);
}
else if ((G[0] == 'R' && G[1] == 'P' ) || (G[0] == 'L' && G[1] == 'R') || (G[0] == 'R'&& G[1] == 'V') || (G[0] == 'P'&& G[1] =='S')|| (G[0] == 'P'&& G[1] == 'L') || (G[0] == 'S' && G[1] == 'R') || (G[0] == 'S' && G[1] == 'V') || (G[0] == 'L' && G[1] == 'S' )|| (G[0] == 'V'&& G[1] == 'P') || (G[0] == 'V'&& G[1] == 'L'))
{
f++;
pos++;
printf("Dos Wins Pos[%d]!\n\n", pos);
}
else if ((G[0] == 'R' && G[1] == 'R' ) || (G[0] == 'P' && G[1] == 'P') || (G[0] == 'S' && G[1] == 'S') || (G[0] == 'L' && G[1] == 'L') || (G[0] == 'V' && G[1] == 'V'))
{
f++;
pos = pos;
}
if (pos == -3 || pos == 3){
printf("Game over\n");
break;
}
if(f == 5 && pos != -3 && pos != 3)
{
if((G[0] == 'L' && G[1] == 'V') || (G[0] == 'V' && G[1] == 'S') || (G[0] == 'S' && G[1] == 'P') || (G[0] == 'P' && G[1] == 'R') || (G[0] == 'R' && G[1] == 'L') || (G[0] == 'R' && G[1] == 'S') || (G[0] == 'P' && G[1] == 'V') || (G[0] == 'S' && G[1] == 'L') || (G[0] == 'V' && G[1] == 'R') || (G[0] == 'L' && G[1] == 'P') )
{
printf("Uno Wins!\n");
break;
}
else if((G[0] == 'R' && G[1] == 'P' ) || (G[0] == 'L' && G[1] == 'R') || (G[0] == 'R'&& G[1] == 'V') || (G[0] == 'P'&& G[1] =='S')|| (G[0] == 'P'&& G[1] == 'L') || (G[0] == 'S' && G[1] == 'R') || (G[0] == 'S' && G[1] == 'V') || (G[0] == 'L' && G[1] == 'S' )|| (G[0] == 'V'&& G[1] == 'P') || (G[0] == 'V'&& G[1] == 'L'))
{
printf("Dos Win!\n");
break;
}
}
} while (f < 5);
return 0;
}
See code above, It resets at G[0] and G[1] again, i cannot keep track of the previous input because it resets. Is there a way to improve this code? I would gladly appreciate the help.