STUDENTS 3K

  • Home
  • Students+
    • Engineering Students
    • Education Loan
    • Study Abroad Guide
    • Projects Download
  • Freshers
    • Aptitude Q & A
    • Placement Papers
    • Verbal Ability
    • Interview Questions
    • IT Company Details
    • Job Updates
  • Study Resources
    • Career Guidance
    • LAB Programs
      • C Programs
      • CPP Programs [C++]
      • Java Programs
    • Question Papers
    • Learn English
    • Notice Board
  • More –>>
    • Love calculator
You are here: Home / Important Programs / Game coding in C program

Game coding in C program

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.

  • C program to find a Number is Strong or not

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.

[Read: Software Company List] & [Aptitude online portal]

CODE SNIPPET:

Q: How to create a game in C programming?

/* Title: Game Code
Author: Vinoth Selvaraj
© http://students3k.com
*/
//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();
}

Filed Under: Important Programs Tagged With: C, LAB, Programs





Random Materials :

  • Data Mining and Data Warehousing
  • Difference Between Class and Primitive Types
  • Database Roles in SQL
  • CASE Expression in SQL
  • Concurrent Update Problem

Follow Us on Facebook

Advertisement

Company Profile

  • About Students3k
  • Contact Us
  • Earn Money Online
  • Website Archive Page
  • Privacy Policy
  • Disclaimer

Categories

  • Important Programs
  • Study Abroad
  • IT Companies
  • Career Guidance for Students
  • Teachers
  • Verbal Analogies

We Are Social

  • Facebook Fans
  • Twitter Follow
  • Google Plus
  • Pinterest Page

© Copyright 2012 - 2016 Students3k.com · All Rights Reserved · Designed By Benefits

Show