Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Connect 4 game variable problems
Author Message
IBeMily

Posted: Tue Oct 31, 2017 12:38 pm   Post subject: Connect 4 game variable problems

I am trying to fix a problem with my variables

 Turing: % Global variables var mx, my, mbut : int % mbut = 1 if clicked var board : array 1 .. 6, 1 .. 7 of int % connect 4 board (6 rows, 7 columns) for row : 1 .. 6     for col : 1 .. 7         board (row, col) := 0 % 0 = empty, 1 = red, 2 = yellow         var column : int         var player : int     end for end for % procedures and functions proc updateBoard     var row : int := 6     var x, y : int     var done : boolean := false     loop         if board (row, column) = 0 then %empty spot             x := (column - 1) * 100 + 372             y := (row - 1) * 100 - 27             if player = 1 then % red                 Draw.FillOval (x, y, 40, 40, brightred)             elsif player = 2 then % yellow                 Draw.FillOval (x, y, 40, 40, yellow)             end if             delay (50) % wait             Draw.FillOval (x, y, 40, 40, white) % erase             row := row - 1         else             if board (row, column) = 1 then % red                 Draw.FillOval (x, y, 40, 40, brightred)             elsif board (row, column) = 2 then % yellow                 Draw.FillOval (x, y, 40, 40, yellow)             end if             done := true         end if         exit when done = true     end loop end updateBoard proc drawBoard     var row, col : int     Draw.FillBox (322, 23, 1022, 623, blue)     for y : 73 .. 573 by 100         for x : 372 .. 972 by 100             row := (y - 23) div 100 + 1             col := (x - 322) div 100 + 1             if board (row, col) = 0 then % empty                 Draw.FillOval (x, y, 40, 40, white)             elsif board (row, col) = 1 then % red                 Draw.FillOval (x, y, 40, 40, brightred)             end if         end for     end for end drawBoard proc updateMemory     var row, col : int     row := (my - 23) div 100 + 1     col := (mx - 322) div 100 + 1     if board (row, col) = 0 then %empty spot         board (row, col) := 1     end if end updateMemory proc drawChip     Draw.FillOval (mx, my, 40, 40, red) end drawChip % mainline drawBoard loop     Mouse.Where (mx, my, mbut)     locate (1, 1)     put mx, " ", my, " ", mbut     if mbut = 1 then         %drawChip         updateMemory         drawBoard     end if end loop

My variables column and player aren't working. Do you have a suggestion. I've tried and failed to incorporate the new variables, but it didn't work

Turing 4.1.1

Clayton

Posted: Tue Oct 31, 2017 2:13 pm   Post subject: RE:Connect 4 game variable problems

The issue you are running into has to do with a concept known as scope in programming. Look at where you've declared your variables. Where should they be able to be seen to the rest of the program?
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: