You are not logged in or registered. Please login or register to use the full functionality of this board...
Login Register For FREE

QB64 Member Project - Overboard
QB64 Member Project - Foursight
QB64 Member Project - Input
QB64 Member Project - Point Blank
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Dakapo
QB64 Member Project - Color Triangles
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Dreamy Clock
QB64 Member Project - Quarto
QB64 Member Project - Othello
QB64 Member Project - Pivet version one
QB64 Member Project - Connect Four
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Rotating Background
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Qubic
QB64 Member Project - Pivot version two
QB64 Member Project - Basic Dithering
QB64 Member Project - Sabotage
QB64 Member Project - Touche
QB64 Member Project - Rubix's Magic
QB64 Member Project - Blokus
QB64 Member Project - Swirl
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Color Rotating Text
QB64 Member Project - Kings Court
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - ARB Checkers
QB64 Member Project - Exit
QB64 Member Project - Isolation
QB64 Member Project - 9 Board
QB64 Member Project - Score 4
QB64 Member Project - Line Thickness
QB64 Member Project - OpenGL Triangles
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Bowditch curve
QB64 Member Project - Spiro Roses
QB64 Member Project - Inside Moves
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Domain
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Amazon
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Algeria Weather
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Splatter
QB64 Member Project - Martin Fractals version one



Rubik's Magic Strategy Game in QB64
06-15-2014, 09:43 PM (This post was last modified: 07-21-2014 12:19 AM by Waltersmind.)
Post: #1
 (Print Post)
Rubik's Magic Strategy Game in QB64
Code Snippet: [Select]
_TITLE "Rubik's Magic Strategy Game by Donald L. Foster Jr."


SCREEN _NEWIMAGE(1000, 735, 256)

CLEAR

_LIMIT 100

_PALETTECOLOR 2, _RGB32(0, 80, 0) '     Green
_PALETTECOLOR 3, _RGB32(170, 170, 170) 'Dk Grey
_PALETTECOLOR 5, _RGB32(139, 0, 139) '  Magenta
_PALETTECOLOR 6, _RGB32(120, 120, 120) 'Lt Grey
_PALETTECOLOR 7, _RGB32(255, 140, 0) '  Yellow
_PALETTECOLOR 9, _RGB32(0, 0, 150) '    Blue
_PALETTECOLOR 12, _RGB32(255, 0, 0) '   Red
_PALETTECOLOR 14, _RGB32(255, 214, 0) ' Orange

s1(1) = 129: s1(2) = 288: t = 1

FOR z = 1 TO 4
    FOR y = 1 TO 4
        d(z, y) = 0: e(z, y) = 0: f(z, y) = 0
    NEXT
NEXT

a = 1: b = 2: c(1) = 15: c(2) = 0

LINE (0, 0)-(999, 734), 15, BF
LINE (19, 19)-(715, 715), 0, BF
LINE (40, 40)-(694, 694), 6, BF

v = 0
FOR z = 1 TO 4
    x = 0
    FOR y = 1 TO 4
        LINE (60 + x, 60 + v)-(198 + x, 198 + v), 8, BF
        a(z, y) = 129 + x: b(z, y) = 129 + v
        x = x + 159
    NEXT
    v = v + 159
NEXT

LINE (748, 19)-(966, 396), 0, BF
LINE (768, 40)-(946, 376), 6, BF

v = 0
FOR z = 1 TO 2
    LINE (788, 60 + v)-(926, 198 + v), 8, BF
    v = v + 159
NEXT

COLOR 0, 15
LOCATE 27, 95: PRINT "Rubik's Magic Strategy Game"
LOCATE 30, 105: PRINT "Player"

STARTGAME:
FOR z = 1 TO 4
    FOR y = 1 TO 4
        a1(z, y) = 0: a2(z, y) = 0: a3(z, y) = 0: a4(z, y) = 0
    NEXT
NEXT

x = 0: u = 0
FOR z = 1 TO 4
    FOR y = 1 TO 4
        IF d(z, y) = 0 THEN GOTO ENDLOOP
        IF z - 1 >= 1 THEN IF d(z - 1, y) = 0 THEN a1(z, y) = 1: x = 1
        IF y + 1 <= 4 THEN IF d(z, y + 1) = 0 THEN a2(z, y) = 1: x = 1
        IF z + 1 <= 4 THEN IF d(z + 1, y) = 0 THEN a3(z, y) = 1: x = 1
        IF y - 1 >= 1 THEN IF d(z, y - 1) = 0 THEN a4(z, y) = 1: x = 1
        IF f(z, y) = 1 THEN g(u) = z: h(u) = y: u = u + 1
        IF (f(z, y) = 1) * ((a1(z, y) = 1) + (a2(z, y) = 1) + (a3(z, y) = 1) + (a4(z, y) = 1)) THEN v = v + 1
        ENDLOOP:
    NEXT
NEXT

IF v = 1 THEN
    GOTO LABEL1
ELSEIF v > 1 THEN
    FOR z = 1 TO 3
        f(g(z), h(z)) = 0
    NEXT
    LOCATE 30, 111: PRINT a;
    FOR z = 1 TO 2
        x1 = 857: x2 = s1(z): c = z: d = 2
        ON a GOSUB CIRCLEPIECE, DIAMONDPIECE
    NEXT
    IF x = 0 THEN GOTO LABEL2 ELSE k = i: l = j: m = 1: n = 1
END IF

MOVECURSOR1:
LOCATE 31, 92: PRINT " Choose opponents piece to flip. "
LINE (a(k, l) - 78, b(k, l) - 78)-(a(k, l) + 78, b(k, l) + 78), 6, B
LINE (a(m, n) - 78, b(m, n) - 78)-(a(m, n) + 78, b(m, n) + 78), 15, B

GETINPUT1:
a$ = INKEY$: IF a$ = "" THEN GOTO GETINPUT1

IF (m = 1) * (a$ = CHR$(0) + CHR$(72)) THEN k = m: l = n: m = 4: GOTO MOVECURSOR1
IF a$ = CHR$(0) + CHR$(72) THEN k = m: l = n: m = m - 1: GOTO MOVECURSOR1

IF (n = 4) * (a$ = CHR$(0) + CHR$(77)) THEN k = m: l = n: n = 1: GOTO MOVECURSOR1
IF a$ = CHR$(0) + CHR$(77) THEN k = m: l = n: n = n + 1: GOTO MOVECURSOR1

IF (m = 4) * (a$ = CHR$(0) + CHR$(80)) THEN k = m: l = n: m = 1: GOTO MOVECURSOR1
IF a$ = CHR$(0) + CHR$(80) THEN k = m: l = n: m = m + 1: GOTO MOVECURSOR1

IF (n = 1) * (a$ = CHR$(0) + CHR$(75)) THEN k = m: l = n: n = 4: GOTO MOVECURSOR1
IF a$ = CHR$(0) + CHR$(75) THEN k = m: l = n: n = n - 1: GOTO MOVECURSOR1

IF ASC(a$) = 13 THEN GOTO CHECKLEGAL1
GOTO GETINPUT1

CHECKLEGAL1:
IF (d(m, n) = b) * ((a1(m, n) = 1) + (a2(m, n) = 1) + (a3(m, n) = 1) + (a4(m, n) = 1)) THEN o = m: p = n: q = m: R = n ELSE GOTO GETINPUT1

MOVECURSOR2:
IF (o = m) * (p = n) THEN vb = 15 ELSE vb = 6

LOCATE 31, 92: PRINT "Choose location to flip piece to."
LINE (a(o, p) - 78, b(o, p) - 78)-(a(o, p) + 78, b(o, p) + 78), vb, B
LINE (a(q, R) - 78, b(q, R) - 78)-(a(q, R) + 78, b(q, R) + 78), 15, B

GETINPUT2:
a$ = INKEY$: IF a$ = "" THEN GOTO GETINPUT2

IF (q = 1) * (a$ = CHR$(0) + CHR$(72)) THEN o = q: p = R: q = 4: GOTO MOVECURSOR2
IF a$ = CHR$(0) + CHR$(72) THEN o = q: p = R: q = q - 1: GOTO MOVECURSOR2

IF (R = 4) * (a$ = CHR$(0) + CHR$(77)) THEN o = q: p = R: R = 1: GOTO MOVECURSOR2
IF a$ = CHR$(0) + CHR$(77) THEN o = q: p = R: R = R + 1: GOTO MOVECURSOR2

IF (q = 4) * (a$ = CHR$(0) + CHR$(80)) THEN o = q: p = R: q = 1: GOTO MOVECURSOR2
IF a$ = CHR$(0) + CHR$(80) THEN o = q: p = R: q = q + 1: GOTO MOVECURSOR2

IF (R = 1) * (a$ = CHR$(0) + CHR$(75)) THEN o = q: p = R: R = 4: GOTO MOVECURSOR2
IF a$ = CHR$(0) + CHR$(75) THEN o = q: p = R: R = R - 1: GOTO MOVECURSOR2

IF (ASC(a$) = 8) + ((q = m) * (R = n) * (ASC(a$) = 13)) THEN k = q: l = R: GOTO MOVECURSOR1

IF ASC(a$) = 13 THEN GOTO CHECKLEGAL2
GOTO GETINPUT2

CHECKLEGAL2:
IF ((a1(m, n) = 1) * (q = m - 1) * (R = n)) + ((a2(m, n) = 1) * (q = m) * (R = n + 1)) + ((a3(m, n) = 1) * (q = m + 1) * (R = n)) + ((a4(m, n) = 1) * (q = m) * (R = n - 1)) THEN
    GOTO CHECKLEGAL3
ELSE GOTO GETINPUT2
END IF

CHECKLEGAL3:
d(q, R) = b: d(m, n) = 0
IF e(m, n) = 1 THEN e(q, R) = 2: c = 2: d = 1 ELSE e(q, R) = 1: c = 1: d = 2
e(m, n) = 0
LINE (a(m, n) - 69, b(m, n) - 69)-(a(m, n) + 69, b(m, n) + 69), 8, BF
x1 = a(q, R): x2 = b(q, R): ON b GOSUB CIRCLEPIECE, DIAMONDPIECE
LINE (a(m, n) - 78, b(m, n) - 78)-(a(m, n) + 78, b(m, n) + 78), 6, B
LINE (a(q, R) - 78, b(q, R) - 78)-(a(q, R) + 78, b(q, R) + 78), 6, B

LABEL2: '          line 310
t = 1: GOSUB LABEL3
IF x = 1 THEN GOTO LABEL1 ELSE s1 = 1: s2 = 1

MOVECURSOR3:
LOCATE 31, 92: PRINT "   Choose a piece side to play.   "
LINE (779, s1(s1) - 78)-(935, s1(s1) + 78), 6, B
LINE (779, s1(s2) - 78)-(935, s1(s2) + 78), 15, B

GETINPUT3:
a$ = INKEY$: IF a$ = "" THEN GOTO GETINPUT3
IF (s2 = 1) * ((a$ = CHR$(0) + CHR$(72)) + (a$ = CHR$(0) + CHR$(80))) THEN s1 = 1: s2 = 2: GOTO MOVECURSOR3
IF (s2 = 2) * ((a$ = CHR$(0) + CHR$(72)) + (a$ = CHR$(0) + CHR$(80))) THEN s1 = 2: s2 = 1: GOTO MOVECURSOR3
IF ASC(a$) = 13 THEN g = 1: h = 1: i = 1: j = 1: GOTO MOVECURSOR4
GOTO GETINPUT3

MOVECURSOR4:
LOCATE 31, 92: PRINT " Choose location to place piece. "
LINE (a(g, h) - 78, b(g, h) - 78)-(a(g, h) + 78, b(g, h) + 78), 6, B
LINE (a(i, j) - 78, b(i, j) - 78)-(a(i, j) + 78, b(i, j) + 78), 15, B

GETINPUT4:
a$ = INKEY$: IF a$ = "" THEN GOTO GETINPUT4
IF (i = 1) * (a$ = CHR$(0) + CHR$(72)) THEN g = i: h = j: i = 4: GOTO MOVECURSOR4
IF a$ = CHR$(0) + CHR$(72) THEN g = i: h = j: i = i - 1: GOTO MOVECURSOR4
IF (j = 4) * (a$ = CHR$(0) + CHR$(77)) THEN g = i: h = j: j = 1: GOTO MOVECURSOR4
IF a$ = CHR$(0) + CHR$(77) THEN g = i: h = j: j = j + 1: GOTO MOVECURSOR4
IF (i = 4) * (a$ = CHR$(0) + CHR$(80)) THEN g = i: h = j: i = 1: GOTO MOVECURSOR4
IF a$ = CHR$(0) + CHR$(80) THEN g = i: h = j: i = i + 1: GOTO MOVECURSOR4
IF (j = 1) * (a$ = CHR$(0) + CHR$(75)) THEN g = i: h = j: j = 4: GOTO MOVECURSOR4
IF a$ = CHR$(0) + CHR$(75) THEN g = i: h = j: j = j - 1: GOTO MOVECURSOR4
IF ASC(a$) = 8 THEN LINE (a(i, j) - 78, b(i, j) - 78)-(a(i, j) + 78, b(i, j) + 78), 6, B: GOTO GETINPUT3
IF (d(i, j) = 0) * (ASC(a$) = 13) THEN GOTO LABEL5
GOTO GETINPUT4

LABEL5: '          line 400
d(i, j) = a: e(i, j) = s2
IF s2 = 1 THEN c = 1: d = 2: ELSE c = 2: d = 1
LINE (779, s1(s2) - 78)-(935, s1(s2) + 78), 6, B
LINE (788, s1(s2) - 68)-(926, s1(s2) + 68), 8, BF
x1 = a(i, j): x2 = b(i, j): ON a GOSUB CIRCLEPIECE, DIAMONDPIECE

LABEL3: '          line 430
FOR z = 1 TO 4: FOR y = 1 TO 4: f(z, y) = 0: NEXT: NEXT

s = 0
FOR z = 1 TO 4
    FOR y = 1 TO 4
        IF d(z, y) > 0 THEN s = s + 1
    NEXT
NEXT

x = 0
FOR z = 1 TO 4
    FOR y = 1 TO 2
        IF (d(z, y) = a) * (d(z, y + 1) = a) * (d(z, y + 2) = a) * (e(z, y) = e(z, y + 1)) * (e(z, y + 1) = e(z, y + 2)) THEN
            f(z, y) = 1: f(z, y + 1) = 1: f(z, y + 2) = 1: v = 1
        ELSEIF (d(z, y) = b) * (d(z, y + 1) = b) * (d(z, y + 2) = b) * (e(z, y) = e(z, y + 1)) * (e(z, y + 1) = e(z, y + 2)) THEN
            f(z, y) = 1: f(z, y + 1) = 1: f(z, y + 2) = 1: x = 1
        END IF
        IF (d(y, z) = a) * (d(y + 1, z) = a) * (d(y + 2, z) = a) * (e(y, z) = e(y + 1, z)) * (e(y + 1, z) = e(y + 2, z)) THEN
            f(y, z) = 1: f(y + 1, z) = 1: f(y + 2, z) = 1: v = 1
        ELSEIF (d(y, z) = b) * (d(y + 1, z) = b) * (d(y + 2, z) = b) * (e(y, z) = e(y + 1, z)) * (e(y + 1, z) = e(y + 2, z)) THEN
            f(y, z) = 1: f(y + 1, z) = 1: f(y + 2, z) = 1: x = 1
        END IF
    NEXT
NEXT

FOR z = 1 TO 2
    FOR y = 1 TO 2
        w = e(z, y): u = e(2 + z, y)
        IF (d(z, y) = a) * (d(z + 1, y + 1) = a) * (d(z + 2, y + 2) = a) * (e(z + 1, y + 1) = w) * (e(z + 2, y + 2) = w) THEN
            f(z, y) = 1: f(z + 1, y + 1) = 1: f(z + 2, y + 2) = 1: v = 1
        ELSEIF (d(z, y) = b) * (d(z + 1, y + 1) = b) * (d(z + 2, y + 2) = b) * (e(z + 1, y + 1) = w) * (e(z + 2, y + 2) = w) THEN
            f(z, y) = 1: f(z + 1, y + 1) = 1: f(z + 2, y + 2) = 1: x = 1
        END IF
        IF (d(2 + z, y) = a) * (d(1 + z, 1 + y) = a) * (d(z, 2 + y) = a) * (e(1 + z, 1 + y) = u) * (e(2 + z, y) = u) THEN
            f(2 + z, y) = 1: f(1 + z, 1 + y) = 1: f(z, 2 + y) = 1: v = 1
        ELSEIF (d(2 + z, y) = b) * (d(1 + z, 1 + y) = b) * (d(z, 2 + y) = b) * (e(1 + z, 1 + y) = u) * (e(z, 2 + y) = u) THEN
            f(2 + z, y) = 1: f(1 + z, 1 + y) = 1: f(z, 2 + y) = 1: x = 1
        END IF
    NEXT
NEXT

IF t = 1 THEN t = 0: RETURN
IF s = 16 THEN s = 1: GOTO LABEL1 ELSE s = 0

SWAP a, b: GOTO STARTGAME

LABEL1: '          line 600
IF (s = 1) * (v = 1) THEN winner = a ELSE winner = b

FOR z = 1 TO 2
    x1 = 857: x2 = s1(z): c = z
    IF (s = 1) * (v <> 1) THEN w = z ELSE w = winner
    ON w GOSUB CIRCLEPIECE, DIAMONDPIECE
NEXT

IF (s = 1) * (v <> 1) THEN
    LOCATE 30, 97: PRINT "                ";: LOCATE 31, 92: PRINT "  The game has ended in a draw.  ";: winner = 0
ELSE LOCATE 30, 97: PRINT "                ";: LOCATE 31, 92: PRINT "    Player"; winner; "is the Winner!!!    ";
END IF
FOR z = 1 TO 4
    FOR y = 1 TO 4
        IF f(z, y) = 1 THEN ta = 15 ELSE ta = 6
        LINE (a(z, y) - 78, b(z, y) - 78)-(a(z, y) + 78, b(z, y) + 78), ta, B
    NEXT
NEXT

LOCATE 43, 96: PRINT "Play another game?  (Y/N)"

PLAYAGAIN:
a$ = INKEY$: IF a$ = "" THEN GOTO PLAYAGAIN:
IF (a$ = "y") + (a$ = "Y") THEN RUN
IF (a$ = "n") + (a$ = "N") THEN END
GOTO PLAYAGAIN

CIRCLEPIECE:
LINE (x1 - 68, x2 - 68)-(x1 + 68, x2 + 68), c(c), BF
CIRCLE (x1, x2), 57, 8
LINE (x1 - 57, x2)-(x1 + 57, x2), 8
LINE (x1 - 53, x2 - 19)-(x1 + 53, x2 - 19), 8
LINE (x1 - 53, x2 + 19)-(x1 + 53, x2 + 19), 8
LINE (x1 - 41, x2 - 38)-(x1 + 41, x2 - 38), 8
LINE (x1 - 41, x2 + 38)-(x1 + 41, x2 + 38), 8
PAINT (x1, x2 - 40), 12, 8
PAINT (x1, x2 - 21), 7, 8
PAINT (x1, x2 - 2), 14, 8
PAINT (x1, x2 + 2), 2, 8
PAINT (x1, x2 + 21), 9, 8
PAINT (x1, x2 + 40), 5, 8
RETURN

DIAMONDPIECE:
LINE (x1 - 68, x2 - 68)-(x1 + 68, x2 + 68), c(c), BF
PSET (x1, x2 - 57), 8
DRAW "f57g57h57e57f19l38g19r76f19l114f19r76g19l38"
PAINT (x1, x2 - 40), 12, 8
PAINT (x1, x2 - 21), 7, 8
PAINT (x1, x2 - 2), 14, 8
PAINT (x1, x2 + 2), 2, 8
PAINT (x1, x2 + 21), 9, 8
PAINT (x1, x2 + 40), 5, 8
RETURN


Rubik's Magic Strategy Board Game is a 2 player game.

Controls: Use Arrow keys to select piece and board location to place piece and press ENTER. Use BACKSPACE to deselect piece and select another piece.

This is version 2. The first version I wrote used Letters and Numbers to select a piece. I rewrote this game to use arrow keys. This game was written on the Tandy 2000 over 25 years ago.

If you download and play my game, please leave a comment or suggestion. Hope you enjoy playing.

Donald



.bas  Rubiks.bas (Size: 10.8 KB / Downloads: 60)

.pdf  Rubik's Magic Strategy Game Rules.pdf (Size: 483.94 KB / Downloads: 58)


   

       

POST MODIFIED BY ADMINISTRATOR:
Find all posts by this user
Like Post
The following 3 users Like Donald Foster's post:
Anthony.R.Brown, thelasttruegreatamerican, Waltersmind (Admin)




Forum Jump:


User(s) browsing this thread: 1 Guest(s)