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

Username:   Password: 
 RegisterRegister   
 A pretty crude snake!
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
A.J




PostPosted: Mon Mar 10, 2008 7:39 pm   Post subject: A pretty crude snake!

yep, pretty crude Very Happy
There are some .wav files you need for this game. how do i attach them?



Snake.t
 Description:

Download
 Filename:  Snake.t
 Filesize:  6.8 KB
 Downloaded:  189 Time(s)


snake.txt
 Description:

Download
 Filename:  snake.txt
 Filesize:  2.08 KB
 Downloaded:  142 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Mon Mar 10, 2008 7:49 pm   Post subject: RE:A pretty crude snake!

Put all of the required files into one folder, compress, and then upload.
A.J




PostPosted: Mon Mar 10, 2008 8:03 pm   Post subject: Re: A pretty crude snake!

here goes nothing!


Snake.zip
 Description:

Download
 Filename:  Snake.zip
 Filesize:  2.69 MB
 Downloaded:  94 Time(s)

CodeMonkey2000




PostPosted: Mon Mar 10, 2008 8:10 pm   Post subject: RE:A pretty crude snake!

That's pretty good. 280 lines of code seems too much though, think you can reduce it to 150? And what is it with all the snake games recently?
Saad




PostPosted: Mon Mar 10, 2008 8:25 pm   Post subject: Re: A pretty crude snake!

Good game, but I have a few problems with the coding

Turing:

for i : 0 .. r - 1
        for j : 0 .. c - 1
            if square (i, j) = "I" then
                Draw.FillBox (i * 20, j * 20, i * 20 + 20, j * 20 + 20, red)
            else
                Draw.FillBox (i * 20, j * 20, i * 20 + 20, j * 20 + 20, black)
            end if
        end for
    end for


Hmm, if i is for row then why is it being used as an x-cooridnate?

But more comments that relate to the actual coding technique

1. Space it out, it will make the code much easier to read. White spaces are helpful especially when its comes to larger amount of codes since they allow you to visually see blocks of code.
2. Follow one type of naming convention and make the variable names usefull.

Turing:

var stream, r, c, x, d, d2 : int  %% What do have of these variables do?, one letter is not enough to find out the purpose of the variable
var displacementX, displacementY := 0  %% Good use of variable naming, athough why not use the coord type?
var s : string %% Again what is s for?
var lost, bpoint, fin, used : boolean  %% Why did you go back to another naming convention?



3. Some redundant code
Turing:

if square (i - 1, j - 1) = "1" then
            square (i - 1, j - 1) := "N"
            S (1).x := i - 1
            S (1).y := j - 1
        end if
        if square (i - 1, j - 1) = "2" then
            square (i - 1, j - 1) := "N"
            S (2).x := i - 1
            S (2).y := j - 1
        end if
        if square (i - 1, j - 1) = "3" then
            square (i - 1, j - 1) := "N"
            S (3).x := i - 1
            S (3).y := j - 1
        end if
        if square (i - 1, j - 1) = "4" then
            square (i - 1, j - 1) := "N"
            S (4).x := i - 1
            S (4).y := j - 1
        end if
        if square (i - 1, j - 1) = "5" then
            square (i - 1, j - 1) := "N"
            S (5).x := i - 1
            S (5).y := j - 1
        end if
        if square (i - 1, j - 1) = "6" then
            square (i - 1, j - 1) := "N"
            S (6).x := i - 1
            S (6).y := j - 1
        end if
        if square (i - 1, j - 1) = "7" then
            square (i - 1, j - 1) := "N"
            S (7).x := i - 1
            S (7).y := j - 1
        end if


This could be shortened to one for loop

4. Could better use functions and procedures

- For example loading the map should be a function allowing you to load up a map with a single call

Sorry if I seem harsh, but good coding technique should always be used


Saad
CodeMonkey2000




PostPosted: Mon Mar 10, 2008 8:37 pm   Post subject: RE:A pretty crude snake!

saad, I wanted him to figure that out himself. Anyway there are other places where you can factor down some code. (One big example is the convention you use to read you map, integer values are useful).
A.J




PostPosted: Mon Mar 10, 2008 10:44 pm   Post subject: Re: A pretty crude snake!

thnx for your comments guys!
here's a little better version (oh, and saad, I improved the naming, and I am going to return the favor by critiquing YOUR code at school Very Happy)
here is the updated version!!



Snake.zip
 Description:

Download
 Filename:  Snake.zip
 Filesize:  2.69 MB
 Downloaded:  105 Time(s)

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


Style:  
Search: