You are not logged in or registered. Please login or register to use the full functionality of this board...
The QB64 Edition
9 Board Game in QB64 - Printable Version

+- The QB64 Edition (http://www.thejoyfulprogrammer.com/qb64/forum)
+ Thread: 9 Board Game in QB64 (/showthread.php?tid=203)



9 Board Game in QB64 - Donald Foster - 12-08-2014 12:42 AM

Hello all,

9 is a board game put out by Nestorgames. They have a website with pictures and PDF rules you can download for over a dozen of their games. 9 is my first attempt to remake one of their games. I originally started making 9 months ago and had trouble with game ending scores. So it got put on the back burner. I finally dug it out and finished it. I also have a few more games I started months ago. I guess one day they'll get finished too.

9 is a 2 to 4 player game played in 3 stages on a Sodoku type game board. Player 1 plays with the Yellow pieces. Player 2 playes with Blue pieces. Player 3 playes with the Green Pieces and Player 4 playes with the Orange pieces. The games rules had Player 3 Orange and Player 4 Green. I didn't like that for my game and swapped them. There are 9 Red Marker pieces.

In the first phase, players take turns placing one Red Marker piece in each of the 9 Cells of the game board. Each Cell is a 3x3 grid sharing the same board background color. The colors alternate to seperate the Cells from one another. The Red Markers can be placed anywhere in the Cell using < Up, Down, Right, Left Arrow Keys> except the outer sqares of the Cell. For example Rows 2 to 8 and Columns 2 to 8. The computer will prevent placing the Red Markers outside those locations. The Red Markers limit the movement of the Players pieces. They act as road blocks.

In the scond phase of the game, each player, in turn, places one piece at a time outside the game board location. There are 36 locations around the outside the game board. Players takes turn placing their pieces. All 36 locations will be filled regardless of the number of players. The <Right Arrow Key> advances the cursor around the 36 positions in a Clockwise motion. The <Left Arrow Key> advances the cursor around the 36 positions in a Clounter Clockwise motion.

In the third phase, each player slides one of their pieces from the outside edge of the board inward til that piece travel is ended on the approach of one of the Red Markers or another player's piece. Players continue taking turns sliding their pieces inward till no more pieces can be moved. Some pieces may be blocked from moving and will remain outside of the game board. 

After all the pieces, that will moves, are slide into the game board, scores are calculated and the winner is declaired. Scoring is as followed: The Cells are numbered 1 to 9 starting with Cell at the Upper Left corner is number 1 and moving across the top then downward to the Right Lower Cell is 9. Each Cell is calculated seperately and the player with the most number of pieces in that Cell is the Winner of that Cell. The player who Wins the most number of Cells, Wins the game. I have included a copy of the rules as well as a photo of the actual game and a screenshot of the game.

Hope you enjoy playing.
Donald

Code Snippet: [Select]
_TITLE "9 by Donald L. Foster Jr."


SCREEN _NEWIMAGE(1010, 735, 256)

_PALETTECOLOR 7, _RGB32(255, 215, 0) '        Yellow
_PALETTECOLOR 9, _RGB32(0, 0, 180) '          Blue
_PALETTECOLOR 14, _RGB32(255, 140, 0) '       Orange
_PALETTECOLOR 2, _RGB32(0, 180, 0) '          Green
_PALETTECOLOR 12, _RGB32(255, 0, 0) '         Red
_PALETTECOLOR 3, _RGB32(144, 238, 144)
_PALETTECOLOR 13, _RGB32(255, 192, 203)

DIM a1(36), b1(36), d1(36), e1(36), e2(36), e3(36), e4(36), l1(36), m1(36)

a = 1: c = 5: d = 5: e = 5: f = 5: endgame = 1
c(1) = 7: c(2) = 9: c(3) = 2: c(4) = 14

LINE (0, 0)-(1009, 734), 15, BF
LINE (76, 76)-(658, 658), 0, BF
LINE (79, 79)-(654, 654), 15, BF
x = 0
FOR z = 1 TO 9
    w = 0
    FOR y = 1 TO 9
        IF (z < 4) * (y < 4) THEN
            cell(z, y) = 1: cellcolor(z, y) = 3
        ELSEIF (z < 4) * (y > 6) THEN cell(z, y) = 3: cellcolor(z, y) = 3
        ELSEIF z < 4 THEN cell(z, y) = 2: cellcolor(z, y) = 13
        ELSEIF (z > 6) * (y < 4) THEN cell(z, y) = 7: cellcolor(z, y) = 3
        ELSEIF (z > 6) * (y > 6) THEN cell(z, y) = 9: cellcolor(z, y) = 3
        ELSEIF z > 6 THEN cell(z, y) = 8: cellcolor(z, y) = 13
        ELSEIF y < 4 THEN cell(z, y) = 4: cellcolor(z, y) = 13
        ELSEIF y > 6 THEN cell(z, y) = 6: cellcolor(z, y) = 13
        ELSE cell(z, y) = 5: cellcolor(z, y) = 3
        END IF
        LINE (79 + w, 79 + x)-(143 + w, 143 + x), cellcolor(z, y), BF
        a(z, y) = 111 + w: b(z, y) = 111 + x
        w = w + 64
    NEXT
    a1(z) = 111 + x: b1(z) = 44: a1(9 + z) = 690: b1(9 + z) = 111 + x: a1(18 + z) = 623 - x: b1(18 + z) = 690: a1(27 + z) = 44: b1(27 + z) = 623 - x
    x = x + 64
NEXT

x = 0
FOR z = 1 TO 10
    LINE (79 + x, 14)-(79 + x, 719), 0
    LINE (14, 79 + x)-(719, 79 + x), 0
    x = x + 64
NEXT

LINE (734, 0)-(1010, 735), 0, BF

COLOR 15, 0
LOCATE 44, 95: PRINT "Number of players (2 to 4). [_]";

CURSOR1:
a$ = INKEY$: IF a$ = "" THEN GOTO CURSOR1
IF (VAL(a$) > 1) * (VAL(a$) < 5) THEN b = VAL(a$): LOCATE 44, 124: PRINT a$;: GOTO CURSOR1
IF ASC(a$) = 8 THEN LOCATE 44, 124: PRINT "_";: GOTO CURSOR1
IF ASC(a$) <> 13 THEN GOTO CURSOR1
IF (b < 2) + (b > 4) THEN GOTO CURSOR1

LOCATE 44, 95: PRINT "                               ";

PLAYERINDICATOR:
CIRCLE (872, 107), 28, 8: PAINT (872, 107), c(a), 8
LOCATE 10, 106: PRINT "Player:"; a;

CIRCLE (872, 300), 28, 8: PAINT (872, 300), 12, 8
LOCATE 15, 103: PRINT "Place a marker";: LOCATE 16, 97: PRINT "in one of the empty cells.";

CURSOR2:
LINE (a(c, d) - 31, b(c, d) - 31)-(a(c, d) + 31, b(c, d) + 31), cellcolor(c, d), B
LINE (a(e, f) - 31, b(e, f) - 31)-(a(e, f) + 31, b(e, f) + 31), 0, B

GETINPUT1:
a$ = INKEY$
IF a$ = "" THEN GOTO GETINPUT1
IF (a$ = CHR$(0) + CHR$(72)) * (e = 2) THEN c = e: d = f: e = 8: GOTO CURSOR2
IF a$ = CHR$(0) + CHR$(72) THEN c = e: d = f: e = e - 1: GOTO CURSOR2
IF (a$ = CHR$(0) + CHR$(77)) * (f = 8) THEN c = e: d = f: f = 2: GOTO CURSOR2
IF a$ = CHR$(0) + CHR$(77) THEN c = e: d = f: f = f + 1: GOTO CURSOR2
IF (a$ = CHR$(0) + CHR$(80)) * (e = 8) THEN c = e: d = f: e = 2: GOTO CURSOR2
IF a$ = CHR$(0) + CHR$(80) THEN c = e: d = f: e = e + 1: GOTO CURSOR2
IF (a$ = CHR$(0) + CHR$(75)) * (f = 2) THEN c = e: d = f: f = 8: GOTO CURSOR2
IF a$ = CHR$(0) + CHR$(75) THEN c = e: d = f: f = f - 1: GOTO CURSOR2
IF ASC(a$) <> 13 THEN GOTO GETINPUT1

IF (d(e, f) = 0) * (marker(cell(e, f)) = 0) THEN
    d(e, f) = 5: counter = counter + 1: marker(cell(e, f)) = 1: CIRCLE (a(e, f), b(e, f)), 28, 8: PAINT (a(e, f), b(e, f)), 12, 8
ELSE GOTO GETINPUT1
END IF

IF a = b THEN a = 1 ELSE a = a + 1

IF counter < 9 THEN GOTO PLAYERINDICATOR

a = 1: c = e: d = f: g = 1: h = 1: counter = 0
LINE (a(c, d) - 31, b(c, d) - 31)-(a(c, d) + 31, b(c, d) + 31), cellcolor(c, d), B

PLAYERINDICATOR1:
CIRCLE (872, 107), 28, 0: PAINT (872, 107), c(a), 0
LOCATE 10, 106: PRINT "Player:"; a;

IF counter < 36 THEN
    LOCATE 15, 99: PRINT "    Place your piece    ";: LOCATE 16, 96: PRINT "outside of the playing board.";
ELSE LOCATE 15, 99: PRINT "     Choose a piece     ";: LOCATE 16, 96: PRINT "   to move onto the board.   ";
END IF

LINE (842, 270)-(902, 330), 0, BF

IF counter < 36 THEN GOTO cursor3

endplayer = 1

FOR z = 1 TO 36: e1(z) = 0: NEXT
FOR z = 1 TO 36
    IF d1(z) = 0 THEN GOTO ENDLOOP
    IF z < 10 THEN i = 1: j = z: k = 0: GOTO DIR1
    IF (z > 9) * (z < 19) THEN i = z - 9: j = 9: k = 0: GOTO DIR2
    IF (z > 18) * (z < 28) THEN i = 9: j = 28 - z: k = 0: GOTO DIR3
    IF z > 27 THEN i = 37 - z: j = 1: k = 0: GOTO DIR4

    DIR1:
    IF i + k < 10 THEN
        IF d(i + k, j) = 0 THEN
            IF (d1(z) = a) * (i + k = 9) THEN e1(z) = 1: l1(z) = 9: m1(z) = j: endplayer = 0: GOTO ENDLOOP
            k = k + 1: GOTO DIR1
        ELSE k = k - 1
        END IF
    END IF
    IF k >= 0 THEN
        endgame = 0
        IF (d1(z) = a) + (i + k = 9) THEN
            e1(z) = 1: l1(z) = i + k: m1(z) = z: endplayer = 0
        END IF
    END IF
    GOTO ENDLOOP

    DIR2:
    IF j - k >= 0 THEN
        IF d(i, j - k) = 0 THEN
            IF (d1(z) = a) * (j - k = 1) THEN e1(z) = 1: l1(z) = i: m1(z) = 1: endplayer = 0: GOTO ENDLOOP
            k = k + 1: GOTO DIR2
        ELSE k = k - 1
        END IF
    END IF
    IF k >= 0 THEN
        endgame = 0
        IF (d1(z) = a) + (j - k = 1) THEN
            e1(z) = 1: l1(z) = i: m1(z) = j - k: endplayer = 0
        END IF
    END IF
    GOTO ENDLOOP

    DIR3:
    IF i - k >= 0 THEN
        IF d(i - k, j) = 0 THEN
            IF (d1(z) = a) * (i - k = 1) THEN e1(z) = 1: l1(z) = 1: m1(z) = j: endplayer = 0: GOTO ENDLOOP
            k = k + 1: GOTO DIR3
        ELSE k = k - 1
        END IF
    END IF
    IF k >= 0 THEN
        endgame = 0
        IF (d1(z) = a) + (i - k = 1) THEN
            e1(z) = 1: l1(z) = i - k: m1(z) = j: endplayer = 0
        END IF
    END IF
    GOTO ENDLOOP

    DIR4:
    IF j + k < 10 THEN
        IF d(i, j + k) = 0 THEN
            IF (d1(z) = a) * (j + k = 9) THEN e1(z) = 1: l1(z) = i: m1(z) = 9: endplayer = 0: GOTO ENDLOOP
            k = k + 1: GOTO DIR4
        ELSE k = k - 1
        END IF
    END IF
    IF k >= 0 THEN
        endgame = 0
        IF (d1(z) = a) + (j + k = 9) THEN
            e1(z) = 1: l1(z) = i: m1(z) = j + k: endplayer = 0
        END IF
    END IF

    ENDLOOP:
NEXT

IF endgame = 1 THEN
    LINE (734, 0)-(1010, 735), 0, BF
    LOCATE 23, 104: PRINT "Cells Won by:";

    v = 0: w = 0
    FOR y = 1 TO b
        CIRCLE (872, 48 + w), 28, 8: PAINT (872, 48 + w), c(y), 8
        LOCATE 6 + v, 106: PRINT "Player:"; y;
        v = v + 5: w = w + 80
    NEXT

    x = 0
    FOR z = 1 TO 9
        celltotal = 0
        FOR y = 1 TO b
            IF playercell(y, z) > celltotal THEN celltotal = playercell(y, z): cellwinner(z) = y ELSE IF playercell(y, z) = celltotal THEN cellwinner(z) = 0
        NEXT
        LOCATE 25 + x, 100: PRINT "Cell"; z; ":    ";: IF cellwinner(z) = 0 THEN PRINT "No Winner"; ELSE PRINT "Player "; cellwinner(z);
        x = x + 2
    NEXT

    FOR z = 1 TO b: playerwinner(z) = 0: NEXT
    FOR z = 1 TO 9: playerwinner(cellwinner(z)) = playerwinner(cellwinner(z)) + 1: NEXT

    cells = 0
    FOR z = 1 TO b
        IF playerwinner(z) > cells THEN cells = playerwinner(z): winner = z ELSE IF playerwinner(z) = cells THEN winner = 0
    NEXT

    LOCATE 43, 97: IF winner = 0 THEN PRINT "The game ended in a Draw!!!"; ELSE PRINT " Player"; winner; "is the winner!!! ";

    LOCATE 45, 96: PRINT "Play Another Game?  ( Y / N )";

    ENDGAME:
    a$ = UCASE$(INKEY$)
    IF a$ = "" THEN GOTO ENDGAME
    IF a$ = "Y" THEN RUN
    IF a$ = "N" THEN END
    GOTO ENDGAME

END IF

IF endplayer = 1 THEN
    LOCATE 15, 99: PRINT "You have no more moves. ";
    LOCATE 16, 96: PRINT " Press <ENTER> to continue. ";
    PRESSENTER:
    a$ = INKEY$: IF a$ = "" THEN GOTO PRESSENTER
    IF ASC(a$) <> 13 THEN GOTO PRESSENTER
    GOTO ENDTURN
END IF

cursor3:
LINE (a1(g) - 30, b1(g) - 30)-(a1(g) + 30, b1(g) + 30), 15, B
LINE (a1(h) - 30, b1(h) - 30)-(a1(h) + 30, b1(h) + 30), 0, B

GETINPUT2:
a$ = INKEY$
IF a$ = "" THEN GOTO GETINPUT2
IF (a$ = CHR$(0) + CHR$(77)) * (h = 36) THEN g = h: h = 1: GOTO cursor3
IF a$ = CHR$(0) + CHR$(77) THEN g = h: h = h + 1: GOTO cursor3
IF (a$ = CHR$(0) + CHR$(75)) * (h = 1) THEN g = h: h = 36: GOTO cursor3
IF a$ = CHR$(0) + CHR$(75) THEN g = h: h = h - 1: GOTO cursor3
IF ASC(a$) <> 13 THEN GOTO GETINPUT2

IF (d1(h) = 0) * (counter < 36) THEN
    d1(h) = a
    CIRCLE (a1(h), b1(h)), 28, 0: PAINT (a1(h), b1(h)), c(a), 0
    counter = counter + 1

ELSEIF (d1(h) = a) * (e1(h) = 1) * (counter = 36) THEN
    d1(h) = 0
    e1(h) = 0
    d(l1(h), m1(h)) = a
    playercell(a, cell(l1(h), m1(h))) = playercell(a, cell(l1(h), m1(h))) + 1
    LINE (a1(h) - 30, b1(h) - 30)-(a1(h) + 30, b1(h) + 30), 15, BF
    CIRCLE (a(l1(h), m1(h)), b(l1(h), m1(h))), 28, 0
    PAINT (a(l1(h), m1(h)), b(l1(h), m1(h))), c(a), 0

ELSE GOTO GETINPUT2
END IF

ENDTURN:
IF a = b THEN a = 1 ELSE a = a + 1

endgame = 1

GOTO PLAYERINDICATOR1

[attachment=363][attachment=364][attachment=365][attachment=366]