Computer Science Canada

Tetris

Author:  rollerdude [ Thu Oct 28, 2004 4:31 pm ]
Post subject:  Tetris

Ok
so here's my tetris code, so far, it's very basic and the peices still squash each other
[code]
%TETRIS
setscreen ("nocursor,noecho,graphics:500;500")
proc block (x, y, clr100 : int) %build peices
Draw.FillBox (x, y, x + 10, y + 10, clr100)
end block
proc straight (a, b, clr, pos : int)
if pos = 1 or pos = 3 then
block (a, b, clr)
block (a + 10, b, clr)
block (a + 20, b, clr)
block (a + 30, b, clr)
elsif pos = 2 or pos = 4 then
block (a, b, clr)
block (a, b + 10, clr)
block (a, b + 20, clr)
block (a, b + 30, clr)
end if
end straight
proc t (e, f, clr3, pos : int)
if pos = 3 then
block (e, f, clr3)
block (e, f + 10, clr3)
block (e, f + 20, clr3)
block (e + 10, f + 10, clr3)
elsif pos = 1 then
block (e + 10, f, clr3)
block (e, f + 10, clr3)
block (e + 10, f + 10, clr3)
block (e + 10, f + 20, clr3)
elsif pos = 2 then
block (e, f + 10, clr3)
block (e + 10, f, clr3)
block (e + 10, f + 10, clr3)
block (e + 20, f + 10, clr3)
elsif pos = 4 then
block (e, f, clr3)
block (e + 10, f, clr3)
block (e + 20, f, clr3)
block (e + 10, f + 10, clr3)
end if
end t
proc bl (m, n, clr4, pos : int)
if pos = 1 then
block (m, n, clr4)
block (m, n + 10, clr4)
block (m, n + 20, clr4)
block (m + 10, n + 20, clr4)
elsif pos = 3 then
block (m, n, clr4)
block (m + 10, n, clr4)
block (m + 10, n + 10, clr4)
block (m + 10, n + 20, clr4)
elsif pos = 2 then
block (m, n + 10, clr4)
block (m + 10, n + 10, clr4)
block (m + 20, n + 10, clr4)
block (m + 20, n, clr4)
elsif pos = 4 then
block (m, n, clr4)
block (m + 10, n, clr4)
block (m + 20, n, clr4)
block (m, n + 10, clr4)
end if
end bl
proc fl (u, v, clr11, pos : int)
if pos = 1 then
block (u + 10, v, clr11)
block (u + 10, v + 10, clr11)
block (u + 10, v + 20, clr11)
block (u, v + 20, clr11)
elsif pos = 3 then
block (u + 10, v, clr11)
block (u, v + 10, clr11)
block (u, v + 0, clr11)
block (u, v + 20, clr11)
elsif pos = 2 then
block (u, v, clr11)
block (u + 10, v, clr11)
block (u + 20, v, clr11)
block (u + 20, v + 10, clr11)
elsif pos = 4 then
block (u, v + 10, clr11)
block (u + 10, v + 10, clr11)
block (u + 20, v + 10, clr11)
block (u, v, clr11)
end if
end fl
proc bloc (aa, bb, clr15 : int)
block (aa, bb, clr15)
block (aa, bb + 10, clr15)
block (aa + 10, bb, clr15)
block (aa + 10, bb + 10, clr15)
end bloc
proc fz (cc, dd, clr16,pos : int)
if pos = 1 or pos = 3 then
block (cc, dd, clr16)
block (cc + 10, dd, clr16)
block (cc + 10, dd + 10, clr16)
block (cc + 20, dd + 10, clr16)
elsif pos = 2 or pos = 4 then
block (cc, dd + 10,clr16)
block (cc, dd + 20,clr16)
block (cc + 10, dd,clr16)
block (cc + 10, dd + 10,clr16)
end if
end fz
var switch : int := 1
var ch : string (1) := " "
var oldch : string (1) := "a"
var row, col : int
row := 500 div 2 - 25
col := 500 - 50
loop
var NextPeice : int := Rand.Int (1, 6)
%var NextPeice : int := 2
loop
switch := 1
row := 500 div 2 - 25
for decreasing i : 500 .. 0 by 10
ch := oldch
if hasch then
getch (ch)
end if
if switch = 5 then
switch := 1
end if
if ord (ch) = 32 then
switch += 1
end if
if ord (ch) = 205 then
row := row + 10
elsif ord (ch) = 203 then
row := row - 10
else
end if
if NextPeice = 1 then
bl (row, i, 1, switch)
delay (100)
bl (row, i, white, switch)
elsif NextPeice = 2 then
t (row, i, 2, switch)
delay (100)
t (row, i, white, switch)
elsif NextPeice = 3 then
straight (row, i, 3, switch)
delay (100)
straight (row, i, white, switch)
elsif NextPeice = 4 then
fl (row, i, 4, switch)
delay (100)
fl (row, i, white, switch)
elsif NextPeice = 5 then
bloc (row, i, 5)
delay (100)
bloc (row, i, white)
elsif NextPeice = 6 then
fz (row, i, 6, switch)
delay (100)
fz (row, i, white, switch)
end if
end for
if NextPeice = 1 then
bl (row, 0, 1, switch)
elsif NextPeice = 2 then
t (row, 0, 2, switch)
elsif NextPeice = 3 then
straight (row, 0, 3, switch)
elsif NextPeice = 4 then
fl (row, 0, 4, switch)
elsif NextPeice = 5 then
bloc (row, 0, 5)
elsif NextPeice = 6 then
fz (row, 0, 6, switch)
end if
exit
end loop
end loop
[/code]
tell me what you think

Author:  rollerdude [ Thu Oct 28, 2004 4:32 pm ]
Post subject:  tetris

ok so, now that you tried, it, can you tell me how to make so the peices can't go off the screen
and how to make them not sqish each other?

Author:  Andy [ Thu Oct 28, 2004 5:42 pm ]
Post subject: 

make walls on all four sides... and set a statement where if u cant go past a wall...

here is one that i made a while back...
http://compsci.ca/v2/viewtopic.php?p=7751#7751

yea that wasnt too good... te best way to do it is treat it as a matrix and just keep on multiplying the matrix by some multiplier

Author:  rollerdude [ Thu Oct 28, 2004 5:48 pm ]
Post subject: 

thanx but, i'm using turing 3.1.1
so veiw.update and stuff like doesn't work

thanx anyway

Author:  Andy [ Thu Oct 28, 2004 7:32 pm ]
Post subject: 

haha, that wasnt an invitation to copy my code.. it was so u can see what i did and make your own

Author:  gigaman [ Thu Oct 28, 2004 9:24 pm ]
Post subject: 

I would reccomend that you use a random integer in an if statement so that each number calls a different piece. each piece a function

Author:  rollerdude [ Fri Oct 29, 2004 12:35 pm ]
Post subject:  tetris

Quote:

haha, that wasnt an invitation to copy my code.. it was so u can see what i did and make your own

either way, can't use Veiw.Update so i don't no what it does(nor key up arrow,ect.)

Author:  Tony [ Fri Oct 29, 2004 4:42 pm ]
Post subject:  Re: tetris

[quote="rollerdude"
either way, can't use Veiw.Update[/quote]
View.Update updates the view... you'd think the function name would imply its purpose Confused But that's just graphics stuff, don't worry about it.

Author:  coolmanjess [ Thu Jun 02, 2005 10:58 am ]
Post subject: 

hey rollerdude, what does the switch statement mean.....and im trying to figure out a way to stack them...i found out how to stop them at the wall n stuff...heres the code

if ord (ch) = 205 and row < wall (i used 300)
then
row := row + 10
elsif ord (ch) = 203 and row > 0 and row < 300
then
row := row - 10

there ya go

Author:  wadeshaqdunk [ Thu Jun 02, 2005 3:38 pm ]
Post subject:  C'Mon

/*
How about some user input???
*/
if hasch then
getch (ch)
if ch = chr (203) then
Pic.Rotate (Pic.FileNew ("block.bmp), 1, 1, 90)
elsif ch = chr (205) then
%Just rotate the block the other way
%You actually have to have

Author:  coolmanjess [ Fri Jun 03, 2005 9:35 am ]
Post subject: 

ya thats a pretty good idea too....alot easier definetly, but how would u get them to stack....like if one block is full then dont drop to bottom...but what would be the code....and for getting rid of the lines after their filled up....i have a couple of classes left before my isu is done and thats all i need to finish up

Author:  coolmanjess [ Fri Jun 03, 2005 9:36 am ]
Post subject: 

ya thats a pretty good idea too....alot easier definetly, but how would u get them to stack....like if one block is full then dont drop to bottom...but what would be the code....and for getting rid of the lines after their filled up....i have a couple of classes left before my isu is done and thats all i need to finish up

Author:  coolmanjess [ Fri Jun 03, 2005 9:37 am ]
Post subject: 

ya thats a pretty good idea too....alot easier definetly, but how would u get them to stack....like if one block is full then dont drop to bottom...but what would be the code....and for getting rid of the lines after their filled up....i have a couple of classes left before my isu is done and thats all i need to finish up

Author:  coolmanjess [ Fri Jun 03, 2005 10:25 am ]
Post subject: 

sorry about that, spam = accident

Author:  lzbravo [ Fri Jun 10, 2005 7:02 pm ]
Post subject: 

the game isn't bad but you should put instructions and also slow the gmae down put more detail


: