Someone help me with this game??
The Problem
Many games store a player's score and allow the player to have multiple lives. The final score of playing a game is the score the player attains at the point in time that they have no lives left. Furthermore, many of these games have several rounds or boards. If a player completes a round without losing a life, rather than the opponent getting a chance to play, that player gets to continue playing. Using these general guidelines, you will design the framework for a game program without knowing any detailed information of the game. You will only be given the function prototype for a function that executes a single round of a game as well as some other specifications for how you should run the game.
Since the goal of this exercise is to show how a good functional design can be used to split up work amongst mostly independently. an actual function will not be provided until later.
Here is the prototype of the function you will have to call that executes a single round of a game:
// Pre-condition: name is the name of the current player. numlives is a reference to
// the variable storing the number of lives left of the current player.
// score is a reference to the variable storing the score of the current
// player, and round is the round the player is currently on.
// Post-conditions: A single round of the game will be executed. The player's score
// and number of lives will be adjusted accordingly. The round
// will be completed unless the player has no more lives left.
void playround(char name[], int* numlives, int* score, int round);
You will execute a competition between two players in this mystery game. Before the game starts, ask each player their name and set their scores to 0 and their total number of lives to 5.
After this, the game begins. Allow player 1 to go first. On a particular round, if a player does NOT lose any lives, then do NOT change the turn to the next player. Instead, allow the same player to continue their turn playing the next round.
In the situation that the player does lose at least one life, the subsequent turn is taken by the other player. The only exception to either of these rules is if one player has 0 lives. If one player has 0 lives, then all turns will be given to his/her competitor till they lose all their lives.
Your main goal will be to call the playround function when appropriate, control who's turn it is and quit the game and print out the final results of both players. You should print out a status report for each player after they finish a round. (Or if they do not succeed in finishing a round and end up with 0 lives while playing a round.)
Note: This setup is DIFFERENT than standard video games where your opponent always gets to go after you lose a life. Here the change in turn is indicated by finishing a round in which you could lose more than one life. Furthermore, if you finish a round without losing a life, the turn doesn't change, but you DO have to make a new call to the playround function. It is also possible for you to finish a round, lose a life or more in the process, but not lose one at the end of the round. In this case, play advances to the other player if they have lives left.
please help heres what i have
OK i have this now please help me on how to switch to player 2?
And any other errors you see. Thanks so much.
Code:
#include <stdio.h>
char name[100] = {0};
int numlives = 5;
int score = 0;
int round = 1;
int player1live = 5;
int player1turn = 0;
int player1score = 0;
int player2lives = 5;
int player2turn = 0;
int player2score = 0;
int templives
void activeplayerstats(void);
int main(void) {
char name1[100]= {0};
char name2[100]= {0};
printf("Player one, what is your name?\n");
scanf("%s", &name1);
printf("Player two, what is your name?\n");
scanf("%s", &name2);
strcpy(name1, name)
round = player1turn;
numlives = player1lives;
score = player1score;
while (player1lives>0 || player2lives>0);
{
if (numlives>0);
{
templives=numlives;
****CALL playround(char name[], int* numlives, int* score, int round);
}
if (numlives=0)
printf("Your Game is Over.\n");
void activeplayerstats(void);
if (numlives < templives)
switch to other player ********************
}
printf("Here are the final standings:\n");
if(player1score>player2score)
printf("%s %d points\n", name1, player1score);
printf("%s %d points\n", name2, player2score);
else (
printf("%s %d points\n", name2, player2score);
printf("%s %d points\n", name1, player1score);
else {
}
void activeplayerstats(void) {
printf("%s, you now have %d points and %d lives left.\n", name,
score, numlives);
Almost done please help fix errors
OK, almost done. Here is what i havenow. The errors are posted below it. I marked the lines where the errors are with ************ followed by the line number. Hope that helps you out. please let me know how to fix the problems. Thank you guys so much for all of your help throughout this. I'm using gcc compiler in telnet on windows xp
Code:
#include <stdio.h>
#include<string.h>
char name[100] = {0};
int numlives = 5;
int score = 0;
int round = 1;
int player1lives = 5;
int player1turn = 0;
int player1score = 0;
int player2lives = 5;
int player2turn = 0;
int player2score = 0;
int templives;
void swapplayers(void);
void activeplayerstats(void); ************ line 16
void playround(char name[], int* numlives, int*score, int round); ********* line 17
int main(void) { ********** line 19
char name1[100]= {0};
char name2[100]= {0};
printf("Player one, what is your name?\n");
scanf("%s", name1);
printf("Player two, what is your name?\n");
scanf("%s", name2);
strcpy(name,name1);
round = player1turn;
numlives = player1lives;
score = player1score;
while (player1lives>0 || player2lives>0)
{
if (numlives>0)
{
templives=numlives;
playround(name, &numlives, &score,round);
}
if (numlives==0)
{
printf("Your Game is Over.\n");
}
activeplayerstats();
swapplayers( &name1, &name2); ****** line 46
}
printf("Here are the final standings:\n");
if(player1score>player2score)
{
printf("%s %d points\n", name1, player1score);
printf("%s %d points\n", name2, player2score);
}
else
{
printf("%s %d points\n", name2, player2score);
printf("%s %d points\n", name1, player1score);
}
}
void activeplayerstats(void) {
printf("%s, you now have %d points and %d lives left.\n", name,
score, numlives);
void swapplayers(char *p, char *q) {
char tmp[100]; ******** line 70
tmp = *p;
*p = *q;
*q = *tmp;
} **************** line 74
errors....
game3.c: In function 'swapplayers':
game3.c:19: parse error before '{' token
game3.c:19: declaration for parameter 'main' but no such
parameter
game3.c:17: declaration for parameter 'playround' but no such parameter
game3.c:16: declaration for parameter 'activeplayerstats' but no such parameter
game3.c:19: number of arguements doesn't match prototype
cc1: prototype declaration ********whats this??
game3.c:46: too many arguements to function 'swapplayers'
game3.c: In function 'swapplayers':
game3.c:70:incompatible types in assignment
game3.c: In function 'activeplayerstats':
game3.c:74: parse error at end of input
LIKE 2 ERRORS NOW PLEASE HELP
ERRORS POSTED AT BOTTOM WHATS WRONG???? WHAT CAN I DO??
Code:
#include <stdio.h>
#include<string.h>
int playerlives[2] = {5,5};
int round=1;
int playerscore[2] = {0,0};
int currentplayer = 0;
int templives;
void swapplayers();
void activeplayerstats(char,int,int,int);
void playround(char name[], int* numlives, int*score, int round);
int main() {
int numlives = 5;
int score = 0;
char playername[2][100]= {0};
char name[100]= {0};
printf("Player one, what is your name?\n");
scanf("%s", name[0]);
printf("Player two, what is your name?\n");
scanf("%s", name[1]);
strcpy(name,playername[currentplayer]);
numlives = playerlives[currentplayer];
score = playerscore[currentplayer];
while (numlives>0)
{
templives=numlives;
playround(name, &numlives, &score, round);
round+=1;
activeplayerstats(name[currentplayer], score, numlives,currentplayer);
if (numlives==0)
{
printf("Your Game is Over.\n");
}
swapplayers();
}
printf("Here are the final standings:\n");
if(playerscore[0]>playerscore[1])
{
printf("%s %d points\n", name[0], playerscore[0]);
printf("%s %d points\n", name[1], playerscore[1]);
}
else
{
printf("%s %d points\n", name[1], playerscore[1]);
printf("%s %d points\n", name[0], playerscore[0]);
}
return 0;
}
void activeplayerstats( char playername[], int score[currentplayer],
int numlives, int currentplayer) {
printf("%s, you now have %d points and %d lives left.\n",
playername[currentplayer],score[currentplayer],
numlives[currentplayer]);
}
void swapplayers(int numlives,int templives, int currentplayer) {
if (numlives<templives) {
if (currentplayer==0) {
currentplayer=1; }
if (currentplayer==1) {
currentplayer=0; }
}
}
void playround(char name[], int *numlives, int *score, int round){
game3.c:65: conflicting types for `activeplayerstats'
game3.c:18: previous declaration of `activeplayerstats'
game3.c: In function `activeplayerstats':
game3.c:68: subscripted value is neither array nor pointer ]
I USe GCC compiler