Please help with some coding..

This is a discussion on Please help with some coding.. within the C Programming forums, part of the General Programming Boards category; Hey I really need help figuring out this problem for my program study group. I need to show this code ...

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

    Please help with some coding..

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

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > scanf("%s", name1[100]);
    Should be:
    scanf("%s", name1);

    >printf("%s", name1[100]);
    Should be:
    printf("%s", name1);

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Please don't make new threads on the same subject.
    I need some quick help with code.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 06:22 PM
  2. Coding Guideline ....!!
    By imfeelingfortun in forum Tech Board
    Replies: 8
    Last Post: 10-08-2006, 08:09 AM
  3. Before Coding
    By cyberCLoWn in forum C++ Programming
    Replies: 16
    Last Post: 12-15-2003, 02:26 AM
  4. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 05:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21