Thread: Someone help me with this game??

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    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.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    what exactly is the question?

    do you have any code to show? this sounds like homework to me...
    I came up with a cool phrase to put down here, but i forgot it...

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    its a small program

    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?
    Code:
    #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??

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    scanf( "%s", name );

    It would be better to use fgets( ) though.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    56
    Code:
    #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.

  6. #6
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    Code:
    #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]);

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    hows this so far???

    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....
    Code:
    #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??

    Code:
    printf("%s", name1[100]);
    printf("%s", name2[100]);
    Last edited by stehigs321; 10-27-2003 at 05:52 PM.

  8. #8
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    so far... please help

    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




    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);
        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);

  9. #9
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    bump

    bump

  10. #10
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  11. #11
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    Unhappy Sorry

    Sorry about that but i really need help badly on this. forgive me im new.

  12. #12
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    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);

  13. #13
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    NEW UPDATE PLEASE HELP

    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 **********
    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 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);

  14. #14
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    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
    Last edited by stehigs321; 10-30-2003 at 10:12 AM.

  15. #15
    Registered User
    Join Date
    Sep 2003
    Posts
    56

    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
    Last edited by stehigs321; 10-30-2003 at 08:47 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM