Post by yoric on Mar 7, 2006 12:07:27 GMT -5
Here is my code for Stage 3. of the 'Yoric Project'.
"Double Cross" is the 2 player version of "Cross".
Briefly, when you remove a piece from your own board you also remove any piece occupying the same position on your opponents board, and vice-versa.
The highest scorer is the winner, of course.
More, on Stage 4, next. Cya all, Yoric
dim Board (9, 9)
dim x, y, xl, yl, xd, yd, sc, scp, cl1, cl2
dim char$, start$, Play$, Player$, Result$
dim xdr, ydr, scr, spr, spg, scg, xdg, ydg
dim Player, Change, Play, Pass, Result, Check, Cursor
dim up, down, left, right
xdr = 2: ydr = 6: spr = 6
xdg =29: ydg = 6: spg = 32
color (255, 255, 255)
locate 12, 0: print "* Double Cross *"
color (0, 0, 255)
locate 4, 2: print "Left-Click a ball for directions"
locate 0, 3: print "Hold Cursor Key and Left-Click Selection"
locate 17, 5: print "score "
locate 10, 23: print "Press return to Esc"
color (255, 0, 0)
for y = 3 to 5
for x = 1 to 7
locate x + xdr, y + ydr: print "O"
next
next
for y = 1 to 7
for x = 3 to 5
locate x + xdr, y + ydr: print "O"
next
next
locate xdr + 4, ydr + 4: print "+"
color (0, 255, 0)
for y = 3 to 5
for x = 1 to 7
locate x + xdg, y + ydg: print "O"
next
next
for y = 1 to 7
for x = 3 to 5
locate x + xdg, y + ydg: print "O"
next
next
locate xdg + 4, ydg + 4: print "+"
color (0, 0, 255)
locate 11,22: input "Play first R or G"; Player$
locate 12, 18: print "End key to pass"
locate 13, 19: print "Three Passes"
Locate 13, 20: print "Will End game"
gosub Player
Play:
locate 10,22: ClearLine ()
if Player$ = "r" then color (255, 0, 0)
else color (0, 255, 0) endif
locate 15,22: print Player$ + " to play"
while true
if not Mouse_Button (MOUSE_LBUTTON) then
locate x, y
endif
x = Mouse_X () * TextCols ()
y = Mouse_Y () * TextRows ()
xl = x - xd: yl = y - yd
if xl < 0 or xl > 7 or yl < 1 or yl > 7 then xl = 0 endif
if yl < 0 or yl > 7 or xl < 1 or xl > 7 then yl = 0 endif
char$ = CharAt$ (x, y)
locate 13, 15: color (0, 0, 255): print "X = " + xl; " " "Y = " + yl: Sleep (100)
if ScanKeyDown (VK_END) then pass = pass + 1: goto change endif
if ScanKeyDown (VK_RETURN) then goto finish endif
if Mouse_Button (MOUSE_LBUTTON) then gosub Check: endif
wend
Finish:
color (0, 0, 255): locate 10, 23: ClearLine ()
locate 8, 23: input "play again? (y, or esc)"; Play$
if Play$ = "y" then run
else end
endif
Check:
if Player$ = "r" and x > 20 then return endif
if Player$ = "g" and x < 20 then return endif
if CharAt$(x, y) = "O" and CharAt$(x, y - 1) = "O" and CharAt$(x, y - 2) = "+" then
locate xd, 17: color (0, 0, 255): print "Up OK" : up = true:
else locate xd, 17: color (cl1, cl2, 0): print "Up No": up = false
endif
if CharAt$(x, y) = "O" and CharAt$(x, y + 1) = "O" and CharAt$(x, y + 2) = "+" then
locate xd, 18: color (0, 0, 255): print "Down OK": down = true:
else locate xd, 18: color (cl1, cl2, 0): print "Down No": down = false
endif
if CharAt$(x, y) = "O" and CharAt$(x - 1, y) = "O" and CharAt$(x - 2, y) = "+" then
locate xd, 19: color (0, 0, 255): print "Left OK": left = true:
else locate xd, 19: color (cl1, cl2, 0): print "Left No": left = false
endif
if CharAt$(x, y) = "O" and CharAt$(x + 1, y) = "O" and CharAt$(x + 2, y) = "+" then
locate xd, 20: color (0, 0, 255): print "Right OK": right = true:
else locate xd, 20: color (cl1, cl2, 0): print "Right No": right = false
endif
Cursor:
color (cl1, cl2, 0)
if ScanKeyDown (VK_UP) and up then gosub up endif
if ScanKeyDown (VK_DOWN) and down then gosub down endif
if ScanKeyDown (VK_LEFT) and left then gosub left endif
if ScanKeyDown (VK_RIGHT) and right then gosub right endif
locate scp, 5: print sc
if Player$ = "r" then scr = sc endif
if Player$ = "g" then scg = sc endif
Sleep (100)
return
up:
board (xl, yl) = 1: board (xl, yl - 1) = 1: board (xl, yl - 2) = 2
locate x, y: print "+": locate x, y - 1: print "+": locate x, y - 2: print "O"
if Player$ = "r" then locate xl + xdg, y - 1: color (0, 255, 0): print "+" endif
if Player$ = "g" then locate xl + xdr, y - 1: color (255, 0, 0): print "+" endif
sc = sc + 1: y = y - 2: pass = 0: ClearKeys (): Sleep (500): gosub check
if not up and not down and not left and not right then gosub change endif
return
down:
board (xl, yl) = 1: board (xl, yl + 1) = 1: board (xl, yl + 2) = 2
locate x, y: print "+": locate x, y + 1: print "+": locate x, y + 2: print "O"
if Player$ = "r" then locate xl + xdg, y + 1: color (0, 255, 0): print "+" endif
if Player$ = "g" then locate xl + xdr, y + 1: color (255, 0, 0): print "+" endif
sc = sc + 1: y = y + 2: pass = 0: ClearKeys (): Sleep (500): gosub check
if not up and not down and not left and not right then gosub change endif
return
left:
board (xl, yl) = 1: board (xl - 1, yl) = 1: board (xl - 2, yl) = 2
locate x, y: print "+": locate x - 1, y: print "+": locate x - 2, y: print "O"
if Player$ = "r" then locate xl + xdg - 1, y: color (0, 255, 0): print "+" endif
if Player$ = "g" then locate xl + xdr - 1, y: color (255, 0, 0): print "+" endif
sc = sc + 1: x = x - 2: pass = 0: ClearKeys (): Sleep (500): gosub check
if not up and not down and not left and not right then gosub change endif
return
right:
board (xl, yl) = 1: board (xl + 1, yl) = 1: board (xl + 2, yl) = 2
locate x, y: print "+": locate x + 1, y: print "+": locate x + 2, y: print "O"
if Player$ = "r" then locate xl + xdg + 1, y: color (0, 255, 0): print "+" endif
if Player$ = "g" then locate xl + xdr + 1, y: color (255, 0, 0): print "+" endif
sc = sc + 1: x = x + 2: pass = 0: ClearKeys (): Sleep (500): gosub check
if not up and not down and not left and not right then gosub change endif
return
Player:
if Player$ = "r" then xd = xdr: yd = ydr: sc = scr: scp = spr
cl1 = 255: cl2 = 0
endif
if Player$ = "g" then xd = xdg: yd = ydg: sc = scg: scp = spg
cl1 = 0: cl2 = 255
endif
return
Change:
if Player$ = "r" then Player$ = "g"
else Player$ = "r"
endif
if pass > 2 then goto Result endif
gosub Player
goto Play
Result:
if scr > scg then color (255, 0, 0): Result$ = "Red Victory" endif
if scr < scg then color (0, 255, 0): Result$ = "Greens Won" endif
if scr = scg then color (0, 0, 255): Result$ = "Game Drawn" endif
locate 14, 22: ClearLine ()
locate 14, 22: print Result$
goto finish
"Double Cross" is the 2 player version of "Cross".
Briefly, when you remove a piece from your own board you also remove any piece occupying the same position on your opponents board, and vice-versa.
The highest scorer is the winner, of course.
More, on Stage 4, next. Cya all, Yoric
dim Board (9, 9)
dim x, y, xl, yl, xd, yd, sc, scp, cl1, cl2
dim char$, start$, Play$, Player$, Result$
dim xdr, ydr, scr, spr, spg, scg, xdg, ydg
dim Player, Change, Play, Pass, Result, Check, Cursor
dim up, down, left, right
xdr = 2: ydr = 6: spr = 6
xdg =29: ydg = 6: spg = 32
color (255, 255, 255)
locate 12, 0: print "* Double Cross *"
color (0, 0, 255)
locate 4, 2: print "Left-Click a ball for directions"
locate 0, 3: print "Hold Cursor Key and Left-Click Selection"
locate 17, 5: print "score "
locate 10, 23: print "Press return to Esc"
color (255, 0, 0)
for y = 3 to 5
for x = 1 to 7
locate x + xdr, y + ydr: print "O"
next
next
for y = 1 to 7
for x = 3 to 5
locate x + xdr, y + ydr: print "O"
next
next
locate xdr + 4, ydr + 4: print "+"
color (0, 255, 0)
for y = 3 to 5
for x = 1 to 7
locate x + xdg, y + ydg: print "O"
next
next
for y = 1 to 7
for x = 3 to 5
locate x + xdg, y + ydg: print "O"
next
next
locate xdg + 4, ydg + 4: print "+"
color (0, 0, 255)
locate 11,22: input "Play first R or G"; Player$
locate 12, 18: print "End key to pass"
locate 13, 19: print "Three Passes"
Locate 13, 20: print "Will End game"
gosub Player
Play:
locate 10,22: ClearLine ()
if Player$ = "r" then color (255, 0, 0)
else color (0, 255, 0) endif
locate 15,22: print Player$ + " to play"
while true
if not Mouse_Button (MOUSE_LBUTTON) then
locate x, y
endif
x = Mouse_X () * TextCols ()
y = Mouse_Y () * TextRows ()
xl = x - xd: yl = y - yd
if xl < 0 or xl > 7 or yl < 1 or yl > 7 then xl = 0 endif
if yl < 0 or yl > 7 or xl < 1 or xl > 7 then yl = 0 endif
char$ = CharAt$ (x, y)
locate 13, 15: color (0, 0, 255): print "X = " + xl; " " "Y = " + yl: Sleep (100)
if ScanKeyDown (VK_END) then pass = pass + 1: goto change endif
if ScanKeyDown (VK_RETURN) then goto finish endif
if Mouse_Button (MOUSE_LBUTTON) then gosub Check: endif
wend
Finish:
color (0, 0, 255): locate 10, 23: ClearLine ()
locate 8, 23: input "play again? (y, or esc)"; Play$
if Play$ = "y" then run
else end
endif
Check:
if Player$ = "r" and x > 20 then return endif
if Player$ = "g" and x < 20 then return endif
if CharAt$(x, y) = "O" and CharAt$(x, y - 1) = "O" and CharAt$(x, y - 2) = "+" then
locate xd, 17: color (0, 0, 255): print "Up OK" : up = true:
else locate xd, 17: color (cl1, cl2, 0): print "Up No": up = false
endif
if CharAt$(x, y) = "O" and CharAt$(x, y + 1) = "O" and CharAt$(x, y + 2) = "+" then
locate xd, 18: color (0, 0, 255): print "Down OK": down = true:
else locate xd, 18: color (cl1, cl2, 0): print "Down No": down = false
endif
if CharAt$(x, y) = "O" and CharAt$(x - 1, y) = "O" and CharAt$(x - 2, y) = "+" then
locate xd, 19: color (0, 0, 255): print "Left OK": left = true:
else locate xd, 19: color (cl1, cl2, 0): print "Left No": left = false
endif
if CharAt$(x, y) = "O" and CharAt$(x + 1, y) = "O" and CharAt$(x + 2, y) = "+" then
locate xd, 20: color (0, 0, 255): print "Right OK": right = true:
else locate xd, 20: color (cl1, cl2, 0): print "Right No": right = false
endif
Cursor:
color (cl1, cl2, 0)
if ScanKeyDown (VK_UP) and up then gosub up endif
if ScanKeyDown (VK_DOWN) and down then gosub down endif
if ScanKeyDown (VK_LEFT) and left then gosub left endif
if ScanKeyDown (VK_RIGHT) and right then gosub right endif
locate scp, 5: print sc
if Player$ = "r" then scr = sc endif
if Player$ = "g" then scg = sc endif
Sleep (100)
return
up:
board (xl, yl) = 1: board (xl, yl - 1) = 1: board (xl, yl - 2) = 2
locate x, y: print "+": locate x, y - 1: print "+": locate x, y - 2: print "O"
if Player$ = "r" then locate xl + xdg, y - 1: color (0, 255, 0): print "+" endif
if Player$ = "g" then locate xl + xdr, y - 1: color (255, 0, 0): print "+" endif
sc = sc + 1: y = y - 2: pass = 0: ClearKeys (): Sleep (500): gosub check
if not up and not down and not left and not right then gosub change endif
return
down:
board (xl, yl) = 1: board (xl, yl + 1) = 1: board (xl, yl + 2) = 2
locate x, y: print "+": locate x, y + 1: print "+": locate x, y + 2: print "O"
if Player$ = "r" then locate xl + xdg, y + 1: color (0, 255, 0): print "+" endif
if Player$ = "g" then locate xl + xdr, y + 1: color (255, 0, 0): print "+" endif
sc = sc + 1: y = y + 2: pass = 0: ClearKeys (): Sleep (500): gosub check
if not up and not down and not left and not right then gosub change endif
return
left:
board (xl, yl) = 1: board (xl - 1, yl) = 1: board (xl - 2, yl) = 2
locate x, y: print "+": locate x - 1, y: print "+": locate x - 2, y: print "O"
if Player$ = "r" then locate xl + xdg - 1, y: color (0, 255, 0): print "+" endif
if Player$ = "g" then locate xl + xdr - 1, y: color (255, 0, 0): print "+" endif
sc = sc + 1: x = x - 2: pass = 0: ClearKeys (): Sleep (500): gosub check
if not up and not down and not left and not right then gosub change endif
return
right:
board (xl, yl) = 1: board (xl + 1, yl) = 1: board (xl + 2, yl) = 2
locate x, y: print "+": locate x + 1, y: print "+": locate x + 2, y: print "O"
if Player$ = "r" then locate xl + xdg + 1, y: color (0, 255, 0): print "+" endif
if Player$ = "g" then locate xl + xdr + 1, y: color (255, 0, 0): print "+" endif
sc = sc + 1: x = x + 2: pass = 0: ClearKeys (): Sleep (500): gosub check
if not up and not down and not left and not right then gosub change endif
return
Player:
if Player$ = "r" then xd = xdr: yd = ydr: sc = scr: scp = spr
cl1 = 255: cl2 = 0
endif
if Player$ = "g" then xd = xdg: yd = ydg: sc = scg: scp = spg
cl1 = 0: cl2 = 255
endif
return
Change:
if Player$ = "r" then Player$ = "g"
else Player$ = "r"
endif
if pass > 2 then goto Result endif
gosub Player
goto Play
Result:
if scr > scg then color (255, 0, 0): Result$ = "Red Victory" endif
if scr < scg then color (0, 255, 0): Result$ = "Greens Won" endif
if scr = scg then color (0, 0, 255): Result$ = "Game Drawn" endif
locate 14, 22: ClearLine ()
locate 14, 22: print Result$
goto finish