Question

In: Computer Science

Write a code for simple racing game (using dots) on c program.

Write a code for simple racing game (using dots) on c program.

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

#include <stdio.h>
#include <stdlib.h>
int main()
{
   int i,j;
   int size=10;
   int carPosition[10];
   int gameRunning = 1;
   int time=1;
   for(i=0;i<size;i++){
       carPosition[i]=0;
   }
   while(gameRunning){
       printf("\nTime : %d\n",time);
       time++;
       for(i=0;i<size;i++){
           char car='A'+i;
           for(j=0;j<size;j++){
               if(j==carPosition[i]){
                   printf("%c",car);
               }else{
                   printf("%c",'.');
               }
           }
           printf("\n");
           carPosition[i] += rand()%2;
       }

       for(i=0;i<size;i++){
           char car='A'+i;
           if(carPosition[i]==size){
               printf("Car %c won the race",car);
               gameRunning = 0;
           }
       }
   }

   return 0;
}


Related Solutions

Write a code for simple racing game (using dots) on c coding.
Write a code for simple racing game (using dots) on c coding.
Write a simple code for a simple connect the dots game in plain C coding.
Write a simple code for a simple connect the dots game in plain C coding.
Simple code for a game on C coding.
Simple code for a game on C coding.
Using C Write a program that will serve as a simple shell. This shell will execute...
Using C Write a program that will serve as a simple shell. This shell will execute an infinite for loop. In each iteration of the loop, the user will be presented with a prompt. When the user enters a command, the shell will tokenize the command, create a child process to execute it and wait for the child process to be over. If the user enters an invalid command, the shell should recognize the situation and show a meaningful message....
write a c# program that: The file is using a very simple form of compression in...
write a c# program that: The file is using a very simple form of compression in which there are no spaces, each word is separated by camel casing. For Example, the string "TheCatWillRun" is parsed as "The Cat Will Run". *Now for the statistics* Prints to the console the following statistics about the content in the file retrieved above. - How many of each letter are in the file - How many letters are capitalized in the file - The...
Simple code please thats easy to follow. C++ Write a program that can be used to...
Simple code please thats easy to follow. C++ Write a program that can be used to compare Insertion Sort, Merge Sort and Quick Sort. Program must: Read an array size from the user, dynamically an array of that size, and fill the array with random numbers Sort the array with the Insertion Sort, MergeSort and QuickSort algorithms studied in class, doing a time-stamp on each sort. Use your program to measure and record the time needed to sort random arrays...
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
In C++, Write the following program using a vector: A common game is the lottery card....
In C++, Write the following program using a vector: A common game is the lottery card. The card has numbered spots of which a certain number are selected at random. Write a Lotto() function that takes two arguments. The first should be the number of spots on a lottery card and the second should be the number of spots selected at random. The function should return a vector object that contains, in sorted order, the numbers selected at random. Use...
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for...
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for this game are special oriental dice. Each die has six different patterns. The six possible patterns are: Fish, Shrimp, Crab, Chicken, goldenCoin, Barrel. This game has three dice. In this game, the player can place his or her bet on any die-pattern. The amount of the winning prize is directly proportional to the number of matched dice after the two dice have been tossed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT