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

Username:   Password: 
 RegisterRegister   
 Hangman
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Amarylis




PostPosted: Tue May 01, 2012 5:33 pm   Post subject: Hangman

Since I have now handed this in, I'm allowed to share the code without being accused of plagiarism.

It's really just a simple game of hangman with 2 themes, and the option for you to make your own themes. Works with letters of any length, provided that it doesn't go off the screen.


Here you go~



hangman.rar
 Description:
All necessary files to play this game of hangman

Download
 Filename:  hangman.rar
 Filesize:  673.39 KB
 Downloaded:  463 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
chipanpriest




PostPosted: Wed Oct 31, 2012 7:06 pm   Post subject: Re: Hangman

When I ran your program, I created some words. When I looked in the containing folder, I found heythere.WDBNK. Can Turing make a type of file and read from it? I thought turing could only support .txt files. So could you type:

Turing:

var f : int
open : f,"heythere.sdfkjsfk", get, mod, seek, put
put : f , "omgdoesthiswork?"
close : f


Would it work and be able to read from those files?
TerranceN




PostPosted: Wed Oct 31, 2012 11:17 pm   Post subject: RE:Hangman

You can open whatever files you want in turing. Using read and write you can read/write files in binary, and using char and int you can read/write in increments of 1 and 4 bytes at a time. Just remember that files are just data, there's nothing magical about supporting a file type other than learning its specification. As an example, I just made this bmp reader:

Turing:

% Simple bitmap reader

% I skip a lot of information that's probably important.
% If you really want to implement this correctly, read over the
% bitmap specification: http://en.wikipedia.org/wiki/BMP_file_format

var stream : int

% temporary values for reading
var c : char      % this will read one byte
var intVal : int  % this will read 4 bytes

var width : int
var height : int

var offset : int


open : stream, "img.bmp", read

put "Header information:"
% the first 14 bytes are bmp file information

% make sure the file is bmp by checking first two bytes
% should be 0x42 0x4D in hex or 66 77 in decimal
read: stream, c
if ord(c) ~= 66 then
    quit
end if
put ord(c), " "..

read: stream, c
if ord(c) ~= 77 then
    quit
end if
put ord(c), " "..

for i : 1 .. 8
    read : stream, c
    put ord (c), " " ..
end for

% the last 4 of this section is an offset to
% where the pixel values are
read : stream, offset
put offset, " " ..

% DIB header size
read : stream, intVal

% width/height
read : stream, width
read : stream, height

% now skip ahead to the pixels
for i : 1 .. offset - 26 % (14 byte header
                         %  + 4 byte DIB header size
                         %  + 8 bytes for width/height)
    read : stream, c
    put ord (c), " " ..
end for

% draw the pixels
for y : 0 .. height - 1
    for x : 0 .. width - 1
        var r, g, b : int
        read : stream, c
        b := ord (c)
        read : stream, c
        g := ord (c)
        read : stream, c
        r := ord (c)
        drawdot (x, y, RGB.AddColor (r / 255, g / 255, b / 255))
    end for
   
    % each row is padded so that it is a multiple of four bytes
    % we need to remove that padding to get to the next row
    for x : 1 .. (4 - ((width * 3) mod 4))
        read : stream, c
    end for
end for
close : stream
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: