Ok not so good at gaming code - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Ok not so good at gaming code

This question is as i seen it playing it with daughter.
: Was wondering if you could write a program in C not C++,for a game my daughter wants that she found in school.
: I know you guys will have the abilty to do this if you have the time.
: (Not so good at tricky program like this)
:
: Its a small program that will play a game called find the hurkle.
: The game consists of trying to locate an object(the "HURKLE")within a grid of predetermined size.The program should generate two random numbers to represent co-ordinates on a 10 by 10 grid. The user should then be promted to find the coordinates of the hurkle(i.e. a row and column number).
: The messages, "HIT - You Found It !" or "Bad Luck - You Missed", Should be diplayed,depending upon the coordanates given by user. If the user misses,the program should give the user a clue as to the direction to try as their next guess, i.e. "UP", "DOWN","LEFT","RIGHT", or in combinations e.g."DOWN LEFT". The user should be allowed a maximum of te attempts to find the hurkle.


Comments

  • nightsurfernightsurfer Posts: 272Member
    This game is not all that difficult to program, but I do not know C or C++, but I could write it in either Java and send you the source and compiled file, or in Visual Basic and send you an exe file.

    Let me know.



    Later in life you will be more disappointed by the things you haven't done than by those you have. So cast off the bowlines and sail away into the seas of opportunity.


  • Sephiroth2Sephiroth2 Posts: 423Member
    I told you the answer on the c/c++ programming board.

  • speedy11speedy11 Posts: 14Member
    : I told you the answer on the c/c++ programming board.
    :
    I tried both boards,,thanks for you help.
    I'm struggling to run your code it has bugs in it not sure where.
    I got devcpp,and TurboC++, It won't run on either of them.
    I came up with one of my own,,no offence.
    Its a bit more easy to program ,,see what you think.

    #include
    #include
    #define MAXROWS 10
    #define MAXCOLS 10
    #define MAXTRYS 10

    int main()
    {
    int x_coord, y_coord, attempts, i, j;

    x_coord = rand() % MAXROWS+1;
    y_coord = rand() % MAXCOLS+1;

    for(attempts = 0; attempts < MAXTRYS; attempts++)
    {
    printf("
    Enter your co-ordinates ( row then column) > ");
    scanf ("%d %d", &i, &j);

    if( i == x_coord && j == y_coord)
    {
    printf("
    You hit the target!!");
    printf("
    You took %d guesses
    ", attempts + 1);
    break;
    }
    printf("
    Bad luck...You missed try...");
    if(x_coord < i)
    printf("Down ");
    else
    if(x_coord > i)
    printf("Up ");
    if(y_coord > j)
    printf("Right ");
    else
    if(y_coord < j)
    printf("Left ");
    }
    if(attempts == MAXTRYS)
    printf("
    Too many tries. Target was at Row %d Col %d
    ", x_coord, y_coord);
    return 0;
    }

  • Sand_Hawk9Sand_Hawk9 Posts: 233Member
    Howdy,

    I tried you're code and it worked perfect with mine compiler. I use Borland C++ 5.02(No command line shit!) :-). I changed some stuff so I looks better. If you still have problems, send me a mail and I will send you the executable. Maybe you can tell me the what errors you get. Here is the code

    [code]
    #include
    #include
    #include

    #define MAXROWS 10
    #define MAXCOLS 10
    #define MAXTRYS 10

    int main()
    {
    int x_coord, y_coord, attempts, i, j;

    x_coord = rand() % MAXROWS+1;
    y_coord = rand() % MAXCOLS+1;

    for(attempts = 0; attempts < MAXTRYS; attempts++)
    {
    printf("
    Enter row : "
    scanf("%d", &i);
    printf("
    Enter column: "
    scanf("%d", &j);

    if( i == x_coord && j == y_coord)
    {
    printf("
    You hit the target!!");
    printf("
    You took %d guesses
    ", attempts + 1);
    break;
    }

    printf("
    Bad luck...You missed! Try ");
    if(x_coord < i)
    printf("Down ");
    else if(x_coord > i)
    printf("Up ");

    if(y_coord > j)
    printf("Right ");
    else if(y_coord < j)
    printf("Left ");
    }

    if(attempts == MAXTRYS)
    printf("
    Too many tries. Target was at Row %d Col %d
    ", x_coord, y_coord);

    getch();
    return 0;
    }
    [/code]

    You might want to remove the getch(); statement. I just put it there to see if the output is correct. Tell me what you think. I didn't do much to change but it works perfect on my compiler. :-)

    Sand Hawk
    Member of the Stupid Coders
    http://www.stupidcoders.cjb.net

    - Earth is 98% full. Please delete anybody you can.


  • PhreakPhreak Posts: 54Member
    DO YOUR OWN HOMEWORK... creative try though.

  • vdub12vdub12 Posts: 19Member
    : DO YOUR OWN HOMEWORK... creative try though.
    :
    Boy that comment was sure nice

    I know hardly anything about programming but really want to put some of my 3D models in to games.

    I hope I dont get comments like that when I ask questions that someone might think is stupid


  • vdub12vdub12 Posts: 19Member
    : DO YOUR OWN HOMEWORK... creative try though.
    :
    Boy that comment was sure nice

    I know hardly anything about programming but really want to put some of my 3D models in to games.

    I hope I dont get comments like that when I ask questions that someone might think is stupid


Sign In or Register to comment.