View Full Version : Someone help me with this game??
stehigs321
10-26-2003, 04:18 PM
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.
what exactly is the question?
do you have any code to show? this sounds like homework to me...
stehigs321
10-26-2003, 07:23 PM
should numlives be a variable too since it isntr a constant??
i have this now. this look corect so far. What should i do now?
#include <stdio.h>
int numlives = 5
int score = 0
int round = 1
int main(void) {
char name[100] = {0};
printf("Player one, what is your name?\n");
scanf( HOW DO I SCAN A NAME? i know it has to go in the name[100])
how does it all loook so far as being setup for what i need to do??
XSquared
10-26-2003, 07:37 PM
scanf( "%s", name );
It would be better to use fgets( ) though.
stehigs321
10-27-2003, 09:17 AM
#include <stdio.h>
int numlives = 5
int score = 0
int round = 1
int main(void) {
char name[100] = {0};
printf("Player one, what is your name?\n")
scanf("%s", name);
printf("Player two, what is your name?\n")
scanf("%s", name);
hows this look so far can i put the two peoples names in the same array??? like so?? what should i do next??? please help guys. I dont think this is that tough. Im just a newbie. Im getting better. Thanks so much for everything already.
Dark Nemesis
10-27-2003, 09:25 AM
#include <stdio.h>
int numlives = 5;
int score = 0;
int round = 1;
int main(void) {
char name[100][3]= {0};
printf("Player one, what is your name?\n"); //You were missing semi-colons...
scanf("%s", name[1]);
printf("Player two, what is your name?\n");
scanf("%s", name[2]);
stehigs321
10-27-2003, 05:40 PM
Hey I really need help figuring out this problem for my program study group. I need to show this code in my presentation. I was just wondering if anyone could help me figue it out. Heres the problem.
The Problem
Input Specification
Assume in all situations, the user enters valid input.
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.
the goal is to show how a good functional design can be used to split up work amongst mostly independently working programmers, an actual function will not be provided until after the due date to the assignment.
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.
Thanks so much guys!
setup game:
Get Player1 name
Get player2 name
set player1Lives = 5
set player1Turn = 0
set player1Score = 0
set player2Lives = 5
set player2Turn = 0
set player2Score = 0
set ActivePlayer pointers to player1:
set ActivePlayerName* to player1Name
set ActivePlayerTurn* = player1Turn
set ActivePlayerLives* = player1Lives
set ActivePlayerScore* = player1Score
Play Game:
while player1 has lives or player2 has lives:
if ActivePlayer has lives
save ActivePlayerLives into tempLives
call playround(ActivePlayerName, ActivePlayerLives, ActivePlayerScore, ActivePLayerTurn);
if ActivePlayerLives is 0, display Game OVer message for ActivePlayer
Display ActivePlayer Status message
if ActivePlayerLives < tempLives
change ActivePlayer to other player
loop to Play Game:
Final Game Over:
Display player1 status message
Display player2 status message
Get Want to Play Again reply?
If yes loop to Setup Game:
Heres what i have....
#include <stdio.h>
int numlives = 5;
int score = 0;
int round = 1;
int main(void) {
char name1[100]= {0};
char name2[100]= {0};
printf("Player one, what is your name?\n");
scanf("%s", name1[100]);
printf("Player two, what is your name?\n");
scanf("%s", name2[100]);
Heres what i have so far. I dont think it works though. How do i print the names once they are stored in the array? I tried it and it printed them incorrectly.
is this how i would print the names??
printf("%s", name1[100]);
printf("%s", name2[100]);
stehigs321
10-27-2003, 11:03 PM
Heres what i have so far thanks to all of your guys help. thanks again. This is how far i am. The things i need help with are labeled with ************* please help me with anythig you can You can see the problem in the first page of this posting.
thanks again
#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);
name = name1; **************************
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);
stehigs321
10-28-2003, 10:57 AM
bump
XSquared
10-28-2003, 03:13 PM
http://cboard.cprogramming.com/announcement.php?s=&forumid=6
Read board rule #5.
stehigs321
10-28-2003, 09:01 PM
Sorry about that but i really need help badly on this. forgive me im new.
stehigs321
10-29-2003, 07:20 AM
OK i have this now please help me on how to switch to player 2?
And any other errors you see. Thanks so much.
#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);
stehigs321
10-29-2003, 12:38 PM
Heres what i have almost finished!!
How do i switch from player 1 to player two after player one's turn. then switch back when player 2 is done??
Please help me figure this out guys. I put a spot where i think the code belongs. its labeled with **********
#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 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(name,name1);
round = player1turn;
numlives = player1lives;
score = player1score;
while (player1lives>0 || player2lives>0)
{
if (numlives>0)
{
templives=numlives;
playround(char name[], int* numlives, int* score, int round);
}
if (numlives=0)
printf("Your Game is Over.\n");
activeplayerstats(); // See below.
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);
}
}
void activeplayerstats(void) {
printf("%s, you now have %d points and %d lives left.\n", name,
score, numlives);
stehigs321
10-30-2003, 09:48 AM
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
#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
stehigs321
10-30-2003, 08:44 PM
ERRORS POSTED AT BOTTOM WHATS WRONG???? WHAT CAN I DO??
#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
confuted
10-30-2003, 09:42 PM
Check it out! This is awesome!
In the bottom right hand corner of your posts, there is a button labelled "edit." I challenge you to click it and figure out how to use it, rather than double/triple/quadruple posting.
edit: "ERRORS POSTED AT BOTTOM WHATS WRONG???? WHAT CAN I DO??" Oh, and writing in ALL CAPS just discourages me from looking at your post.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.