Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with my Connect 4 win situations
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Justgo13




PostPosted: Tue May 31, 2016 3:44 pm   Post subject: Help with my Connect 4 win situations

What is it you are trying to achieve?
I am trying to have the program check if a player has won or not every time they drop a piece

What is the problem you are having?
I can't seem to find the right way to execute the program


Describe what you have tried to solve this problem
I have tried to make array's to have the program check each circle next to or diagonal to the newly inputted piece if they are player 1's, player 2's, or blank.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
What I have so far

Turing:


<Add your code here>  % Game start
% Column is x
% Row is y
import GUI
var font1 : int
font1 := Font.New ("Times.New.Roman:12")
setscreen ("graphics:500;500")
drawfill (1, 1, red, red)
var count : int := 0
var turns : int := 1
var pos : int
var player : array 1 .. 42 of int
for i : 1 .. 42
    player (i) := 0
end for
var xpos : array 1 .. 42 of int := init (100, 150, 200, 250, 300, 350, 400, 100, 150, 200, 250, 300, 350, 400, 100, 150, 200, 250, 300, 350, 400, 100, 150, 200, 250, 300, 350, 400, 100, 150, 200,
    250, 300, 350, 400, 100, 150, 200, 250, 300, 350, 400)
var ypos : array 1 .. 42 of int := init (115, 165, 215, 265, 315, 365, 115, 165, 215, 265, 315, 365, 115, 165, 215, 265, 315, 365, 115, 165, 215, 265, 315, 365, 115, 165, 215, 265, 315, 365, 115,
    165, 215, 265, 315, 365, 115, 165, 215, 265, 315, 365)
var x, y, button : int
procedure Start_game
    cls
    drawfill (1, 1, red, red)
    % Game board
    drawfillbox (65, 80, 435, 400, blue)
    for i : 1 .. 42
        drawfilloval (xpos (i), ypos (i), 15, 15, 0)
        Font.Draw ("Bottom", 200, 50, font1, white)
        player (i) := 0
    end for
    loop
        Mouse.Where (x, y, button)
        if button = 1 then
            for i : 1 .. 42
                pos := i
                exit when x <= (xpos (i) + 15) and x >= (xpos (i) - 15) and y <= (ypos (i) + 15) and y >= (ypos (i) - 15)
            end for
            if turns = 1 and player (pos) = 0 then
                player (pos) := 1
                turns := 2
                drawfilloval (xpos (pos), ypos (pos), 15, 15, red)
                if xpos (pos) + 50 = player (pos) then
               
            elsif turns = 2 and player (pos) = 0 then
                player (pos) := 2
                turns := 1
                drawfilloval (xpos (pos), ypos (pos), 15, 15, yellow)
            end if
            delay (300)
        end if
    end loop
end Start_game

procedure Go_back
    cls
    drawfill (1, 1, red, red)
    var button1 : int := GUI.CreateButton (10, 450, 0, "Start Game", Start_game)
end Go_back

procedure How_to_play
    cls
    drawfill (1, 1, black, black)
    Font.Draw ("1. Decide  who  plays first. Alternate turns after playing a piece.", 50, 400, font1, white)
    Font.Draw ("2. You MUST start at the bottom of the board ", 50, 350, font1, white)
    Font.Draw ("3. Click on the open hole where you want to place your piece.", 50, 300, font1, white)
    Font.Draw ("4. There must be a piece under the place you want to go", 50, 250, font1, white)
    Font.Draw ("5. When one person gets four pieces in a row, they win.", 50, 200, font1, white)
    Font.Draw ("6. If all the slots are filled and nobody won then it is a tie. ", 50, 150, font1, white)
    var button3 : int := GUI.CreateButton (50, 50, 0, "Go Back", Go_back)

end How_to_play

var button1 : int := GUI.CreateButton (10, 450, 0, "Start Game", Start_game)
var button2 : int := GUI.CreateButton (10, 425, 0, "How to play", How_to_play)


loop
    exit when GUI.ProcessEvent
end loop










Please specify what version of Turing you are using
I am using a school version so I don't know which version it is, sorry.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: