You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Connect Four in QB64
06-15-2014, 05:30 PM (This post was last modified: 02-20-2015 03:21 PM by Waltersmind.)
Post: #1
 (Print Post)
Connect Four in QB64
Here is my connect Four game in QB64. It is a 2 player game. Game controls: Number keys to select desired column and press ENTER to place piece on board.

I originally wrote it close about 30 years ago on the TRS-80 Model 4 using ASCII character set for graphics. The Model 4 used a B&W monitor. High Resolution Graphics were available as a option to purchase for it. I never bought it, but wish I did.

When I purchased the Tandy 2000 in late 1986, Connect Four was the first game I wrote on it in High Resolution Color Graphics in GW-BASIC. There was an option to buy a Compiler BASIC, but I never did. Running the game in the BASIC interpreter, my wife liked that, watching the board and pieces being drawn onto the screen.

A few months ago I stated getting back into programming after a 20 year break. QB64 is the perfect language to come back with and remake my games again, so I can play them again and on newer computer systems. And so I can share my games with others to enjoy as well.

I posted this game in QB64.net forum and wanted to share it here also. I enjoy receiving comments and suggestions about my games. So, if you try my games, please leave comment. Just keep in mind that I originally write it about 30 years ago and my goal is to reproduce my games as close to as they were originally done within reason. I have made some improvements on the games, because I have more colors to work with.

Donald
Find all posts by this user
Like Post
08-21-2014, 01:47 PM (This post was last modified: 10-30-2016 11:51 AM by Waltersmind.)
Post: #2
 (Print Post)
RE: Connect Four in QB64
Hi Donald
Your Attachments are Not! Attached ?


Anthony.
Find all posts by this user
Like Post
08-21-2014, 08:59 PM (This post was last modified: 10-30-2016 11:51 AM by Waltersmind.)
Post: #3
 (Print Post)
RE: Connect Four in QB64
Code Snippet: [Select]
_TITLE "Connect Four by Donald L. Foster Jr."


SCREEN _NEWIMAGE(1000, 735, 256)

_LIMIT 100

_PALETTECOLOR 9, _RGB32(0, 0, 155) '       Blue
_PALETTECOLOR 6, _RGB32(255, 140, 0) '     Yellow
_PALETTECOLOR 1, _RGB32(0, 95, 0) '       Green
_PALETTECOLOR 4, _RGB32(185, 0, 0) '       Red

d(1) = 0: d(2) = 4: e = 1: f = 0

DATA 1,6,2,6,3,6,4,6,1,5,2,5,3,5,4,5,1,4,2,4,3,4,4,4
DATA 4,6,5,6,6,6,7,6,4,5,5,5,6,5,7,5,4,4,5,4,6,4,7,4

LINE (0, 0)-(999, 734), 9, BF
COLOR 15, 9
LOCATE 2, 39: PRINT "C   O   N   N   E   C   T          F   O   U   R";
LOCATE 4, 23: PRINT "(1)          (2)          (3)          (4)          (5)          (6)          (7)";

LOCATE 7, 9: PRINT "P"; STRING$(107, 32); "P";
LOCATE 9, 9: PRINT "L"; STRING$(107, 32); "L";
LOCATE 11, 9: PRINT "A"; STRING$(107, 32); "A";
LOCATE 13, 9: PRINT "Y"; STRING$(107, 32); "Y";
LOCATE 15, 9: PRINT "E"; STRING$(107, 32); "E";
LOCATE 17, 9: PRINT "R"; STRING$(107, 32); "R";
LOCATE 19, 8: PRINT "[1]"; STRING$(105, 32); "[2]";

CIRCLE (67, 380), 40, 15: PAINT (67, 380), 0, 15
CIRCLE (933, 380), 40, 15: PAINT (933, 380), 4, 15

LINE (134, 70)-(864, 695), 1, BF: LINE (139, 75)-(859, 690), 14, BF
v = 6: x = 0
FOR z = 1 TO 6
    w = 0
    FOR y = 1 TO 7
        LINE (190 - 51 + w, 125 - 51 + x)-(190 + 51 + w, 125 + 51 + x), 1, BF
        LINE (192 - 51 + w, 127 - 51 + x)-(188 + 51 + w, 123 + 51 + x), 14, BF
        CIRCLE (190 + w, 125 + x), 40, 15: PAINT (190 + w, 125 + x), 9, 15
        a(y) = 1: b(y, v) = 190 + w: c(y, v) = 125 + x
        w = w + 103
    NEXT
    v = v - 1: x = x + 103
NEXT

STARTGAME:
IF e = 1 THEN LINE (17, 330)-(117, 430), 15, B ELSE LINE (883, 330)-(983, 430), 15, B

LOCATE 45, 38: PRINT "Player"; e; "please enter number of desired column. [_]";

GETINPUT:
a$ = INKEY$: IF a$ = "" THEN GOTO GETINPUT
b = VAL(a$): IF (b > 0) * (b < 8) * (a(b) < 7) THEN LOCATE 45, 87: PRINT a$;: GOTO GETENTER
GOTO GETINPUT

GETENTER:
a$ = INKEY$: IF a$ = "" THEN GOTO GETENTER
IF ASC(a$) = 8 THEN LOCATE 45, 87: PRINT "_";: GOTO GETINPUT
IF ASC(a$) <> 13 THEN GOTO GETENTER

PAINT (b(b, a(b)), c(b, a(b))), d(e), 15
e(b, a(b)) = e: a(b) = a(b) + 1: t = t + 1

FOR z = 1 TO 7
    FOR y = 1 TO 3
        IF (e(z, y) > 0) * (e(z, y) = e(z, y + 1)) * (e(z, y + 1) = e(z, y + 2)) * (e(z, y + 2) = e(z, y + 3)) THEN GOTO WINNER
    NEXT
NEXT

FOR z = 1 TO 6
    FOR y = 1 TO 4
        IF (e(z, y) > 0) * (e(z, y) = e(z + 1, y)) * (e(z + 1, y) = e(z + 2, y)) * (e(z + 2, y) = e(z + 3, y)) THEN GOTO WINNER
    NEXT
NEXT

FOR z = 1 TO 12
    READ f, g
    IF (e(f, g) > 0) * (e(f, g) = e(f + 1, g - 1)) * (e(f + 1, g - 1) = e(f + 2, g - 2)) * (e(f + 2, g - 2) = e(f + 3, g - 3)) THEN GOTO WINNER
NEXT

FOR z = 1 TO 12
    READ f, g
    IF (e(f, g) > 0) * (e(f, g) = e(f - 1, g - 1)) * (e(f - 1, g - 1) = e(f - 2, g - 2)) * (e(f - 2, g - 2) = e(f - 3, g - 3)) THEN GOTO WINNER
NEXT

RESTORE
GOTO TIE

WINNER:
LOCATE 45, 38: PRINT " Player"; e; "is the Winner!!!     Play again? (Y or N) ";
GOTO PLAYAGAIN

TIE:
IF t = 42 THEN LOCATE 45, 37: PRINT "The game has ended in a tie.     Play again? (Y or N)"; ELSE GOTO SWITCHPLAYERS
IF e = 1 THEN LINE (17, 330)-(117, 430), 9, B ELSE LINE (883, 330)-(983, 430), 9, B

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

SWITCHPLAYERS:
IF e = 1 THEN LINE (17, 330)-(117, 430), 9, B ELSE LINE (883, 330)-(983, 430), 9, B

IF e = 1 THEN e = 2 ELSE e = 1
GOTO STARTGAME


Attached File(s) Image(s)
       

.bas  Connect Four.bas (Size: 3.5 KB / Downloads: 27)
Find all posts by this user
Like Post
08-22-2014, 06:01 AM
Post: #4
 (Print Post)
RE: Connect Four in QB64
Cool Cool Donald I found your other Connect 4 link as-well! Wink


Anthony.
Find all posts by this user
Like Post



Forum Jump:


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




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