I am trying to write a tetris clone, and after some research, I came across an example that uses small user controls to form a block and a larger user control that contains a grid.
Everything that I wrote seems to work very well (blocks are generated and placed in the grid, I can even place them somewhere else if I change the code), but I can not make the blocks block move while the program is running. In this example, I use this by changing the property of control.lefteach of the blocks. I tried this, debugged it, and until the property changes, the block does not move.
I searched for about 4 hours. I am a beginner programmer, so I know that this is probably something stupid, but I can not find what it is.
Here are the methods I wrote:
public void MoveRight()
{
blok.MoveBlock("x", 1);
}
public void MoveBlock(string pos, int Amount)
{
if (pos == "x")
{
for (int i = 0; i < this.Shape().Count; i++)
{
((Blokje)this.Shape()[i]).MoveSide(1);
}
}
if (pos == "y")
{
for (int i = 0; i < this.Shape().Count; i++)
{
((Blokje)this.Shape()[i]).MoveDown(1);
}
}
public void MoveSide(int Step)
{
this.Left += (Step * 20);
}
The form is actually an arraylist that contains only 4 blocks. Block.cs is a partial class, as this is the code behind the usercontrol, which is a small square, Shape.cs makes shapes out of blocks, and tetrisgame only gallological
Keypress Event:
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if (e.KeyChar == 'q')
{
if (!paused)
{
Game.MoveLeft();
}
}
else if (e.KeyChar == 'd')
{
if (!paused)
{
Game.MoveRight();
}
}
else if (e.KeyChar == 'p')
{
if (paused)
{
tmrGame.Start();
}
else
{
tmrGame.Stop();
}
}
else if (e.KeyChar == 'z')
{
if (!paused)
{
Game.Rotate();
}
}
else if (e.KeyChar == 'h')
{
Help.Show();
}
else if (e.KeyChar == 'f')
{
}
else if (e.KeyChar == 's')
{
if (!paused)
{
Game.Drop();
}
}
}
catch
{
}
}
source
share