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 >
AMOS Source Code  |  1978-02-21  |  12KB  |  250 lines

  1. '
  2. '*************************************************************************** 
  3. '*                           tick - tack - toe                             * 
  4. '*                                                                         *                                 
  5. '*                                  by                                     * 
  6. '*                                                                         * 
  7. '*                            martin mc donald                             * 
  8. '*                                                                         * 
  9. '*                    tick-tack-toe is a two player game                   * 
  10. '*           press left mouse button to place an ' x ' on the screen       * 
  11. '*           press right mouse button to place an ' 0 ' on the screen      * 
  12. '*      first player to get three x's or three 0's in a row wins the game  * 
  13. '*                                                                         * 
  14. '*      p.s  i would  like to thank len/ann for all the help in the past   *                                                           
  15. '*      and also a man that goes out of his way to help other beginners    *                                                                   * 
  16. '*      like myself the one and only steve bennet thanks steve.keep up     *   
  17. '*      the good work.                                                     * 
  18. '*************************************************************************** 
  19. Dim X(9),Y(9),LABEL(18) : Rem --dimension an array of variables
  20. Screen Open 0,320,256,32,Lowres : Rem ---- open screen 0 
  21. Curs Off : Cls 0 : Paper 0 : Rem --- hide the curser and change screen colour 
  22. Load Iff "df1:x_and_o.iff", : Rem --- load the playing grid pictire
  23. Ink 4 : Pen 4 : Box 40,223 To 270,247
  24. Reserve Zone(9) : Rem ---- reserve 9 zones for the playing grid
  25. For A=1 To 9 : Rem -- loop 9 times
  26. Read X(A) : Read Y(A) : Rem --- read x data value and y data value 
  27. Set Zone A,X(A)*45,Y(A)*45 To X(A)*45+38,Y(A)*45+38 : Rem - set up detection zones 
  28. Next : Rem -- end of >> for and next loop <<
  29. '
  30. '
  31. Repeat : Rem ---- start of main loop
  32.        MK=Mouse Key : Rem --- put mouse zone into the variable mk
  33.                      MZ=Mouse Zone : Rem -- put mouse zone into the variable mz 
  34. '----------------------------------------------------------------
  35. ' ******* by changing mouse key and mouse zone into short variables saves ***  
  36. ' ******* a lot of typing when writing a program ****************************
  37. '----------------------------------------------------------------
  38. '*****************   player one  ************************* 
  39. '--------------------------------------------------------------------------
  40. '****** all that each one of these conditions below does is as follows.  
  41. 'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv         
  42. '****** 1. check if the left mouse button has been pressed 
  43. '****** 2. check what zone you are in  
  44. '****** 3. put a number in that zone ether 1 or 2
  45. '****** 4. place cross or a nought in that zone
  46. '****** 5. make a bell sound 
  47. '****** 6. reset the zone so that it cant be detected anymore
  48. '------------------------------------------------------------
  49. If MK=1 and MZ=1 : LABEL(MZ)=1
  50.    Paste Bob X(MZ)*40,Y(MZ)*40,1
  51.     Bell 5 : G=G+1 : Reset Zone MZ
  52.      End If 
  53. If MK=1 and MZ=2 : LABEL(MZ)=1
  54.    Paste Bob X(MZ)*43,Y(MZ)*40,1
  55.     Bell 5 : G=G+1 : Reset Zone MZ
  56.      End If 
  57. If MK=1 and MZ=3 : LABEL(MZ)=1
  58.    Paste Bob X(MZ)*45,Y(MZ)*40,1
  59.     Bell 5 : G=G+1 : Reset Zone MZ
  60.      End If 
  61. If MK=1 and MZ=4 : LABEL(MZ)=1
  62.    Paste Bob X(MZ)*40,Y(MZ)*45,1
  63.     Bell 5 : G=G+1 : Reset Zone MZ
  64.       End If 
  65. If MK=1 and MZ=5 : LABEL(MZ)=1
  66.    Paste Bob X(MZ)*43,Y(MZ)*45,1
  67.     Bell 5 : G=G+1 : Reset Zone MZ
  68.      End If 
  69. If MK=1 and MZ=6 : LABEL(MZ)=1
  70.   Paste Bob X(MZ)*45,Y(MZ)*45,1
  71.    Bell 5 : G=G+1 : Reset Zone MZ
  72.      End If 
  73. If MK=1 and MZ=7 : LABEL(MZ)=1
  74.    Paste Bob X(MZ)*40,Y(MZ)*47,1
  75.     Bell 5 : G=G+1 : Reset Zone MZ
  76.      End If 
  77. If MK=1 and MZ=8 : LABEL(MZ)=1
  78.    Paste Bob X(MZ)*43,Y(MZ)*47,1
  79.     Bell 5 : G=G+1 : Reset Zone MZ
  80.       End If 
  81. If MK=1 and MZ=9 : LABEL(MZ)=1
  82.     Paste Bob X(MZ)*45,Y(MZ)*47,1
  83.       Bell 5 : G=G+1 : Reset Zone MZ
  84.         End If 
  85. '------------------------------------------------------------------------  
  86. '***********************  Player two  ******************** 
  87. '------------------------------------------------------------------------  
  88. '*** these conditions are the same as for player one except that we **                   
  89. '*** are checking the right mouse button instead of the left mouse button ** 
  90. '*************************************************************************** 
  91. If MK=2 and MZ=1 : LABEL(MZ)=2
  92.     Paste Bob X(MZ)*40,Y(MZ)*42,2
  93.      Bell 70 : G=G+1 : Reset Zone MZ
  94.       End If 
  95. If MK=2 and MZ=2 : LABEL(MZ)=2
  96.     Paste Bob X(MZ)*43,Y(MZ)*42,2
  97.      Bell 70 : G=G+1 : Reset Zone MZ
  98.        End If 
  99. If MK=2 and MZ=3 : LABEL(MZ)=2
  100.     Paste Bob X(MZ)*45,Y(MZ)*42,2
  101.       Bell 70 : G=G+1 : Reset Zone MZ
  102.        End If 
  103. If MK=2 and MZ=4 : LABEL(MZ)=2
  104.     Paste Bob X(MZ)*40,Y(MZ)*45,2
  105.       Bell 70 : G=G+1 : Reset Zone MZ
  106.         End If 
  107. If MK=2 and MZ=5 : LABEL(MZ)=2
  108.     Paste Bob X(MZ)*43,Y(MZ)*45,2
  109.       Bell 70 : G=G+1 : Reset Zone MZ
  110.         End If 
  111. If MK=2 and MZ=6 : LABEL(MZ)=2
  112.     Paste Bob X(MZ)*45,Y(MZ)*45,2
  113.        Bell 70 : G=G+1 : Reset Zone MZ
  114.         End If 
  115. If MK=2 and MZ=7 : LABEL(MZ)=2
  116.      Paste Bob X(MZ)*40,Y(MZ)*47,2
  117.        Bell 7 : G=G+1 : Reset Zone MZ
  118.          End If 
  119. If MK=2 and MZ=8 : LABEL(MZ)=2
  120.     Paste Bob X(MZ)*43,Y(MZ)*47,2
  121.       Bell 70 : G=G+1 : Reset Zone MZ
  122.         End If 
  123. If MK=2 and MZ=9 : LABEL(MZ)=2
  124.      Paste Bob X(MZ)*45,Y(MZ)*47,2
  125.        Bell 70 : G=G+1 : Reset Zone MZ
  126.          End If 
  127. '
  128. '                   ----------------------   
  129. '                   ****** player X ****** 
  130. '                   ---------------------- 
  131. '********************************************************************* 
  132. 'this may seem a little complicated but if you break it down 
  133. 'into small pices its really quite simple.look at the conditions 
  134. 'above and you will notice that the first thing that we do is check
  135. 'what mouse key has been pressed.if mk=1 then the left mouse button
  136. 'has been pressed and we then know that player one has placed an 'X' 
  137. 'into one of the zones then we make the variable - LABEL - of that 
  138. 'zone ether 1 for an 'X' or 2 for a 'Y'.then all we have to do is check
  139. 'wether there are three 1's or three 2's in a row and if there is then 
  140. 'go to the _WINNER_X or _WINNER _O procedure.
  141. '----------------------------------------------------------------------
  142. '**********************************************************************
  143. If LABEL(1)=1 and LABEL(2)=1 and LABEL(3)=1 : Gosub _WINNER_X : End If 
  144. '              ------------------------- 
  145. If LABEL(4)=1 and LABEL(5)=1 and LABEL(6)=1 : Gosub _WINNER_X : End If 
  146. '              ------------------------- 
  147. If LABEL(7)=1 and LABEL(8)=1 and LABEL(9)=1 : Gosub _WINNER_X : End If 
  148. '              ------------------------- 
  149. If LABEL(1)=1 and LABEL(4)=1 and LABEL(7)=1 : Gosub _WINNER_X : End If 
  150. '              -------------------------   
  151. If LABEL(2)=1 and LABEL(5)=1 and LABEL(8)=1 : Gosub _WINNER_X : End If 
  152. '              ------------------------- 
  153. If LABEL(3)=1 and LABEL(6)=1 and LABEL(9)=1 : Gosub _WINNER_X : End If 
  154. '              ------------------------- 
  155. If LABEL(1)=1 and LABEL(5)=1 and LABEL(9)=1 : Gosub _WINNER_X : End If 
  156. '              ------------------------- 
  157. If LABEL(3)=1 and LABEL(5)=1 and LABEL(7)=1 : Gosub _WINNER_X : End If 
  158. '
  159. '                  ---------------------   
  160. '                  ***** player O ****** 
  161. '                  --------------------- 
  162. If LABEL(1)=2 and LABEL(2)=2 and LABEL(3)=2 : Gosub _WINNER_O : End If 
  163. '                  ----------------------
  164. If LABEL(4)=2 and LABEL(5)=2 and LABEL(6)=2 : Gosub _WINNER_O : End If 
  165. '                  ----------------------
  166. If LABEL(7)=2 and LABEL(8)=2 and LABEL(9)=2 : Gosub _WINNER_O : End If 
  167. '                  ----------------------
  168. If LABEL(1)=2 and LABEL(4)=2 and LABEL(7)=2 : Gosub _WINNER_O : End If 
  169. '                  ----------------------
  170. If LABEL(2)=2 and LABEL(5)=2 and LABEL(8)=2 : Gosub _WINNER_O : End If 
  171. '                  ----------------------
  172. If LABEL(3)=2 and LABEL(6)=2 and LABEL(9)=2 : Gosub _WINNER_O : End If 
  173. '                  ----------------------
  174. If LABEL(1)=2 and LABEL(5)=2 and LABEL(9)=2 : Gosub _WINNER_O : End If 
  175. '                  ----------------------
  176. If LABEL(3)=2 and LABEL(5)=2 and LABEL(7)=2 : Gosub _WINNER_O : End If 
  177. '
  178. If G=9 : Gosub _DRAW : End If : Rem  ** check if all moves have been played
  179.  If MK=1 : For DELAY=1 To 1000 : Next : CO=CO+1 : If CO>12 : Gosub _RESTART : End If : End If 
  180.  If MK=2 : For DELAY=1 To 1000 : Next : COU=COU+1 : If COU>12 : Gosub _RESTART : End If : End If 
  181. Wait Vbl 
  182. Until MK=3
  183. '
  184. '--------------------------------------------------------------------------------------------------  
  185. '***************    this is the data used to set up the zones    ****************
  186. '                   ------------------------------------------ 
  187. Data 2,1,3,1,4,1
  188. Data 2,2,3,2,4,2
  189. Data 2,3,3,3,4,3
  190. '*************** 
  191. '
  192. '************** i havent rem any of these procedures as *************************
  193. '************** i think they are pritty straight forward *************************** 
  194. '
  195. _WINNER_X:
  196. For A=1 To 3
  197. For B=1 To 70 : Bell B : Wait Vbl : Next B : Wait Vbl : Next A
  198. Pen 3 : Locate 0,29 : Centre ">> you win player - X <<"
  199.    Wait 150 : Cls 0,42,225 To 268,245
  200.      Locate 0,29 : Centre ">> press a key please <<"
  201.         Wait Key 
  202.             Edit 
  203.                Return 
  204. '--------------------------------------------------------- 
  205. '--------------------------------------------------------- 
  206. _WINNER_O:
  207. For A=1 To 3
  208. For B=70 To 1 Step -1 : Bell B : Wait Vbl : Next B : Wait Vbl : Next A
  209. Pen 3 : Locate 0,29 : Centre ">> you win player - O <<"
  210.    Wait 150 : Cls 0,42,225 To 268,245
  211.      Locate 0,29 : Centre ">> press a key please <<"
  212.           Wait Key 
  213.                 Edit 
  214.                    Return 
  215. '----------------------------------------------------------
  216. '----------------------------------------------------------
  217. _DRAW:
  218.  For B=1 To 70 : Bell B : Wait Vbl : Next 
  219.  Pen 3 : Locate 0,29 : Centre ">> its a draw <<" : Wait 150 : Edit 
  220. Return 
  221. '----------------------------------------------------------------- 
  222. '----------------------------------------------------------------- 
  223. _RESTART:
  224.  For B=70 To 1 Step -1 : Bell B : Wait Vbl : Next 
  225. Boom : Pen 3 : Locate 0,29 : Centre ">> error:game over <<" : Wait 150 : Edit 
  226. Return 
  227. '--------------------------------------------------------------------------- 
  228. '*************************************************************************** 
  229. 'well thats all for now i hope this programme has been of some help
  230. 'to you.feel free to mess around and change this programme as much as  
  231. 'you like.break the programme into small pieces and try to find how each 
  232. 'piece works.remember a big programme is only a lot of small programmes put
  233. 'togeather.here are some changes that you could do to improve this programme.  
  234. '******************************* 
  235. '1. include better sound effects.
  236. '2. change the playing screen. 
  237. '3. improve the images.
  238. '*******************************   
  239. 'p.s - if this programme helps you in any way please let me know .after all
  240. 'we all need a little bit of encouragement dont we.best of luck with your
  241. 'programing in the future. 
  242. '
  243. '
  244. '
  245. '                                                MARTIN MC DONALD  
  246. '                                                  17 GLASSLOUGH STREET
  247. '                                                   MONAGHAN,CO MONAGHAN 
  248. '                                                    REP OF IRELAND
  249. '                                                     IRELAND
  250. '-----------------------------------------------------------------------------------