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

Username:   Password: 
 RegisterRegister   
 Problems with my tetris game
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jason98wang




PostPosted: Sun Jan 15, 2017 12:14 pm   Post subject: RE:Problems with my tetris game

i tried running it but it keeps on showing error during grid
Sponsor
Sponsor
Sponsor
sponsor
jason98wang




PostPosted: Sun Jan 15, 2017 12:15 pm   Post subject: RE:Problems with my tetris game

based on your previous experience how many lines do you think it will take for me to do it? and how many hours?
jason98wang




PostPosted: Sun Jan 15, 2017 12:25 pm   Post subject: RE:Problems with my tetris game

var grid : array (0..9, 0..49) of boolean
whenever i type in this code it does not work it gives me a error
jason98wang




PostPosted: Sun Jan 15, 2017 1:18 pm   Post subject: RE:Problems with my tetris game

var grid : array 0 .. 9, 0 .. 49 of int
for x : 0 .. 9
for y : 0 .. 49
grid (x, y) := 0
end for
end for

%Making something fall down is easy:

var x := 5
var y := 50

loop
y -= 1
delay (500)
if y = 0 then
grid (x, y) := 1 %this spot is now full.
exit
end if
end loop

%checking for collisions is easy too!

x := 5
y := 50

loop
if grid (x, y - 1) = 0 then %check if square below is empty
y -= 1 %This is the same as y := y - 1
else
grid (x, y) := 1
exit
end if
delay (500)
end loop

%Look at how simple that code is! It's easy to read, it's easy to write! But we still have to draw everything! Fortunately, that's easy too!

procedure drawEverything

for x : 0 .. 9
for y : 0 .. 49
if grid (x, y) = 1 then
Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, red)
end if
end for
end for

end drawEverything

i have changed some of the code so now it runs but however everytime it runs, nothing shows up
Insectoid




PostPosted: Sun Jan 15, 2017 3:21 pm   Post subject: RE:Problems with my tetris game

Don't try to glue my code pieces together. That's not why I wrote them and it will not work. In fact, trying to glue pieces together like that will never work, so don't even try copy & pasting code from now on.

You are making no effort to understand the code I showed you. You need to understand it. Go back to the big post I wrote up earlier, and read through it slowly and carefully. Make sure you understand the code snippet I wrote before you move on to the next one. It isn't easy, there are no shortcuts. Don't even bother writing any code until you understand mine, because it will not work.

Quote:
based on your previous experience how many lines do you think it will take for me to do it? and how many hours?


I wouldn't plan on visiting friends after school for the next few days. This will take you a long time. The more shortcuts you try to take, the longer it will take. The sooner you start doing it right, the sooner you'll get it done.


Break the problem down into pieces. I think that was the first advice I gave you and the first advice you ignored. I don't know why you ignore it, it's good advice. I've been doing this for a long time now, so you can trust me when I say these things. Try to make a game where a single box falls on top of another box. That's one of the smallest 'pieces' of the Tetris program. If you can get that working, you're well on your way to making the rest of the game.
jason98wang




PostPosted: Sun Jan 15, 2017 4:33 pm   Post subject: RE:Problems with my tetris game

im looking at your code and i don't understand how this piece of code would makes the blocks fall. since its not redrawing the blocks or anything like that? so how would the program know to redraw the block? also isn't the only way to clear block by covering it up with the colour of the background?



%Making something fall down is easy:

var x := 5
var y := 50

loop
y -= 1
delay (500)
if y = 0 then
grid (x, y) := 1 %this spot is now full.
exit
end if
end loop
jason98wang




PostPosted: Sun Jan 15, 2017 5:58 pm   Post subject: RE:Problems with my tetris game

Also another part i don't really understand is everytime the block changes location how are you removing the previous block so it looks like the block is actually falling?
jason98wang




PostPosted: Sun Jan 15, 2017 6:52 pm   Post subject: RE:Problems with my tetris game

Also will i be using the stuff like view.update, view.set and etc? because i have no idea what they are and how to use them
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sun Jan 15, 2017 10:11 pm   Post subject: RE:Problems with my tetris game

Quote:
im looking at your code and i don't understand how this piece of code would makes the blocks fall.


It does make the blocks fall. It doesn't draw it, because it's not supposed to. It's just supposed to make the block fall. That's what it's doing. You need a different function to draw it, somewhere else.

Don't try to remove the previous block. That's hard. It's a lot easier to just erase EVERYTHING with cls, and then re-draw only the parts we want. This is why we separate the game code from the drawing code.

You won't be using View.Update, because it's just not worth worrying about right now.


Why don't you try to make one box land on top of another? That's easy. It's a lot better to start with easy problems before moving on to hard ones.
jason98wang




PostPosted: Mon Jan 16, 2017 7:46 am   Post subject: RE:Problems with my tetris game

Also drawing the blocks are you doing that by physically drawing the shapes?
jason98wang




PostPosted: Mon Jan 16, 2017 7:52 am   Post subject: RE:Problems with my tetris game

Also if you use CLS how would turing remember where the other blocks that have fallen are loaded?
jason98wang




PostPosted: Mon Jan 16, 2017 7:53 am   Post subject: RE:Problems with my tetris game

im not trying to copy but can you show me how the blocks are going to fall i really don't understand
jason98wang




PostPosted: Mon Jan 16, 2017 8:38 am   Post subject: RE:Problems with my tetris game

You say stacking 2 blocks on top of each other is easy, but I just tried it for 30 minutes and I couldn't get it. Can you show me how to do it so I can understand the concept.
jason98wang




PostPosted: Mon Jan 16, 2017 1:05 pm   Post subject: RE:Problems with my tetris game

if you do cls how are you gonna remember the location of the blocks that has fallen
jason98wang




PostPosted: Mon Jan 16, 2017 8:56 pm   Post subject: RE:Problems with my tetris game

setscreen ("graphics:300;600")
var grid : array 0 .. 10, 0 .. 20 of int
var dely : int
var turn : int
var blockType : int
var chars : array char of boolean
dely := 500
for x : 0 .. 10
for y : 0 .. 20
grid (x, y) := 0
end for
end for


%1 means block occupuy that positino
%0 means its an empty block
%Making blocks fall

var x := 10
var y := 60
turn := 1
var array_x : int := 10
var array_y : int := 20
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%All the procedures of drawing and the different shapes and different turns %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%L block%%%%%%%%%
procedure L_block_White
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 0)
Draw.FillBox (x * 10 + 60, y * 10, x * 10 + 90, y * 10 + 30, 0)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 0)
end L_block_White

procedure L_block


Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 42)
Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 42)
Draw.FillBox (x * 10 + 60, y * 10, x * 10 + 90, y * 10 + 30, 42)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 42)
end L_block

procedure L_block_turn_1
loop
loop
exit when grid (array_x, array_y - 1) = 1 or y = 3
cls
dely := 200
y := y - 1
put y
L_block
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
%Rotate
end if
if chars (KEY_RIGHT_ARROW) then
put x
if x < 21 then
x := x + 1
end if
end if
if chars (KEY_LEFT_ARROW) then
if x > 21 then
x := x - 1
end if
end if
if chars (KEY_DOWN_ARROW) then
dely := 50
end if

delay (dely)
View.Update
Time.Delay (5)
end loop
array_x := round (x / 30)
array_y := round (y / 30)


grid (array_x, array_y) := 1 %this spot is now full.
grid (array_x, array_y + 1) := 1
grid (array_x + 1, array_y + 1) := 1
grid (array_x + 2, array_y + 1) := 1
end loop

end L_block_turn_1

%%%%%%Z block%%%%%%%%%
procedure Z_block_White
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, white)
Draw.FillBox (x * 10 - 30, y * 10, x * 10, y * 10 + 30, white)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, white)
Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, white)
end Z_block_White

procedure Z_block
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, brightred)
Draw.FillBox (x * 10 - 30, y * 10, x * 10, y * 10 + 30, brightred)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, brightred)
Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, brightred)
end Z_block

%%%%%%%%%%%S block%%%%%%%%%%%%
procedure S_block_White
Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 0)
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 0)
Draw.FillBox (x * 10 - 30, y * 10 - 30, x * 10, y * 10, 0)
end S_block_White

procedure S_block
Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 10)
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 10)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 10)
Draw.FillBox (x * 10 - 30, y * 10 - 30, x * 10, y * 10, 10)
end S_block

%%%%%%%%J block%%%%%%%%%%%%%
procedure J_block_White
Draw.FillBox (x * 10 - 30, y * 10, x * 10, y * 10 + 30, 0)
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 0)
Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, 0)
end J_block_White

procedure J_block
Draw.FillBox (x * 10 - 30, y * 10, x * 10, y * 10 + 30, 9)
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 9)
Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 9)
Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, 9)
end J_block

%%%%%%%I block%%%%%%%%%%
procedure I_block_White
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 0)
Draw.FillBox (x * 10, y * 10 - 60, x * 10 + 30, y * 10 - 30, 0)
Draw.FillBox (x * 10, y * 10 - 90, x * 10 + 30, y * 10 - 60, 0)
end I_block_White

procedure I_block
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 11)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 11)
Draw.FillBox (x * 10, y * 10 - 60, x * 10 + 30, y * 10 - 30, 11)
Draw.FillBox (x * 10, y * 10 - 90, x * 10 + 30, y * 10 - 60, 11)
end I_block

%%%%%% O block%%%%%%%%%%
procedure O_block_White
Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 0)
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, 0)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 0)
end O_block_White

procedure O_block
Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 14)
Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 14)
Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, 14)
Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 14)
end O_block

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%End of procedures%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

loop
array_x := 10
array_y := 20
x := 10
y := 60
blockType := Rand.Int (1, 6)
if blockType = 1 then
loop
%put array_y
exit when grid (array_x, array_y - 1) = 1 or y = 3
L_block_White
dely := 200
y := y - 1
L_block
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
%Rotate
elsif chars (KEY_RIGHT_ARROW) then
if x < 21 then
x := x + 1
end if
elsif chars (KEY_LEFT_ARROW) then
if x > 0 then
x := x - 1
end if
elsif chars (KEY_DOWN_ARROW) then
dely := 50
end if

delay (dely)
View.Update
Time.Delay (5)
array_x := round (x / 30)
array_y := round (y / 6)
end loop

grid (array_x, array_y) := 1 %this spot is now full.
grid (array_x, array_y + 1) := 1
grid (array_x + 1, array_y + 1) := 1
grid (array_x + 2, array_y + 1) := 1

elsif blockType = 2 then
%put array_y
loop
exit when grid (array_x, array_y - 1) = 1 or y = 3
Z_block_White
dely := 200
y := y - 1
Z_block
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
%Rotate
elsif chars (KEY_RIGHT_ARROW) then

if x < 24 then
x := x + 1
end if
elsif chars (KEY_LEFT_ARROW) then

if x > 3 then
x := x - 1
end if
elsif chars (KEY_DOWN_ARROW) then
dely := 50
end if

delay (dely)
View.Update
Time.Delay (5)
array_x := round (x / 30)
array_y := round (y / 6)
end loop

grid (array_x, array_y) := 1 %this spot is now full.
grid (array_x, array_y + 1) := 1
grid (array_x + 1, array_y + 1) := 1
grid (array_x + 2, array_y + 1) := 1

elsif blockType = 3 then
%put array_y
loop
exit when grid (array_x, array_y - 1) = 1 or y = 3
S_block_White
dely := 200
y := y - 1
S_block
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
%Rotate
elsif chars (KEY_RIGHT_ARROW) then

if x < 24 then
x := x + 1
end if
elsif chars (KEY_LEFT_ARROW) then

if x > 3 and array_x + 1 = 1 then
x := x - 1
end if
elsif chars (KEY_DOWN_ARROW) then
dely := 50
end if

delay (dely)
View.Update
Time.Delay (5)
array_x := round (x / 30)
array_y := round (y / 6)
end loop

grid (array_x, array_y) := 1 %this spot is now full.
grid (array_x, array_y + 1) := 1
grid (array_x + 1, array_y + 1) := 1
grid (array_x + 2, array_y + 1) := 1
elsif blockType = 4 then
%put array_y
loop
exit when grid (array_x, array_y - 1) = 1 or y = 3
J_block_White
dely := 200
y := y - 1
J_block
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
%Rotate
elsif chars (KEY_RIGHT_ARROW) then

if x < 24 then
x := x + 1
end if
elsif chars (KEY_LEFT_ARROW) then

if x > 3 and array_x + 1 = 1 then
x := x - 1
end if
elsif chars (KEY_DOWN_ARROW) then
dely := 50
end if

delay (dely)
View.Update
Time.Delay (5)
array_x := round (x / 30)
array_y := round (y / 6)
end loop

grid (array_x, array_y) := 1 %this spot is now full.
grid (array_x, array_y + 1) := 1
grid (array_x + 1, array_y + 1) := 1
grid (array_x + 2, array_y + 1) := 1
elsif blockType = 5 then
loop
exit when grid (array_x, array_y - 1) = 1 or y = 9
I_block_White
dely := 200
y := y - 1
I_block
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
%Rotate
elsif chars (KEY_RIGHT_ARROW) then

if x < 27 then
x := x + 1
end if
elsif chars (KEY_LEFT_ARROW) then

if x > 0 and array_x + 1 = 1 then
x := x - 1
end if
elsif chars (KEY_DOWN_ARROW) then
dely := 50
end if

delay (dely)
View.Update
Time.Delay (5)
array_x := round (x / 30)
array_y := round (y / 6)
end loop

grid (array_x, array_y) := 1 %this spot is now full.
grid (array_x, array_y + 1) := 1
grid (array_x + 1, array_y + 1) := 1
grid (array_x + 2, array_y + 1) := 1
elsif blockType = 6 then

loop
put array_y
exit when grid (array_x, array_y - 1) = 1 or y = 3
O_block_White
dely := 200
y := y - 1
O_block
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
%Rotate
elsif chars (KEY_RIGHT_ARROW) then

if x < 24 then
x := x + 1
end if
elsif chars (KEY_LEFT_ARROW) then

if x > 0 then
x := x - 1
end if
elsif chars (KEY_DOWN_ARROW) then
dely := 50
end if

delay (dely)
View.Update
Time.Delay (5)
array_x := round (x / 15)
array_y := round (y / 3)
end loop

grid (array_x, array_y) := 1 %this spot is now full.
grid (array_x, array_y + 1) := 1
grid (array_x + 1, array_y + 1) := 1
grid (array_x + 2, array_y + 1) := 1
end if

end loop
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 2 of 3  [ 36 Posts ]
Goto page Previous  1, 2, 3  Next
Jump to:   


Style:  
Search: