Game programming

Moderators: None (Apply to moderate this forum)
Number of threads: 2070
Number of posts: 5361

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Ok not so good at gaming code Posted by speedy11 on 20 Oct 2001 at 5:19 PM
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.


Report
Re: Ok not so good at gaming code Posted by nightsurfer on 20 Oct 2001 at 6:29 PM
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.


Report
Re: Ok not so good at gaming code Posted by Sephiroth2 on 22 Oct 2001 at 3:19 PM
I told you the answer on the c/c++ programming board.

Report
Re: Ok not so good at gaming code Posted by speedy11 on 22 Oct 2001 at 4:14 PM
: 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 <stdio.h>
#include <stdlib.h>
#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("\nEnter your co-ordinates ( row then column) > ");
scanf ("%d %d", &i, &j);

if( i == x_coord && j == y_coord)
{
printf("\nYou hit the target!!");
printf("\nYou took %d guesses\n", attempts + 1);
break;
}
printf("\nBad 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("\nToo many tries. Target was at Row %d Col %d\n", x_coord, y_coord);
return 0;
}

Report
Re: Ok not so good at gaming code Posted by Sand_Hawk9 on 23 Oct 2001 at 2:32 PM
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

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

#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("\nEnter row   : "
      scanf("%d", &i);
      printf("\nEnter column: "
      scanf("%d", &j);

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

      printf("\nBad 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("\nToo many tries. Target was at Row %d Col %d\n", x_coord, y_coord);

   getch();
   return 0;
}


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.


Report
DO YOUR OWN HOMEWORK! Posted by Phreak on 27 Oct 2001 at 9:23 PM
DO YOUR OWN HOMEWORK... creative try though.

Report
Re: DO YOUR OWN HOMEWORK! Posted by vdub12 on 5 Nov 2001 at 6:29 PM
: 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


Report
Re: DO YOUR OWN HOMEWORK! Posted by vdub12 on 5 Nov 2001 at 6:29 PM
: 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





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.