Question

In: Computer Science

I need programing in C language (not C#,C++) Sheldon Game RPSLS: - Stone: Win against Scissors...

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!

Solutions

Expert Solution

#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;
}


Related Solutions

I am building a game in C programming language where I need to add objects of...
I am building a game in C programming language where I need to add objects of various length into a game board. The game board is 8X8 and we must account for the boundaries for the board and not go over them with our objects. The boards upper left corner is at 0x0 and we must return 1 if it fits and -1 if it does not fit. I have the following 2 functions to start with: ```int add_object_vert(int r,...
I need this program in  Paython programing language wants to maintain a list of quiz Questions, refer...
I need this program in  Paython programing language wants to maintain a list of quiz Questions, refer to as their Question Pool, in an external data file. Each Question should have the question text, point value, four answer choices, and the correct answer stored. Since they want to keep it fun, each question should also store witty retorts given as Feedback text to the user along with the answer. The application should have a Graphical User Interface (GUI), which allows the...
Suppose you play rock paper scissors against a computer: *you gain $1 for each win *you...
Suppose you play rock paper scissors against a computer: *you gain $1 for each win *you lose $1 for each lost if it is a tie, nothing happens you choose rock 50% of the time and the others 25% of the time let x be a random variable that represents the amount of money you earn after one game. (a) find the probability distribution of X (b) what is your average payoff after 20 games? (c) what is the standard...
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then prompt for the user’s selection. At that point, the program...
I need 3 examples of Uniformity and Generality in C programing. Also one example of non-regularity.
I need 3 examples of Uniformity and Generality in C programing. Also one example of non-regularity.
c programing language When a new program is executed, a new process is created with the...
c programing language When a new program is executed, a new process is created with the next available process ID. However, there are a few special processes that always have the same process ID, which are usually given the ID value less than 5 these are called system processes. Can you identify which of the two system processes have the process ID of 0 and 1 respectively?
Game of dice - fair dice: If I throw a number >= 5 I win. If...
Game of dice - fair dice: If I throw a number >= 5 I win. If he throws a number =< 4 he wins. I throw the first dice. Given that he loses(throws a number >4) what is the probability of me winning ? What is the expected number of throws before either of us wins?
Design and implement an Android application that plays the Rock-Paper-Scissors game against the computer. When played...
Design and implement an Android application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then seek for the user’s selection (using your choice of an object...
Note: I need a code and other requirement Note: programming language is c++ If you need...
Note: I need a code and other requirement Note: programming language is c++ If you need more information, please clarify what information you want. consider solving the equation sin(x) - e^(-x) = 0 write a computer program to solve the given equation using: 1- bisection method 2- fixed-point method 3- newton's intervals: {0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{8,9},{9,10} choose accuracy E = 10^(-5) Make sure you document your program Requirement : 1- Mathematical justification 2- algorithem description 3- code (program) with documentation 4-output: roots ,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT