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

Username:   Password: 
 RegisterRegister   
 DrawFill Error
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
maxudaskin




PostPosted: Sun Jun 08, 2008 5:23 pm   Post subject: DrawFill Error

The following code should fill all of the squares on the left block, but only outputs this:

Posted Image, might have been reduced in size. Click Image to view fullscreen.

code:
%Declaration Statments
var attacked : boolean := false
var thisColour : int % Used to set square colours
var output_col : int % Used in xySquareID to find the clicked column
var output_row : int % Used in xySquareID to find the clicked row
var output_xy : array 1 .. 2 of int % Used in SquareIDXY to output the xy coordinates for displaying

var player_squares : array 1 .. 10, 1 .. 10 of int
var opponent_squares : array 1 .. 10, 1 .. 10 of int
for current_row : 1 .. 10
    for current_column : 1 .. 10
        player_squares (current_row, current_column) := 0
        opponent_squares (current_row, current_column) := 0
    end for
end for

% Colour Settings
var col_emp, col_hit, col_mis, col : int
col := 0
col_emp := 101 % Light Blue
col_hit := 40 % Red
col_mis := 9 %  Dark Blue

% Square ID to X Y - Inputs SquareID, Outputs the X and Y for displaying
procedure squareIDXY (input_row : int, input_col : int, who : int)
    if who = 1 then
        if input_col = 1 then
            output_xy (1) := 25
        elsif input_col = 2 then
            output_xy (1) := 50
        elsif input_col = 3 then
            output_xy (1) := 75
        elsif input_col = 4 then
            output_xy (1) := 100
        elsif input_col = 5 then
            output_xy (1) := 125
        elsif input_col = 6 then
            output_xy (1) := 150
        elsif input_col = 7 then
            output_xy (1) := 175
        elsif input_col = 8 then
            output_xy (1) := 200
        elsif input_col = 9 then
            output_xy (1) := 225
        elsif input_col = 10 then
            output_xy (1) := 250
        end if
    else
        if input_col = 1 then
            output_xy (1) := 275
        elsif input_col = 2 then
            output_xy (1) := 300
        elsif input_col = 3 then
            output_xy (1) := 325
        elsif input_col = 4 then
            output_xy (1) := 350
        elsif input_col = 5 then
            output_xy (1) := 375
        elsif input_col = 6 then
            output_xy (1) := 400
        elsif input_col = 7 then
            output_xy (1) := 425
        elsif input_col = 8 then
            output_xy (1) := 450
        elsif input_col = 9 then
            output_xy (1) := 475
        elsif input_col = 10 then
            output_xy (1) := 500
        end if
    end if
    if input_col = 10 then
        output_xy (2) := 25
    elsif input_col = 9 then
        output_xy (2) := 50
    elsif input_col = 8 then
        output_xy (2) := 75
    elsif input_col = 7 then
        output_xy (2) := 100
    elsif input_col = 6 then
        output_xy (2) := 125
    elsif input_col = 5 then
        output_xy (2) := 150
    elsif input_col = 4 then
        output_xy (2) := 175
    elsif input_col = 3 then
        output_xy (2) := 200
    elsif input_col = 2 then
        output_xy (2) := 225
    elsif input_col = 1 then
        output_xy (2) := 250
    end if
end squareIDXY

% Check if Already Attacked
procedure checkAttacked (input_row : int, input_col : int, who : int)
    attacked := false % Reset attacked to false
    if who = 1 then % If who is player(1)
        if player_squares (input_row, input_col) = 0 then
            attacked := false
        else
            attacked := true
        end if
    else % If who is opponant (2)
        if opponent_squares (input_row, input_col) = 0 then
            attacked := false
        else
            attacked := true
        end if
    end if
end checkAttacked

% Colour in Squares
procedure fillSquares
    for column : 1 .. 10
        for row : 1 .. 10
            squareIDXY (row, column, 1)
            squareColour (row, column, 1)
            drawfill (output_xy (1), output_xy (2), thisColour, 7)
        end for
    end for
end fillSquares
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Sun Jun 08, 2008 8:16 pm   Post subject: RE:DrawFill Error

Can you attach your whole code. I need to have squareColour and probably some other things.
DemonWasp




PostPosted: Thu Jun 12, 2008 8:54 pm   Post subject: RE:DrawFill Error

Your procedure squareIDXY only ever checks input_col; it never even looks at input_row. I would imagine that the Y-coordinate corresponds to input_row, rather than input_col.

Also, you really, really don't need all those complicated IF statements. You can definitely do it WAY more easily by simple multiplication.

Consider:
Turing:

        if input_col = 1 then
            output_xy (1) := 25
        elsif input_col = 2 then
            output_xy (1) := 50
        elsif input_col = 3 then
            output_xy (1) := 75
        elsif input_col = 4 then
            output_xy (1) := 100
        elsif input_col = 5 then
            output_xy (1) := 125
        elsif input_col = 6 then
            output_xy (1) := 150
        elsif input_col = 7 then
            output_xy (1) := 175
        elsif input_col = 8 then
            output_xy (1) := 200
        elsif input_col = 9 then
            output_xy (1) := 225
        elsif input_col = 10 then
            output_xy (1) := 250
        end if


Note the following:
1 -> 25
2 -> 50
3 -> 75
4 -> 100
...
n -> 25 * n

So why not just use:
Turing:

        output_xy (1) := 25 * input_col


I'll leave the other blocks up to you to figure out.
riveryu




PostPosted: Thu Jun 12, 2008 9:55 pm   Post subject: RE:DrawFill Error

This may not be the goal of the program but, maybe you can just draw a blue background and draw the grid lines on it to make it LOOK like its filled?
SNIPERDUDE




PostPosted: Fri Jun 13, 2008 12:19 am   Post subject: RE:DrawFill Error

I believe that would kill the point...
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  [ 5 Posts ]
Jump to:   


Style:  
Search: