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

Username:   Password: 
 RegisterRegister   
 Loops are messing up my program! Need Help!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
kavinda123




PostPosted: Wed Jan 15, 2014 1:30 pm   Post subject: Loops are messing up my program! Need Help!

What is it you are trying to achieve?
I am trying to make an interface for a card game i am making. Its called Hockey. I am also trying to make a random message/tip square where random messages pop up.
Thanks for any help.


What is the problem you are having?
Loops are messing up the program


Describe what you have tried to solve this problem
changing positions of the loops


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

Turing:


% Main code



    % Graphics
        % Layout

        % Cards


    % Logic
        % Shuffling
            for i : 1 .. 10000
                randint (r, 1, 20)
                save := deck (1 .. r)
                deck := deck (r + 1 .. *)
                deck := deck (r + 1 .. *) + deck (1 .. r) + save
            end for

            cls
            put deck


        % Random Message   
       
            Draw.Box (1025, 920, 1265, 660, black)
           
            Font.Draw ("Tip: ", 1030, 900, font1, black)   
         
        % mousewhere
        loop
            loop
                mousewhere (x, y, button)
                locate ((maxrow - 1), 2)
                if button = 0 then
                    delay (50)
                    put x : 4, "  ", y : 4, "  button up"
                else
                    delay (50)
                    put x : 4, "  ", y : 4, "  button down"
                end if
            end loop

                    loop
                    randint (messageTextNumber, 1, 5)
                        if messageTextNumber = 1 then                           
                            locate (2, 120)                           
                            delay (500)
                            put "yiouoirojo;fdgdg"
                        elsif messageTextNumber = 2 then
                            locate (2, 120)                       
                             
                            delay (500)
                            put "FGFGFDG"                                                                                                           
                        elsif messageTextNumber = 3 then
                            locate (2, 120)                       
                            delay (500)
                            put "fhgf"                                                     
                        elsif messageTextNumber = 4 then
                            locate (2, 120)                           
                            delay (500)
                            put "uioipiopiop"                                                 
                        elsif messageTextNumber = 5 then
                            locate (2, 120)                           
                            delay (500)
                            put "v dfgfthtukhkffserf"                     
                        end if
                    end loop
        end loop



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Jan 15, 2014 1:50 pm   Post subject: RE:Loops are messing up my program! Need Help!

code:
loop
                    randint (messageTextNumber, 1, 5)
                        if messageTextNumber = 1 then                           
                            locate (2, 120)                           
                            delay (500)
                            put "yiouoirojo;fdgdg"
                        elsif messageTextNumber = 2 then
                            locate (2, 120)                       
                             
                            delay (500)
                            put "FGFGFDG"                                                                                                           
                        elsif messageTextNumber = 3 then
                            locate (2, 120)                       
                            delay (500)
                            put "fhgf"                                                     
                        elsif messageTextNumber = 4 then
                            locate (2, 120)                           
                            delay (500)
                            put "uioipiopiop"                                                 
                        elsif messageTextNumber = 5 then
                            locate (2, 120)                           
                            delay (500)
                            put "v dfgfthtukhkffserf"                     
                        end if
                    end loop


This loop will never execute. Ever. Can you tell me why?
Tony




PostPosted: Wed Jan 15, 2014 3:15 pm   Post subject: RE:Loops are messing up my program! Need Help!

on a completely unrelated node
code:

% Shuffling
            for i : 1 .. 10000
                randint (r, 1, 20)

I bet you can shuffle a deck of cards in much less than 10,000 random moves.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
kavinda123




PostPosted: Fri Jan 17, 2014 1:17 pm   Post subject: Re: Loops are messing up my program! Need Help!

ok, so i need help on adding the process or procedure statement into my code. can you guys tell me or fix my code so this will work? i need to have multiple loops to be running for this. Thanks.

here's my updated code:

code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Name : Kavinda Weerakoon
% The Hockey Card Game Culminating Assignment
% Course: ICS2O1
% Date: January 14th, 2014
% Description: This program replicates the card game "Hockey", primarily popular in Canada. This is a player vs. computer competition.
%              This game is played mainly in Canada, and seems to have originated there in the 1960's or earlier.
%              It is normally thought of as a simulation of Hockey as a card game for two players, one representing each team.
%              In Hockey, points are scored by matching the card played by your opponent to create a "breakaway" and then also matching the opponent's following play to score.
%              These points are known as "goals" and the object is of course to score more goals than your opponent.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Program Variables
var x, y, button : int

var r : int := 0
var deck := "AAAA22223333444455556666777788889999TTTTJJJJQQQQKKKK"
var save : string


var messageTextNumber : int
var messageIdentifier : int

var font1 : int
font1 := Font.New ("couriernew:12")

% setscreen

setscreen ("graphics: max, max")


% Introduction

locate (1, 1)
put "Welcome to the Hockey Card Game!"
delay (3000)
locate (2, 1)
put "How to play: The players pick up the cards they are dealt, look at them, and play in turn. The first card is played by the non-dealer."

locate (3, 1)
put "A turn consists of playing one card from your hand face up to the centre of the table. "

locate (4, 1)
put "The cards played by both players are stacked in a single pile so that only the most recently played card is visible."

locate (5, 1)
put "If a card is played which matches the rank of the top card of the pile"

locate (6, 1)
put "(for example an 8 is played on an 8), this creates a breakaway for the person who played the matching card. "

locate (7, 1)
put "Also, any time that a Jack is played, this creates a breakaway for the player of the Jack. "

locate (8, 1)
put "If a player who creates a breakaway then matches the next card played by the opponent, the player scores a goal."

locate (9, 1)
put "A goal itself is not a breakaway. After a goal a new breakaway is needed before a new goal can be scored. "

locate (10, 1)
put "However, a breakaway can be created by matching the card used to score a goal. "

locate (11, 1)
delay (3000)
put "Ready to play?"
locate (12, 1)
delay (2000)
put "Press any button to continue..."
loop
    exit when hasch
end loop

cls

put "Starting in 3..."
delay (1000)
cls
put "Starting in 2..."
delay (1000)
cls
put "Starting in 1..."
delay (1000)
cls
put "Starting in 0..."
delay (1000)



cls



% Main code

    % Logic
        % Shuffling
            for i : 1 .. 10000
                randint (r, 1, 20)
                save := deck (1 .. r)
                deck := deck (r + 1 .. *)
                deck := deck (r + 1 .. *) + deck (1 .. r) + save
            end for

            cls
            put deck

    % Graphics
        % Layout

        % Cards
            % Player
                % Player Card #1
                    Draw.Box (5, 25, 105, 175, black)                                       
                % Player Card #2
                    Draw.Box (125, 25, 225, 175, black)                       
                % Player Card #3
                    Draw.Box (245, 25, 345, 175, black)
                % Player Card #4
                    Draw.Box (365, 25, 465, 175, black)
                % Player Card #5
                    Draw.Box (485, 25, 585, 175, black)
            % Opponent
                % Opponent Card #1
                    Draw.Box (5, 905, 105, 755, black)
                        Draw.Line (5, 905, 105, 755, black)
                        Draw.Line (5, 755, 105, 905, black)
                % Opponent Card #2
                    Draw.Box (125, 905, 225, 755, black)
                        Draw.Line (125, 905, 225, 755, black)
                        Draw.Line (125, 755, 225, 905, black)
                % Opponent Card #3
                    Draw.Box (245, 905, 345, 755, black)
                        Draw.Line (245, 905, 345, 755, black)
                        Draw.Line (245, 755, 345, 905, black)
                % Opponent Card #4
                    Draw.Box (365, 905, 465, 755, black)
                        Draw.Line (365, 905, 465, 755, black)
                        Draw.Line (365, 755, 465, 905, black)
                % Opponent Card #5
                    Draw.Box (485, 905, 585, 755, black)
                        Draw.Line (485, 905, 585, 755, black)
                        Draw.Line (485, 755, 585, 905, black)
                       
        % Random Message
            Draw.Box (1020, 920, 1260, 660, black)
         
       
           
           
    loop
      Font.Draw ("Tip: ", 1025, 895, font1, black)
           
       
        % Point system
   
        % mousewhere
loop
        mousewhere (x, y, button)
            locate ((maxrow - 1), (maxcol- 25))

            if button = 0 then
                put x : 4, "  ", y : 4, "  button up"
            else
                put x : 4, "  ", y : 4, "  button down"
            end if
   
     % random message text
    loop
      randint (messageTextNumber, 1, 5)
        if messageTextNumber = 1 then
            locate (2, 133)
            delay (100)
            put "Did you know?"
            locate (3, 129)
            put "             "
        elsif messageTextNumber = 2 then
            locate (2, 133)
            delay (100)
            put " "
            locate (3, 129)
            put "             "
        elsif messageTextNumber = 3 then
            locate (2, 133)
            delay (100)
            put "fhgf "
            locate (3, 129)
            put "             "
        elsif messageTextNumber = 4 then
            locate (2, 133)
            delay (100)
            put "uioipiopiop "
            locate (3, 129)
            put "            "
        elsif messageTextNumber = 5 then
            locate (2, 133)
            delay (100)
            put "v dfgfthtukhkffserf "
            locate (3, 129)
            put "            "
        end if   
        end loop
    end loop
end loop

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  [ 4 Posts ]
Jump to:   


Style:  
Search: