home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Corel Draw 6
/
corel-draw-6-cd1.iso
/
draw
/
connect.csc
< prev
next >
Wrap
Text File
|
1995-08-18
|
5KB
|
164 lines
REM A simple 2 Player Game. Get five in a row and you win
REM Connect.csc 31 July, 1995
REM This game is very similar to Tic-Tac-Toe. The first player to get
REM to get five of their markers in a row wins.
DECLARE SUB CheckForWin(BYVAL Player%, BYVAL XPos%, BYVAL YPos%)
GLOBAL MAP(0 to 20, 0 to 20) as INTEGER 'Stores the location of all pieces.
'(X, Y) ( 1 = White), (2 = Black)
GLOBAL Name$(2) 'Stores the Player's Names
ON ERROR EXIT
RESTART:
GridStr$ = INPUTBOX("Please enter a size ( >= 5, <= 20)") 'All rows + cols must be sinle digit
IF GridStr = "" THEN STOP 'If Cancel pressed
Grid& = CSTR(GridStr)
IF Grid < 5 THEN 'Check Value
MESSAGE "Too Small"
GOTO RESTART
END IF
IF Grid > 20 THEN
MESSAGE "Too Large"
GOTO RESTART
END IF
Name(1) = INPUTBOX("Please enter Player #1's name: ")
Name(2) = INPUTBOX("Please enter Player #2's name: ")
WITHOBJECT DRAW
.FileNew
FOR i% = 1 to Grid& 'Create the Grid and Numbers
.CreateArtisticText STR(i)
.SetReferencePoint 8
.SetPosition FROMINCHES(-3.75), FROMINCHES(4 - i/3)
.BeginDrawCurve FROMINCHES(-3.25), FROMINCHES(4 - i/3)
.DrawCurveLineTo FROMINCHES(-3.25 + (Grid+1)/3), FROMINCHES(4 - i/3)
.EndDrawCurve
.ApplyOutline FROMINCHES(0.05), 1, 1, 0, 0, 0, 0, 0, 0, 0
.CreateArtisticText STR(i)
.SetReferencePoint 6
.SetPosition FROMINCHES(-3.25 + i/3), FROMINCHES(4.25)
.BeginDrawCurve FROMINCHES(-3.25 + i/3), FROMINCHES(4)
.DrawCurveLineTo FROMINCHES(-3.25 + i/3), FROMINCHES(4 - (grid+1)/3)
.EndDrawCurve
.ApplyOutline FROMINCHES(0.05), 1, 1, 0, 0, 0, 0, 0, 0, 0
Next i
DIM testvar AS BOOLEAN
testvar = TRUE
.UnSelectAll
BEGIN DIALOG CoordDialog 430, 75, 212, 73, "Coordinates" 'Dialog for returning the coordinates of the next move
TEXT 12, 22, 50, 8, "&X Coordinate"
SPINCONTROL 80, 23, 50, 12, PlayX%
TEXT 12, 43, 50, 8, "&Y Coordinate"
SPINCONTROL 80, 43, 50, 11, PlayY%
OKBUTTON 149, 22, 40, 14
CANCELBUTTON 149, 43, 40, 14
TEXT 16, 4, 186, 15, Prompt$
END DIALOG
DIM FlipFlop AS BOOLEAN 'Boolean Variable to remember who's turn it is
FlipFlop = 0
DO WHILE testvar
FlipFlop = NOT(FlipFlop) 'Toggle which player
PlayerNum% = FlipFlop + 2
RETRY:
Prompt$ = Name(PlayerNum%) + ", please enter your play in the appropriate boxes"
ret% = Dialog(CoordDialog) 'Call the Dialog
IF CANCEL THEN STOP 'check for cancel
IF MAP(PlayX, PlayY) <> 0 THEN 'check to see if its already taken
MESSAGE "That's already taken"
GOTO RETRY
END IF
IF PlayX > Grid OR PlayY > Grid THEN 'check to see if its off the grid
MESSAGE "That's not in the Grid"
GOTO RETRY
END IF
REM Draw the marker
.CreateEllipse FROMINCHES(4.15 - PlayY/3),FROMINCHES(-3.4 + PlayX/3),FROMINCHES(3.9 - PlayY / 3),FROMINCHES(-3.15 + PlayX / 3), 0, 0, 0
IF FlipFlop = TRUE THEN .ApplyUniformFillColor 5, 255, 255, 255, 0 'Player 1
IF FlipFlop = FALSE THEN .ApplyUniformFillColor 5, 0, 0, 0, 0 'Player 1
.UnSelectAll
REM Update the MAP Array and check to see if there's a winner
MAP(PlayX, PlayY) = PlayerNum
CheckForWin PlayerNum, PlayX, PlayY
LOOP
END WITHOBJECT
REM This sub checks to see if the current player has won.
SUB CheckForWin(Player%, XPos%, YPos%)
DIM TESTER AS BOOLEAN
TESTER = TRUE
DO WHILE Tester 'counts left of current position
NumLeft% = NumLeft% + 1
IF MAP(XPos - NumLeft%, YPos) <> Player% THEN TESTER = FALSE
LOOP
TESTER = TRUE
DO WHILE Tester 'counts Right of current position
NumRight% = NumRight% + 1
IF MAP(XPos + NumRight%, YPos) <> Player% THEN TESTER = FALSE
LOOP
NumRight = NumRight - 1 'decrement right so you don't count current position twice
Horiz% = NumLeft + NumRight 'Add up number of markers in a horizontal
TESTER = TRUE
DO WHILE Tester
NumUp% = NumUp% + 1
IF MAP(XPos, YPos - NumUp) <> Player% THEN TESTER = FALSE
LOOP
TESTER = TRUE
DO WHILE Tester
NumDOwn% = NumDOwn% + 1
IF MAP(XPos, YPos + NumDOwn%) <> Player% THEN TESTER = FALSE
LOOP
NumDOwn = NumDOwn - 1
Vert% = NumUp + NumDOwn
TESTER = TRUE
DO WHILE Tester
NumUpLeft% = NumUpLeft% + 1
IF MAP(XPos - NumUpLeft%, YPos - NumUpLeft%) <> Player% THEN TESTER = FALSE
LOOP
TESTER = TRUE
DO WHILE Tester
NumDOwnRight% = NumDOwnRight% + 1
IF MAP(XPos + NumDOwnRight%, YPos + NumDOwnRight%) <> Player% THEN TESTER = FALSE
LOOP
NumDOwnRight = NumDOwnRight - 1
BackSlash% = NumUpLeft + NumDOwnRight
TESTER = TRUE
DO WHILE Tester
NumUpRight% = NumUpRight% + 1
IF MAP(XPos + NumUpRight, YPos - NumUpRight) <> Player% THEN TESTER = FALSE
LOOP
TESTER = TRUE
DO WHILE Tester
NumDOwnLeft% = NumDOwnLeft% + 1
IF MAP(XPos - NumDOwnLeft%, YPos + NumDOwnLeft%) <> Player% THEN TESTER = FALSE
LOOP
NumDOwnLeft = NumDOwnLeft - 1
ForSlash% = NumUpRight + NumDOwnLeft
IF Horiz > 4 OR Vert > 4 OR BackSlash > 4 OR ForSlash >= 5 THEN 'IF there's 5 in a row in any direction
MESSAGE Name(Player) + " WINS!!"
STOP
END IF
END SUB