A pretty crude snake!
Author |
Message |
A.J
![](http://compsci.ca/v3/uploads/user_avatars/119833057151651227b0d87.gif)
|
Posted: Mon Mar 10, 2008 7:39 pm Post subject: A pretty crude snake! |
|
|
yep, pretty crude
There are some .wav files you need for this game. how do i attach them?
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Snake.t |
Filesize: |
6.8 KB |
Downloaded: |
189 Time(s) |
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
snake.txt |
Filesize: |
2.08 KB |
Downloaded: |
142 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
A.J
![](http://compsci.ca/v3/uploads/user_avatars/119833057151651227b0d87.gif)
|
Posted: Mon Mar 10, 2008 8:03 pm Post subject: Re: A pretty crude snake! |
|
|
here goes nothing!
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Snake.zip |
Filesize: |
2.69 MB |
Downloaded: |
94 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: 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?
|
|
|
|
|
![](images/spacer.gif) |
Saad
![](http://compsci.ca/v3/uploads/user_avatars/182387547249e7ebb91fb8a.png)
|
Posted: 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
|
|
|
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: 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).
|
|
|
|
|
![](images/spacer.gif) |
A.J
![](http://compsci.ca/v3/uploads/user_avatars/119833057151651227b0d87.gif)
|
Posted: 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 )
here is the updated version!!
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Snake.zip |
Filesize: |
2.69 MB |
Downloaded: |
105 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
|
|