
-----------------------------------
Cezna
Thu Jun 17, 2010 2:12 pm

Cezna's Connect 4
-----------------------------------
A few people expressed interest in seeing this, so here it is.
If anyone wants to improve it or help me put AI into it, please post back.


setscreen ("graphics:600;610, position:center;center, offscreenonly, nobuttonbar, title:Connect 4")
var board, piece1, piece2, mousex, mousey, button, turn, column, board_clr, background_clr, player_1_clr,
    player_2_clr : int
var column_height : array 1 .. 7 of int := init (0, 0, 0, 0, 0, 0, 0)
var clicked : boolean := false
var keys : array char of boolean
var win_font := Font.New ("Comic Sans MS:30")

%%% CUSTOMIZABLE PREDEFS %%%
board_clr := 43
background_clr := white
player_1_clr := brightred
player_2_clr := brightblue

forward proc Main

Main

proc DrawPictures
    colourback (background_clr)
    cls
    % BOARD %
    drawfillbox (0, 0, 600, 515, board_clr)
    drawbox (0, 0, 600, 515, black)
    for x : 1 .. 7
        for y : 1 .. 6
            drawfilloval (x * 85 - 40, y * 85 - 40, 40, 40, background_clr)
            drawoval (x * 85 - 40, y * 85 - 40, 40, 40, black)
        end for
    end for
    board := Pic.New (0, 0, 700, 585)
    cls
    % PIECES %
    drawfilloval (100, 100, 40, 40, player_1_clr)
    drawoval (100, 100, 40, 40, black)
    piece1 := Pic.New (60, 60, 140, 140)
    drawfilloval (200, 200, 40, 40, player_2_clr)
    drawoval (200, 200, 40, 40, black)
    piece2 := Pic.New (160, 160, 240, 240)
end DrawPictures

proc Win (clr : int)
    if clr = player_1_clr then
        Font.Draw ("RED WINS", 193, 550, win_font, player_1_clr)
    elsif clr = player_2_clr then
        Font.Draw ("BLUE WINS", 182, 550, win_font, player_2_clr)
    end if
    View.Update
    % frees image IDs so pictures can be redrawn
    Pic.Free (board)
    Pic.Free (piece1)
    Pic.Free (piece2)
    loop
        Mouse.Where (mousex, mousey, button)
        exit when button = 1 or hasch
    end loop
    Main
end Win

proc CheckForLines (x, y, clr : int)
    var scan_dist := 85
    var line := 1
    %% CHECK FOR VERTICAL LINES %%
    if y div 85 