home *** CD-ROM | disk | FTP | other *** search
/ Corel Draw 6 / corel-draw-6-cd1.iso / draw / connect.csc < prev    next >
Text File  |  1995-08-18  |  5KB  |  164 lines

  1. REM A simple 2 Player Game. Get five in a row and you win
  2. REM Connect.csc 31 July, 1995
  3.  
  4. REM This game is very similar to Tic-Tac-Toe. The first player to get
  5. REM to get five of their markers in a row wins.
  6.  
  7. DECLARE SUB CheckForWin(BYVAL Player%, BYVAL XPos%, BYVAL YPos%)
  8.  
  9. GLOBAL MAP(0 to 20, 0 to 20) as INTEGER      'Stores the location of all pieces.
  10.                             '(X, Y) ( 1 = White), (2 = Black)
  11. GLOBAL Name$(2)        'Stores the Player's Names
  12. ON ERROR EXIT
  13.  
  14. RESTART:
  15. GridStr$ = INPUTBOX("Please enter a size ( >= 5, <= 20)")        'All rows + cols must be sinle digit
  16. IF GridStr = "" THEN STOP        'If Cancel pressed
  17. Grid& = CSTR(GridStr)        
  18. IF Grid < 5 THEN             'Check Value
  19.     MESSAGE "Too Small"
  20.     GOTO RESTART
  21. END IF
  22. IF Grid > 20 THEN 
  23.     MESSAGE "Too Large"
  24.     GOTO RESTART
  25. END IF
  26.  
  27. Name(1) = INPUTBOX("Please enter Player #1's name: ")
  28. Name(2) = INPUTBOX("Please enter Player #2's name: ")
  29.  
  30. WITHOBJECT DRAW
  31. .FileNew
  32. FOR i% = 1 to Grid&                'Create the Grid and Numbers
  33.     .CreateArtisticText STR(i)
  34.     .SetReferencePoint 8
  35.     .SetPosition FROMINCHES(-3.75), FROMINCHES(4 - i/3)
  36.     .BeginDrawCurve FROMINCHES(-3.25), FROMINCHES(4 - i/3)    
  37.     .DrawCurveLineTo FROMINCHES(-3.25 + (Grid+1)/3), FROMINCHES(4 - i/3)    
  38.     .EndDrawCurve
  39.     .ApplyOutline FROMINCHES(0.05), 1, 1, 0, 0, 0, 0, 0, 0, 0
  40.  
  41.     .CreateArtisticText STR(i)
  42.     .SetReferencePoint 6
  43.     .SetPosition FROMINCHES(-3.25 + i/3), FROMINCHES(4.25)
  44.     .BeginDrawCurve FROMINCHES(-3.25 + i/3), FROMINCHES(4)    
  45.     .DrawCurveLineTo FROMINCHES(-3.25 + i/3), FROMINCHES(4 - (grid+1)/3)    
  46.     .EndDrawCurve
  47.     .ApplyOutline FROMINCHES(0.05), 1, 1, 0, 0, 0, 0, 0, 0, 0
  48. Next i
  49.  
  50. DIM testvar AS BOOLEAN
  51. testvar = TRUE
  52.     .UnSelectAll
  53.  
  54. BEGIN DIALOG CoordDialog 430, 75, 212, 73, "Coordinates"        'Dialog for returning the coordinates of the next move
  55.     TEXT  12, 22, 50, 8, "&X Coordinate"
  56.     SPINCONTROL  80, 23, 50, 12, PlayX%
  57.     TEXT  12, 43, 50, 8, "&Y Coordinate"
  58.     SPINCONTROL  80, 43, 50, 11, PlayY%
  59.     OKBUTTON  149, 22, 40, 14
  60.     CANCELBUTTON  149, 43, 40, 14
  61.     TEXT  16, 4, 186, 15, Prompt$
  62. END DIALOG
  63.  
  64.  
  65. DIM FlipFlop AS BOOLEAN                'Boolean Variable to remember who's turn it is
  66. FlipFlop = 0
  67. DO WHILE testvar
  68. FlipFlop = NOT(FlipFlop)                'Toggle which player
  69. PlayerNum% = FlipFlop + 2
  70.     RETRY:
  71.     Prompt$ = Name(PlayerNum%) + ", please enter your play in the appropriate boxes"
  72.     ret% = Dialog(CoordDialog)        'Call the Dialog
  73.  
  74.     IF CANCEL THEN STOP            'check for cancel
  75.  
  76.     IF MAP(PlayX, PlayY) <> 0 THEN     'check to see if its already taken    
  77.         MESSAGE "That's already taken"
  78.         GOTO RETRY
  79.     END IF
  80.     IF PlayX > Grid OR PlayY > Grid THEN    'check to see if its off the grid
  81.         MESSAGE "That's not in the Grid"
  82.         GOTO RETRY
  83.     END IF
  84.  
  85. REM Draw the marker    
  86.     .CreateEllipse FROMINCHES(4.15 - PlayY/3),FROMINCHES(-3.4 + PlayX/3),FROMINCHES(3.9 - PlayY / 3),FROMINCHES(-3.15 + PlayX / 3), 0, 0, 0
  87.     IF FlipFlop = TRUE THEN .ApplyUniformFillColor 5, 255, 255, 255, 0            'Player 1
  88.     IF FlipFlop = FALSE THEN .ApplyUniformFillColor 5, 0, 0, 0, 0            'Player 1
  89.     .UnSelectAll
  90.  
  91. REM Update the MAP Array and check to see if there's a winner
  92.     MAP(PlayX, PlayY) = PlayerNum
  93.     CheckForWin PlayerNum, PlayX, PlayY
  94. LOOP
  95. END WITHOBJECT
  96.  
  97. REM This sub checks to see if the current player has won.
  98. SUB CheckForWin(Player%, XPos%, YPos%)
  99. DIM TESTER AS BOOLEAN
  100. TESTER = TRUE
  101.     DO WHILE Tester                'counts left of current position
  102.         NumLeft% = NumLeft% + 1
  103.         IF MAP(XPos - NumLeft%, YPos) <> Player% THEN TESTER = FALSE
  104.     LOOP
  105.  
  106. TESTER = TRUE
  107.     DO WHILE Tester                'counts Right of current position
  108.         NumRight% = NumRight% + 1
  109.         IF MAP(XPos + NumRight%, YPos) <> Player% THEN TESTER = FALSE
  110.     LOOP
  111. NumRight = NumRight - 1                'decrement right so you don't count current position twice
  112.  
  113. Horiz% = NumLeft + NumRight            'Add up number of markers in a horizontal 
  114.  
  115. TESTER = TRUE
  116.     DO WHILE Tester
  117.         NumUp% = NumUp% + 1
  118.         IF MAP(XPos, YPos - NumUp) <> Player% THEN TESTER = FALSE
  119.     LOOP
  120.  
  121. TESTER = TRUE
  122.     DO WHILE Tester
  123.         NumDOwn% = NumDOwn% + 1
  124.         IF MAP(XPos, YPos + NumDOwn%) <> Player% THEN TESTER = FALSE
  125.     LOOP
  126. NumDOwn = NumDOwn - 1
  127.  
  128. Vert% = NumUp + NumDOwn
  129.  
  130. TESTER = TRUE
  131.     DO WHILE Tester
  132.         NumUpLeft% = NumUpLeft% + 1
  133.         IF MAP(XPos - NumUpLeft%, YPos - NumUpLeft%) <> Player% THEN TESTER = FALSE
  134.     LOOP
  135.  
  136. TESTER = TRUE
  137.     DO WHILE Tester
  138.         NumDOwnRight% = NumDOwnRight% + 1
  139.         IF MAP(XPos + NumDOwnRight%, YPos + NumDOwnRight%) <> Player% THEN TESTER = FALSE
  140.     LOOP
  141. NumDOwnRight = NumDOwnRight - 1
  142.  
  143. BackSlash% = NumUpLeft + NumDOwnRight
  144.  
  145. TESTER = TRUE
  146.     DO WHILE Tester
  147.         NumUpRight% = NumUpRight% + 1
  148.         IF MAP(XPos + NumUpRight, YPos - NumUpRight) <> Player% THEN TESTER = FALSE
  149.     LOOP
  150.  
  151. TESTER = TRUE
  152.     DO WHILE Tester
  153.         NumDOwnLeft% = NumDOwnLeft% + 1
  154.         IF MAP(XPos - NumDOwnLeft%, YPos + NumDOwnLeft%) <> Player% THEN TESTER = FALSE
  155.     LOOP
  156. NumDOwnLeft = NumDOwnLeft - 1
  157. ForSlash% = NumUpRight + NumDOwnLeft
  158. IF Horiz > 4 OR Vert > 4 OR BackSlash > 4 OR ForSlash >= 5 THEN    'IF there's 5 in a row in any direction
  159.     MESSAGE Name(Player) + " WINS!!"
  160.     STOP
  161. END IF
  162. END SUB
  163.  
  164.