# Writing a simple game with functions

Page 1 of 1

## 8 Replies - 4140 Views - Last Post: 09 October 2007 - 08:07 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=34802&amp;s=398fa674cec58e4c600b9d270c9c86e4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 christianthelegend

Reputation: 0
• Posts: 3
• Joined: 07-October 07

# Writing a simple game with functions

Posted 07 October 2007 - 07:18 AM

Im doing a course in C++ but ive never programmed before and our lecturer sucks... we have to write a program and im stuck and cant fin any help... . Heres the assignment :
**********************************************************

Assignment D

Unit G: Do-WHILE loop structures (reference Chapter 4)
Learning Objective:
The learner must be competent in enabling a program to repeat instructions using the DO-WHILE loop structure.

Unit H: Functions (reference Chapter 5)
Learning Objective:
The learner must be competent in writing functions.

You need to produce a simple game. The nature of the game will be similar to Scorched Earth, or Gorilla. In our version there will be 2 tanks. One red tank and one blue tank. These tanks will be positioned at the bottom left and bottom right of the screen. Each player will get a chance to adjust the angle of elevation and select 1 of 5 projectile velocities. Once the projectile velocity is selected the tank fires. You then draw the projectile ( ‘*’ ) as it travels across the screen until it strikes an object, the other tank or goes off the screen. If the projectile does strike the other tank then the game is over, with the owner of that projectile being the winner. Otherwise if the projectile is off the screen or strikes the ground, then it is the other player’s chance.

The following functions need to be implemented.
• void displayTitle(): this will clear the screen, display the title of your game, the programmer that wrote the game and it will wait here until a key is pressed.
• void displayVW(): this will clear the screen, draw the ground, draw the red and blue tanks. If the projectile speed is set to -1 then it does not draw the projectile otherwise it does.
• void fseDelay(): this is a delay loop (or two) roughly about 1/10th of a second.
• int getElevVelo(int Colour, int MenuXPosition): Must display the current players Elevation in that players colour and on that players side of the screen (top left, or top right). You can increase and decrease the elevation (angle of elevation) in 1 degree steps using the arrow keys ( <- & -> ). Max & Min elevation is limited to 170 and 10 degrees respectively. This function returns the power level chosen. The power level the velocity that the projectile will initially have and is an integer number from 1 to 5. The power level options must also be displayed on the menu. If you press Esc then it must return a -1.
• int projAI(): this is the function that will draw the projectile as it moves across the screen. It will return 0 if the projectile has hit the ground or is off the sides, 1 if Red is hit and 2 if Blue is hit.
Hint: x=cos(elevation)*power. x will then be the amount of horizontal movement of the projectile per frame/loop.

The rest of the game is up to you to figure out. Such as: the elevation settings of the red and the blue players must be remembered after each turn. The projectile must travel slow enough so that it does not “jump-over” or go through the tank without touching it. The projectile can’t be drawn off the screen.

Some things you may want to add ….(not for marks).
Wind speed! – works for driftX like gravity works on driftY;
Moving tanks …

************************************************************

If theres any body that can help me PLEASE!! Ittl be much appreciated!!

Thanks!!

Is This A Good Question/Topic? 0

## Replies To: Writing a simple game with functions

### #2 PennyBoki

• D.I.C Lover

Reputation: 55
• Posts: 2,345
• Joined: 11-December 06

## Re: Writing a simple game with functions

Posted 07 October 2007 - 07:50 AM

Hi christianthelegend, welcome.

We will help, but first we should see some effort on your side. We will no do the work for you. Please read the forum rules.

### #3 christianthelegend

Reputation: 0
• Posts: 3
• Joined: 07-October 07

## Re: Writing a simple game with functions

Posted 07 October 2007 - 08:00 AM

Im not really looknig for help with the program itself.. rather the use of functions... Im struggling to figure out from my textbook how to exactely to use functions.... if you can maybe just give me an example of how to use void displayTitle and voiddisplayVW... Im new with programming and im not really sure what these things mean, exactely..

thanks

### #4 Gizmo

Reputation: 1
• Posts: 43
• Joined: 04-October 07

## Re: Writing a simple game with functions

Posted 07 October 2007 - 08:04 AM

christianthelegend, on 7 Oct, 2007 - 10:00 AM, said:

Im not really looknig for help with the program itself.. rather the use of functions... Im struggling to figure out from my textbook how to exactely to use functions.... if you can maybe just give me an example of how to use void displayTitle and voiddisplayVW... Im new with programming and im not really sure what these things mean, exactely..

thanks

I found this </DIC> tutorial on functions and calling them. That may help you some.

### #5 PennyBoki

• D.I.C Lover

Reputation: 55
• Posts: 2,345
• Joined: 11-December 06

## Re: Writing a simple game with functions

Posted 07 October 2007 - 08:04 AM

if that is the case then I suggest you take a look at some snippets, and see how things actually work. And try read some tutorial, they are always useful.

So check the snippets area her @ </d.i.c>

This post has been edited by PennyBoki: 07 October 2007 - 08:10 AM

### #6 christianthelegend

Reputation: 0
• Posts: 3
• Joined: 07-October 07

## Re: Writing a simple game with functions

Posted 07 October 2007 - 08:08 AM

Ah thnks.. ill work on it and post my progress if i get stuck thanks

### #7 Pontus

• Cattlebruiser

Reputation: 18
• Posts: 612
• Joined: 28-December 06

## Re: Writing a simple game with functions

Posted 07 October 2007 - 12:35 PM

Yay, sombody is promoting my tutorial

### #8 Gizmo

Reputation: 1
• Posts: 43
• Joined: 04-October 07

## Re: Writing a simple game with functions

Posted 07 October 2007 - 12:38 PM

manhaeve5, on 7 Oct, 2007 - 02:35 PM, said:

Yay, sombody is promoting my tutorial

Yup Great job on that manhaeve5.

This post has been edited by Gizmo: 07 October 2007 - 12:39 PM

### #9 Pontus

• Cattlebruiser

Reputation: 18
• Posts: 612
• Joined: 28-December 06

## Re: Writing a simple game with functions

Posted 09 October 2007 - 08:07 AM

thx