In: Computer Science
I need programing in C language (not C#,C++) Sheldon Game RPSLS:
- Stone: Win against Scissors who destroys and
against Lizard who bursts,ties with himself, and loses to Rock
Covering Paper and Spock that vaporizes the stone.
- Role: Win against Stone who he covers and
against Spock who refutes, tie with himself, and loses against
Scissors who cut it and against Lizard who eat.
- Scissors: Win against Paper who cuts and against
Lizard who decapitates, tie with himself, and loses against Stone
who destroys them and against Spock who crushes.
- Lizard: Win against Paper who eats and
against Spock who poisons,ties with himself, and loses against
Stone that breaks him and against Scissors that beheads him.
- Spock: Win against Stone who vaporizes and
against Scissors who crushes,ties with himself, and loses against
Papel who refutes him and against Lizard who it poisons him.
The program that we must implement must allow two players to play in the same console (there will be only one program),will initialize the information necessary to be able to store the name of two players and their respective markers throughout the game, to present a result message at the end of the game.
1. When the program is ready for the game to start, it will ask
PLAYER1 enter your name.
2. It will then ask PLAYER2 to enter their name.
As long as the game is not over (that is, until one of the two
players arrives to 3 points) the program:
• Will ask PLAYER1 to place his bet (can be entered in the form of
numeric code, or in the form of a character string)
• Will ask PLAYER2 to place his bet (similarly)
• Evaluate both bets, and modify the markers of each of the two
players based on bets
• When either of the two players reaches the score of 3 points, it
will be over the game
3. Message will be displayed on the screen that says: "PLAYER NAME1 has won PLAYERNAME2: SCOREBOARD "if PLAYER1 has won, where SCORE will be the result of the game (for example 3-2).
Then it will say "PLAYERNAME2 has lost against PLAYER NAME1: MARKER "because then PLAYER2 will have lost, and MARKER will have the result reversed (for example 2-3). If he player who has won is PLAYER2, the messages will indicate the victory of the PLAYER2 and PLAYER1's defeat.
As soon as the above message is presented, the program will end
the program must NOT have any input parameters at the time of
making
the program call, and all the parameters you might need (names and
bets) will be entered by keyboard (upon presentation of a message
that clearly state what the user is expected to key in (such as,say
your NAME, enter your BET, etc.)
Thanks!
#include <stdio.h>
#include <string.h>
#define MAX_NAME 31
#define TOTAL_GAMES 3
/*
[0] Stone: Win against Scissors who destroys and against Lizard who
bursts,ties with himself, and loses to Rock Covering Paper and
Spock that vaporizes the stone.
[3] Paper: Win against Stone who he covers and against Spock who
refutes, tie with himself, and loses against Scissors who cut it
and against Lizard who eat.
[1] Scissors: Win against Paper who cuts and against Lizard who
decapitates, tie with himself, and loses against Stone who destroys
them and against Spock who crushes.
[2] Lizard: Win against Paper who eats and against Spock who
poisons,ties with himself, and loses against Stone that breaks him
and against Scissors that beheads him.
[4] Spock: Win against Stone who vaporizes and against Scissors who
crushes,ties with himself, and loses against Papel who refutes him
and against Lizard who it poisons him.
*/
char victory[5][3][12];
int correction(int a)
{
if (a < 0)
a *= -1;
if (a < 3)
return a;
else
{
if (a == 4)
return 1;
else // 3
return 2;
}
}
struct player
{
char name[MAX_NAME];
int marker;
}player1 = { {0}, 0 }, player2 = { {0}, 0 };
void initialise()
{
//Stone
strcpy(victory[0][0], "Stone");
strcpy(victory[0][1], "destroys");
strcpy(victory[0][2], "bursts");
//Scissors
strcpy(victory[1][0], "Scissors");
strcpy(victory[1][1], "decapitates");
strcpy(victory[1][2], "cuts");
//Lizard
strcpy(victory[2][0], "Lizard");
strcpy(victory[2][1], "eats");
strcpy(victory[2][2], "poisons");
//Paper
strcpy(victory[3][0], "Paper");
strcpy(victory[3][1], "refutes");
strcpy(victory[3][2], "covers");
//Spock
strcpy(victory[4][0], "Spock");
strcpy(victory[4][1], "vaporizes");
strcpy(victory[4][2], "crushes");
}
int main()
{
initialise();
int bet1 = 0, bet2 = 0, incorrect = 1, game = 0;
printf("Enter Name of Player 1: ");
scanf("%s", player1.name);
printf("Enter Name of Player 2: ");
scanf("%s", player2.name);
// REORDERED TO MAKE CODE EASIER//
printf("Hello Players\nThe rules of the Game are
simple.\n");
printf("(0)Stone beats Scissors and
Lizard\n");
printf("(1)Scissors beats Lizard and Paper\n");
printf("(2)Lizard beats Paper and
Spock\n");
printf("(3)Paper beats Spock and
Stone\n");
printf("(4)Spock beats Stone and
Scissors\nMEMORIZE THEM!\n");
while (game == 0)
{
incorrect = 1;
while (incorrect)
{
printf("Player
%s, Please Place your Bet(0-4): ", player1.name);
scanf("%d",
&bet1);
if (bet1 <
0 || bet1 > 4)
printf("INCORRECT ENTRY (0-4) : RETRY\n");
else
incorrect = 0;
}
incorrect = 1;
while (incorrect)
{
printf("Player
%s, Please Place your Bet(0-4): ", player2.name);
scanf("%d",
&bet2);
if (bet1 <
0 || bet1 > 4)
printf("INCORRECT ENTRY (0-4) : RETRY\n");
else
incorrect = 0;
}
if (bet1 == bet2) // Draws are
not accounted for in game count
{
printf("Draw!!\n");
}
else
{
if (bet2 ==
((bet1 + 1) % 5) || bet2 == ((bet1 + 2) % 5)) // Player 1
wins
{
printf("%s's %s %s %s's %s\n\n", player1.name,
victory[bet1][0], victory[bet1][correction(bet2-bet1)],
player2.name, victory[bet2][0]);
if(++player1.marker == TOTAL_GAMES)
game = 1;
}
else // Player 2
Wins
{
printf("%s's %s %s %s's %s\n\n", player2.name,
victory[bet2][0], victory[bet2][correction(bet2-bet1)],
player1.name, victory[bet1][0]);
if (++player2.marker == TOTAL_GAMES)
game = 2;
}
}
}
// Assuming Player 2 has won
struct player* winner = &player2;
struct player* loser = &player1;
if (game == 1)// Player 1 Won
{
winner = &player1;
loser = &player2;
}
printf("\n%s has won against %s: %d
- %d\n", winner->name, loser->name, winner->marker,
loser->marker);
printf("%s has lost against %s: %d
- %d\n", loser->name, winner->name, loser->marker,
winner->marker);
printf("victory of the %s with a
lead of %d points\n", winner->name, winner->marker -
loser->marker);
return 0;
}