The following article was printed in March 1991 of the magazine 8000 PLUS"
A game programmed in BASIC
|
|
TENNIS by Jason Sharpe
In the good old days when men were men, women were women, and computers were computers, members of the former two categories used to spend hours playing tennis with members of the latter category.
|
A game of Super-Tennis in progress - with the computer (we call it Steffi) well on the way to another whitewash!
|
Jason Sharpe's TENNIS.BAS program will take you back to those heady days, with a neat implementation of this classic among classics.
At least it's not Space Invaders!
To move your bat (the one at the bottom) use the square bracket keys.
Should the ball get past you, the computer gains a point, but if you get it past the computer you get a point.
The first one to get to 10 points wins, at which point you have the choice of giving up, or playing again.
There is no 'out' at the side of the court - if the ball hits the side lines, then it will come off at the correct angle.
The same applies to a ball hitting either bat, except when your bat is moving.
If it is, then you will see the ball coming off at an unexpected angle, hopefully confusing your adversary.
This is something to be borne in mind if the game ever gets caught in a rut - it can sometimes happen that the ball is moving vertically up and down between both bats, neither bat having to move.
If this is the case, it's up to you to break the deadlock.
The game, then, is very simple.
But for the true BASIC enthusiasts among you, there is a lot of scope for adding those little extras that make all difference.
For a start, the setting is rather bland - perhaps you could give it a bit more of a feel of Flushing Meadows or Wimbledon.
To help you change other details, it might be worth making a few points about the program itself.
The ball position is held in the variables X%
and Y%
.
It is updated by adding the variables XS
and YS
, which always have the value 1.
However, if the ball is going to go out of court, the relevant XS
or XY
variable has its sign changed - if it was positive it becomes negative, if negative it becomes positive.
Thus the direction of the ball is changed, without altering the angle.
The two bats are defined and printed in the sub-routines at 420 and 440.
Throughout the listing, variables which refer to the computer are prefixed by A
, and those which refer to the player are prefixed by B
.
The variables in line 60 define the court, and MBS in line 70 is the "maximum bat speed". BAS% is the computer's bat speed. The highest this can be is two
|
Be careful of the lines 200 and 210. These are all one line. Don't press the return key until you have reached BM% and AM% respectively. By the way,
the OUT commands in those lines turn on and off the PCW buzzer
|
A well behaved program - if you do not want to play again, it returns you to BASIC in 340
|
The evidence - the tast two lines are the sub-routine that sounds the beeper and updates the score when points are won. Changing BP% to a higher number in line 110 will give you a much needed head start over the computer
|
|
[BASIC-Listing] |
Scanned by
Werner Cirsovius
December 2004
© 8000 PLUS