Thursday, 11 September 2014

Game Coding in C Language Program with Example


C program for game design. This code is all about computer and user based play. There will be a turn for a user player & a computer. Anyone can participate this game. Just try yourself to improve your game development knowledge. 

SIMPLE GAME CODING IN C
Game coding in C is used to design a game in C language like other flash and any other java games. It is an useful resource for students. It will be consider as C mini projects or school project in C.

Q: How to create a game in C programming?
//Header file section
#include<stdio.h>
#include<conio.h>
#define TotalSticks 21
 
void main()
{
    Program variable
    int u_Choice,c_Choice,r_Sticks;
    char turn;
 
    clrscr(); //Function to clear previous output
    printf("Matchstick game being played between the computer and a user.\n");//Display function
    printf("\n Rules for the game are as follows:\n");
    printf("\n\n\t 1.There are 21 match sticks\n");
    printf("\t 2.The computer asks the player to pick 1, 2, 3, or 4 match sticks\n");
    printf("\t 3.After the person picks, the computer does its picking\n");
    printf("\t 4.Whoever is forced to pick up the last matchstick loses the game\n");
 
    printf("\n Game starts now....\n");
    r_Sticks = TotalSticks;
 
    while(1//Unconditional statement
    {
        printf("\n User's turn  \n");
        turn='u';
        printf("\n Enter ur choice : ");
        scanf("%d",&u_Choice); //Getting input function
        if(u_Choice > 4 && u_Choice < 1//Conditional statement
        {
            printf("\incorrect choice \n");
            continue;
        }
 
        r_Sticks -= u_Choice;
 
        printf("\n Remaining Sticks  : %d\n",r_Sticks);
 
        if(r_Sticks == 1)
        {
            printf("\n Computer LOST\n");
            break;
        }
 
        printf("\n Computer's turn\n  ");
        turn = 'c';
 
        printf("\n Computer is picking ....\n");
 
        c_Choice = 5 – u_Choice;
 
        printf("\n Computer choice =%d\n",c_Choice);
 
        r_Sticks -= c_Choice;
 
        printf("\n Remaining Sticks  : %d\n",remSticks);
 
        if(r_Sticks == 1)
        {
            printf("\n**** You LOST *****\n");
            printf("\n**** Computer WON the game *****\n");
            break;
        }
    }
    getch();
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.