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

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




PostPosted: Fri Jan 20, 2012 10:38 am   Post subject: I need Help

So, I have to do this for our final assignment, but I'm having trouble getting the keyboard commands work. The code is as following:

code:

setscreen ('graphics')

% Create variables for player names
var p1 : string
var p2 : string

% We need variables to keep score
var score1, score2 : int

% Variables to choose a box from one to nine
var key1, key2 : char

% Variable to check if 'q' has been pressed
var que : char


% Welcome screen
put "TIC TAC TOE"
put skip
put "Player 1, Enter your name: " ..
get p1
put skip
put "Player 2, Enter your name: " ..
get p2
delay (900)
cls
put skip
put skip
put skip
put skip
put skip
put "                            Press any key to continue"

% To check if a start key has been pressed
var reply : string (1)
getch (reply)
cls

% 1 is in top left corner and 9 is in bottom right corner
put "Box 1 is located in the top left corner and Box 9 is"
put "located in the bottom right corner."
put skip
put "The numbers progress from left to right."
delay (10000)
cls

% Draw Tic Tac Toe Board
Draw.ThickLine (maxx div 3, maxy, maxx div 3, 0, 3, 20)
Draw.ThickLine ((maxx div 3) * 2, maxy, (maxx div 3) * 2, 0, 3, 20)
Draw.ThickLine (0, maxy div 3, maxx, maxy div 3, 3, 20)
Draw.ThickLine (0, (maxy div 3) * 2, maxx, (maxy div 3) * 2, 3, 20)

% Ask Player 1 to choose a number from 1 - 9
put p1, " , pick a number from 1 to 9"

if (hasch) then
    key1 := getchar

    if (key1 = '1') then
        Draw.ThickLine (0, maxy, (maxx div 3), (maxy div 3) * 2, 3, red)
        Draw.ThickLine (0, (maxx div 3) * 2, (maxx div 3), 0, 3, red)
    end if

end if
[/quote]
Sponsor
Sponsor
Sponsor
sponsor
tedbean




PostPosted: Fri Jan 20, 2012 10:57 am   Post subject: Re: I need Help

Q: How can we find out errors in this code? if any.

Sorry I have absolutely no clue. Sad
Insectoid




PostPosted: Fri Jan 20, 2012 12:17 pm   Post subject: RE:I need Help

code:
if (hasch) then


This will only execute if a key has been pressed since the last get. The program will typically finish executing far, far faster than you can hit a key. You need to keep checking over and over again to catch the keystrokes as they occur.
Alex C.




PostPosted: Fri Jan 20, 2012 12:39 pm   Post subject: RE:I need Help

basicly loop your program, and exit that loop when you get that key...
SimmiR




PostPosted: Mon Jan 23, 2012 9:26 am   Post subject: RE:I need Help

Thank to all of you, you were a great help Smile
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: