C program coding for games




















This article is for anyone who is interested in gameprogramming. I will take you through the basics of game programming. Here we are specifically focusing on the classic DOS games. Before we actually jump into game programming, we need to know something called event driven programming.

Event driven programming refers to that style of programming wherein the user of the application is free to choose from several options rather than be confined to a predetermined sequence of interactions with the program.

Game programming is one common example of event driven programming. A game is a closed, i. A game is a perfect combination of actions-reactions or event-responses where every response is based on the most-recently occurred event.

Graphics consists of any images that are displayed and any effects that are performed on them. Sound consists of any music or sound effects that are played during the game. The game's story includes any background before the game starts, all information the player gains during the game or when they win and any information they learn about character in the game. A story is an element of a game.

The difference between a story and a game is that a story represents the facts in an immutable i. Though graphics plays an important role in game programming, in this article we're not going to emphasize upon graphics and sound element of a game. We shall be concentrating at elementary game programming through text based interfaces.

Since game design requires one to explore one's artistic abilities, it cannot be formulated in a step by step process. However, there are certain technical steps that one needs to follow in one way or another. These are:. While writing a game program, after selecting the goal-of-game, one needs to determine its initial requirements.

For instance, to write a game program for guessing a number, you need to decide about a way to generate the number, number of players involved, number of chances allowed to the player, a scoring methodology etc. Here we are not aiming at making you a professional game programmer, rather we are concentrating more at giving you an idea of writing simple or elementary game programs.

General Description of Game: The general description of a game involves the general overview of the game, how it works, what happens on each level, etc. It describes all parts of the game from the player's perspective:. Interface is another very important aspect of game programming. The interface is the mode of communication between the computer and the player. Interface will dictate what can or cannot be done. Interface is composed of input and output. While developing interface, the programmer should develop the static display screens and dynamic display screen.

Static display is the screen which remains unaffected by the player's actions i. The dynamic display , on the other hand, is the screen which is governed by the player's actions i. What options are available to the player on the game startup? This describes what options are on the menu, how and where it appears on what screen, how the player gets there, and how he gets out.

What does the screen looks like at the beginning of the game, what are the startup parameters, where are the characters, etc? What messages, if any are on screen, and where? Intro music? Since the dynamic screen vary as per the input given by the player, their descriptions are too many to be listed here.

Some examples:. These screens include messages and responses to questions like: What happens when the player loses? What happens when the player wins? What happens when the player get the high score? Where does the player go when the game is over? How does he start a new game?

This step involves developing a proper logic for gameplay. This requires the game-programmer to answer many questions in the form of program-code. These questions include: How is game played? What are the controls? What is the Game Goal? How is the player going to achieve the game goal?

In other words, we must say that since game represents an event-driven situation, the game-programmer i. Developing logic for the scoring purposes is a subset of developing logic for the game play.

For this, you must first decide the scoring policy that you're going to follow in your game. You're going to decide the maximum number of chances allowed, the scoring mechanism, whether it is tied to time or not, etc. During this phase, the milestone events are worked out and accordingly scoring positively or negatively is carried out.

Every once in a while, the player needs to be rewarded or penalized somehow for reaching that point in the game. Each of these places where something special happens is called a Milestone Event. There are a gauge to let the player know he's on the right or wrong track, and will encourage or discourage him to keep going. Now that we have discussed these different phases in game-development, let us not develop a simple tic-tac-toe game.

Now let us analyze different elements of the game design in the program that we're going to make. Built-in functions used : kbhit : This function in C is used to determine if a key has been pressed or not. To use this function in a program include the header file conio. If a key has been pressed, then it returns a non-zero value otherwise it returns zero. It returns a random integer value every time it is called.

Header files and variables :. Draw : This function is responsible to build the boundary within which the game will be played. Skip to content. Change Language. Related Articles. Table of Contents. Improve Article.

Save Article. Like Article. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert.

Writing code in comment? Please use ide.



0コメント

  • 1000 / 1000