Auto Hunt - Game Using C Programming Language



Auto Hunt is simple game where the raider moves by itself towards the food. After it eats the food, the food gets generated at random point. This game seems like snake game. But, the size of raider is constant unlike snake game.



How to download the source code?
  • Click here  for source code.
  • New window will open where there is a source code of this project. You can download that code.
  • Remember to run this code runs only in Dev C++ compiler. 


Demo of the project
Check out the following video for the demo of this project.

 

For more source code and tutorial, SUBSCRBE to my YouTube channel.  



Development platform
Computer programming language (C programming language) has been used to develop this project.


Compiler
Turbo C has been used as compiler. The compiler version for Turbo C that is used is 3.7.8.9 which is also the latest one.

 

Header files used
The header files used in this project are as follows :
  1. Conio
  2. Graphics
  3. Time
  4. Stdio


Library functions used
The library functions used in this project are as follows :
  1. Bar
  2. Delay
  3. Floodfill
  4. Rand
  5. Setfillstyle



Concepts used
The concepts used in this project are as follows : 
  1. If else conditional statement
  2. Do while looping statement
  3. For loop looping statement
  4. Goto loop
  5. Switch case
Logic description
First of all, the graphic window is set to 645 (width) and 490 (height). Variable x and y are used to set the position of raider/ eater (denoted by red color), whereas the variables fx and fy are used for setting the food position.

The food is represented by green color. Initially, the food position and the the raider's positions are set to initial positions. For raider, it is (300,300), and for food is (200,200). The actual part of the program we observe on the screen takes place inside the 'for(;;)' loop. 'for(;;)' loop means, it infinitely gets looped, until the code inside of it breaks it.

For each loop, the boarders and redrawn/ remake. Then, the position of food is determined i.e. the horizontal and vertical distance between food and the raider is calculated. If food lies left to raider, the raider moves towards left, otherwise right.

When the horizontal positions of food and raider matches, the next step is to move vertically (either upward or downward). In case of food's horizontal position is greater than that of raider, the raider moves downwards until it's horizontal position/ co-ordinate matches the co-ordinate of food. Then both horizontal and vertical co-ordinates of raider matches with that of food, the next step is to generate new co-ordinate of food. The new position of food is generated by the use of rand() function. And this steps infinitely gets looped since I have not integrated any function that terminated the program.

No comments:

Post a Comment

Article Ad1