Horses Race Track Game – C Programming

This is my favorite program that I made in C programming, basically is a horses races with 10 horses.  Horses Race Track Game, this program that runs a random horse race. During each round number from 1 to 100 is generate for each horse. The horse advances one square if the random number is greater than 50. I compile using Dev-C++ for windows  and for Linux , Mac or any Unix console CC. If you running this program maybe your anti-virus can told you that maybe is a risk to running this program. Is because is very basic, but is NOT A VIRUS.

You have a list of horses, each horse have a name. You choose one, press enter and the race start.  Every second you will see that the program print process of the race. At the final the program show you the winner name and the number of the horse. This program have a you can see have good examples of programming. You can see how make a random number using srand. Also you can see  how define, sleep, function that can use in another program, and more that if and else statement. This game and code are free to share and used, as long you give me credit for it. Any question feel free to ask.

Download Source Code
Horse Race Track – Windows (.exe)
Horse Race Track – Linux (.out)


// XD Creations -  www.xd100.wordpress.com
/*
This program that runs a random horse race. During each round number from 1 to 100
is generate for each horse. The horse advances one square if the random number is
greater than 50.

*/
#include
#include
#include
#define NumberHorses 10// Number Horses
#define SpaceHorses 15 // How long is the race? 15 Spaces
#include // Delete this if you are using Linux or Mac, or any Unix console

// Function is for make the output. Something like this 1:Horse-----|
void showhorse(int HorseNumber, int HorsesPosition) {
	int X;
	printf("\t\t%d:", HorseNumber);
	for(X = 0 ; X = 1 && y 	printf("Start GO!\n");
	/*Srand generate a random number, but always is the same random number
	so, you need to use the time to change every single time the random number*/
	srand( (unsigned)time(NULL));

	showhorse(1,Ha);
	showhorse(2,Hb);
	showhorse(3,Hc);
	showhorse(4,Hq);
	showhorse(5,Hw);
	showhorse(6,He);
	showhorse(7,Hr);
	showhorse(8,Ht);
	showhorse(9,Hy);
	showhorse(10,Hu);

	while(Ha < SpaceHorses && Hb < SpaceHorses && Hc < SpaceHorses && Hq < SpaceHorses && Hw < SpaceHorses && He < SpaceHorses && Hr < SpaceHorses && Ht < SpaceHorses && Hy < SpaceHorses && Hu < SpaceHorses) {		 		if((rand () % 100)>50)
			++Ha;
		if((rand () % 100)>50)
			++Hb;
		if((rand () % 100)>50)
			++Hc;
                if((rand () % 100)>50)
			++Hq;
		if((rand () % 100)>50)
			++Hw;
		if((rand () % 100)>50)
			++He;
		if((rand () % 100)>50)
			++Hr;
		if((rand () % 100)>50)
			++Ht;
		if((rand () % 100)>50)
			++Hy;
		if((rand () % 100)>50)
			++Hu;

	printf("\n");
	printf("\t\t=======================\n");
	showhorse(1,Ha);
	showhorse(2,Hb);
	showhorse(3,Hc);
	showhorse(4,Hq);
	showhorse(5,Hw);
	showhorse(6,He);
	showhorse(7,Hr);
	showhorse(8,Ht);
	showhorse(9,Hy);
	showhorse(10,Hu);
	printf("\t\t=======================");
	printf("\n");

	Sleep(1200);/*Change this for this sleep(1); ,if you are using Linux
                or Mac, or any Unix console */
	}
	if(Ha == 15 && Hb == 15 || Ha == 15 && Hc == 15 || Hc == 15 && Hb == 15 ) {
		printf("Tie\n");
      	}
	else if (Ha == 15){
		printf("Congratulations Horse 1  -  Star\n");
	  }
	else if (Hb == 15){
		printf("Congratulations Horse 2  - Dakota\n");
	  }
	else if (Hc == 15){
		printf("Congratulations Horse 3  - Cheyenne\n");
	  }
	else if (Hq == 15){
		printf("Congratulations Horse 4  - Spirit\n");
	  }
	else if (Hw == 15){
		printf("Congratulations Horse 5  - Misty\n");
      }
	else if (He == 15){
		printf("Congratulations Horse 6  - Cowboy\n");
      }
	else if (Hr == 15){
		printf("Congratulations Horse 7  - Honey\n");
	  }
	else if (Ht == 15){
		printf("Congratulations Horse 8  - Duke\n");
	  }
	else if (Hy == 15){
		printf("Congratulations Horse 9  - Rocky\n");
	  }
	else if (Hu == 15){
		printf("Congratulations Horse 10  - Lady\n");
	  }
 	printf("\n I hope that everybody enjoy the race, see you next time!\n");
 	printf("==============================================================\n");
 	printf("                                              By: XD Creations");
	printf("\n");
    printf("\n");

}

else {
     printf("This horses is not in the race.\n\nPlease try again and choose between 1 to 10.\n\n");
     }
    system("PAUSE");
	return 0;

	}
// XD Creations	 - www.xd100.wordpress.com

3 responses to “Horses Race Track Game – C Programming

    • I believe that the hardest part it is the logic and I know the logic of the program.. if u want too I can do it in c++?

      • It would be awesome if you would, I am really interested in how different/similar the code would be!

Leave a comment