home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
451-475
/
apd460
/
martin_macdonald
/
noughts_and_crosses.amos
/
noughts_and_crosses.amosSourceCode
< prev
next >
Wrap
AMOS Source Code
|
1978-02-21
|
12KB
|
250 lines
'
'***************************************************************************
'* tick - tack - toe *
'* *
'* by *
'* *
'* martin mc donald *
'* *
'* tick-tack-toe is a two player game *
'* press left mouse button to place an ' x ' on the screen *
'* press right mouse button to place an ' 0 ' on the screen *
'* first player to get three x's or three 0's in a row wins the game *
'* *
'* p.s i would like to thank len/ann for all the help in the past *
'* and also a man that goes out of his way to help other beginners * *
'* like myself the one and only steve bennet thanks steve.keep up *
'* the good work. *
'***************************************************************************
Dim X(9),Y(9),LABEL(18) : Rem --dimension an array of variables
Screen Open 0,320,256,32,Lowres : Rem ---- open screen 0
Curs Off : Cls 0 : Paper 0 : Rem --- hide the curser and change screen colour
Load Iff "df1:x_and_o.iff", : Rem --- load the playing grid pictire
Ink 4 : Pen 4 : Box 40,223 To 270,247
Reserve Zone(9) : Rem ---- reserve 9 zones for the playing grid
For A=1 To 9 : Rem -- loop 9 times
Read X(A) : Read Y(A) : Rem --- read x data value and y data value
Set Zone A,X(A)*45,Y(A)*45 To X(A)*45+38,Y(A)*45+38 : Rem - set up detection zones
Next : Rem -- end of >> for and next loop <<
'
'
Repeat : Rem ---- start of main loop
MK=Mouse Key : Rem --- put mouse zone into the variable mk
MZ=Mouse Zone : Rem -- put mouse zone into the variable mz
'----------------------------------------------------------------
' ******* by changing mouse key and mouse zone into short variables saves ***
' ******* a lot of typing when writing a program ****************************
'----------------------------------------------------------------
'***************** player one *************************
'--------------------------------------------------------------------------
'****** all that each one of these conditions below does is as follows.
'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
'****** 1. check if the left mouse button has been pressed
'****** 2. check what zone you are in
'****** 3. put a number in that zone ether 1 or 2
'****** 4. place cross or a nought in that zone
'****** 5. make a bell sound
'****** 6. reset the zone so that it cant be detected anymore
'------------------------------------------------------------
If MK=1 and MZ=1 : LABEL(MZ)=1
Paste Bob X(MZ)*40,Y(MZ)*40,1
Bell 5 : G=G+1 : Reset Zone MZ
End If
If MK=1 and MZ=2 : LABEL(MZ)=1
Paste Bob X(MZ)*43,Y(MZ)*40,1
Bell 5 : G=G+1 : Reset Zone MZ
End If
If MK=1 and MZ=3 : LABEL(MZ)=1
Paste Bob X(MZ)*45,Y(MZ)*40,1
Bell 5 : G=G+1 : Reset Zone MZ
End If
If MK=1 and MZ=4 : LABEL(MZ)=1
Paste Bob X(MZ)*40,Y(MZ)*45,1
Bell 5 : G=G+1 : Reset Zone MZ
End If
If MK=1 and MZ=5 : LABEL(MZ)=1
Paste Bob X(MZ)*43,Y(MZ)*45,1
Bell 5 : G=G+1 : Reset Zone MZ
End If
If MK=1 and MZ=6 : LABEL(MZ)=1
Paste Bob X(MZ)*45,Y(MZ)*45,1
Bell 5 : G=G+1 : Reset Zone MZ
End If
If MK=1 and MZ=7 : LABEL(MZ)=1
Paste Bob X(MZ)*40,Y(MZ)*47,1
Bell 5 : G=G+1 : Reset Zone MZ
End If
If MK=1 and MZ=8 : LABEL(MZ)=1
Paste Bob X(MZ)*43,Y(MZ)*47,1
Bell 5 : G=G+1 : Reset Zone MZ
End If
If MK=1 and MZ=9 : LABEL(MZ)=1
Paste Bob X(MZ)*45,Y(MZ)*47,1
Bell 5 : G=G+1 : Reset Zone MZ
End If
'------------------------------------------------------------------------
'*********************** Player two ********************
'------------------------------------------------------------------------
'*** these conditions are the same as for player one except that we **
'*** are checking the right mouse button instead of the left mouse button **
'***************************************************************************
If MK=2 and MZ=1 : LABEL(MZ)=2
Paste Bob X(MZ)*40,Y(MZ)*42,2
Bell 70 : G=G+1 : Reset Zone MZ
End If
If MK=2 and MZ=2 : LABEL(MZ)=2
Paste Bob X(MZ)*43,Y(MZ)*42,2
Bell 70 : G=G+1 : Reset Zone MZ
End If
If MK=2 and MZ=3 : LABEL(MZ)=2
Paste Bob X(MZ)*45,Y(MZ)*42,2
Bell 70 : G=G+1 : Reset Zone MZ
End If
If MK=2 and MZ=4 : LABEL(MZ)=2
Paste Bob X(MZ)*40,Y(MZ)*45,2
Bell 70 : G=G+1 : Reset Zone MZ
End If
If MK=2 and MZ=5 : LABEL(MZ)=2
Paste Bob X(MZ)*43,Y(MZ)*45,2
Bell 70 : G=G+1 : Reset Zone MZ
End If
If MK=2 and MZ=6 : LABEL(MZ)=2
Paste Bob X(MZ)*45,Y(MZ)*45,2
Bell 70 : G=G+1 : Reset Zone MZ
End If
If MK=2 and MZ=7 : LABEL(MZ)=2
Paste Bob X(MZ)*40,Y(MZ)*47,2
Bell 7 : G=G+1 : Reset Zone MZ
End If
If MK=2 and MZ=8 : LABEL(MZ)=2
Paste Bob X(MZ)*43,Y(MZ)*47,2
Bell 70 : G=G+1 : Reset Zone MZ
End If
If MK=2 and MZ=9 : LABEL(MZ)=2
Paste Bob X(MZ)*45,Y(MZ)*47,2
Bell 70 : G=G+1 : Reset Zone MZ
End If
'
' ----------------------
' ****** player X ******
' ----------------------
'*********************************************************************
'this may seem a little complicated but if you break it down
'into small pices its really quite simple.look at the conditions
'above and you will notice that the first thing that we do is check
'what mouse key has been pressed.if mk=1 then the left mouse button
'has been pressed and we then know that player one has placed an 'X'
'into one of the zones then we make the variable - LABEL - of that
'zone ether 1 for an 'X' or 2 for a 'Y'.then all we have to do is check
'wether there are three 1's or three 2's in a row and if there is then
'go to the _WINNER_X or _WINNER _O procedure.
'----------------------------------------------------------------------
'**********************************************************************
If LABEL(1)=1 and LABEL(2)=1 and LABEL(3)=1 : Gosub _WINNER_X : End If
' -------------------------
If LABEL(4)=1 and LABEL(5)=1 and LABEL(6)=1 : Gosub _WINNER_X : End If
' -------------------------
If LABEL(7)=1 and LABEL(8)=1 and LABEL(9)=1 : Gosub _WINNER_X : End If
' -------------------------
If LABEL(1)=1 and LABEL(4)=1 and LABEL(7)=1 : Gosub _WINNER_X : End If
' -------------------------
If LABEL(2)=1 and LABEL(5)=1 and LABEL(8)=1 : Gosub _WINNER_X : End If
' -------------------------
If LABEL(3)=1 and LABEL(6)=1 and LABEL(9)=1 : Gosub _WINNER_X : End If
' -------------------------
If LABEL(1)=1 and LABEL(5)=1 and LABEL(9)=1 : Gosub _WINNER_X : End If
' -------------------------
If LABEL(3)=1 and LABEL(5)=1 and LABEL(7)=1 : Gosub _WINNER_X : End If
'
' ---------------------
' ***** player O ******
' ---------------------
If LABEL(1)=2 and LABEL(2)=2 and LABEL(3)=2 : Gosub _WINNER_O : End If
' ----------------------
If LABEL(4)=2 and LABEL(5)=2 and LABEL(6)=2 : Gosub _WINNER_O : End If
' ----------------------
If LABEL(7)=2 and LABEL(8)=2 and LABEL(9)=2 : Gosub _WINNER_O : End If
' ----------------------
If LABEL(1)=2 and LABEL(4)=2 and LABEL(7)=2 : Gosub _WINNER_O : End If
' ----------------------
If LABEL(2)=2 and LABEL(5)=2 and LABEL(8)=2 : Gosub _WINNER_O : End If
' ----------------------
If LABEL(3)=2 and LABEL(6)=2 and LABEL(9)=2 : Gosub _WINNER_O : End If
' ----------------------
If LABEL(1)=2 and LABEL(5)=2 and LABEL(9)=2 : Gosub _WINNER_O : End If
' ----------------------
If LABEL(3)=2 and LABEL(5)=2 and LABEL(7)=2 : Gosub _WINNER_O : End If
'
If G=9 : Gosub _DRAW : End If : Rem ** check if all moves have been played
If MK=1 : For DELAY=1 To 1000 : Next : CO=CO+1 : If CO>12 : Gosub _RESTART : End If : End If
If MK=2 : For DELAY=1 To 1000 : Next : COU=COU+1 : If COU>12 : Gosub _RESTART : End If : End If
Wait Vbl
Until MK=3
'
'--------------------------------------------------------------------------------------------------
'*************** this is the data used to set up the zones ****************
' ------------------------------------------
Data 2,1,3,1,4,1
Data 2,2,3,2,4,2
Data 2,3,3,3,4,3
'***************
'
'************** i havent rem any of these procedures as *************************
'************** i think they are pritty straight forward ***************************
'
_WINNER_X:
For A=1 To 3
For B=1 To 70 : Bell B : Wait Vbl : Next B : Wait Vbl : Next A
Pen 3 : Locate 0,29 : Centre ">> you win player - X <<"
Wait 150 : Cls 0,42,225 To 268,245
Locate 0,29 : Centre ">> press a key please <<"
Wait Key
Edit
Return
'---------------------------------------------------------
'---------------------------------------------------------
_WINNER_O:
For A=1 To 3
For B=70 To 1 Step -1 : Bell B : Wait Vbl : Next B : Wait Vbl : Next A
Pen 3 : Locate 0,29 : Centre ">> you win player - O <<"
Wait 150 : Cls 0,42,225 To 268,245
Locate 0,29 : Centre ">> press a key please <<"
Wait Key
Edit
Return
'----------------------------------------------------------
'----------------------------------------------------------
_DRAW:
For B=1 To 70 : Bell B : Wait Vbl : Next
Pen 3 : Locate 0,29 : Centre ">> its a draw <<" : Wait 150 : Edit
Return
'-----------------------------------------------------------------
'-----------------------------------------------------------------
_RESTART:
For B=70 To 1 Step -1 : Bell B : Wait Vbl : Next
Boom : Pen 3 : Locate 0,29 : Centre ">> error:game over <<" : Wait 150 : Edit
Return
'---------------------------------------------------------------------------
'***************************************************************************
'well thats all for now i hope this programme has been of some help
'to you.feel free to mess around and change this programme as much as
'you like.break the programme into small pieces and try to find how each
'piece works.remember a big programme is only a lot of small programmes put
'togeather.here are some changes that you could do to improve this programme.
'*******************************
'1. include better sound effects.
'2. change the playing screen.
'3. improve the images.
'*******************************
'p.s - if this programme helps you in any way please let me know .after all
'we all need a little bit of encouragement dont we.best of luck with your
'programing in the future.
'
'
'
' MARTIN MC DONALD
' 17 GLASSLOUGH STREET
' MONAGHAN,CO MONAGHAN
' REP OF IRELAND
' IRELAND
'-----------------------------------------------------------------------------------