Home > other >  Lua how to achieve the rotation of the table?
Lua how to achieve the rotation of the table?

Time:09-28

The table structure
- a square game
Self. Blocktype={
{
{1, 1, 0},
{0, 1, 1}
},
{
{1, 1},
{1, 1}
},
{
{1, 0},
{1, 0},
{1, 1}
},
{
{0, 1, 0},
{1, 1, 1}
}
}
- the rotation of the cube
- oblong rotating
The function Login: Rotation (index)
The self. The count=self. Count the or 0

The local a={}
Rotate it 90 degree -
If (self. Count==0) then
For I=1, # self. Blocktype [index] do
A [I]={}
For j=1, # self. Blocktype [index] [I] do
A [I] [j]=self. Blocktype [index] [2 - j] [I]
End
End
The self. The count=self. Count + 1
Return a
End
The local b={}
Rotate it 180 degree -
If (self. Count==1) then
For I=1, # self. Blocktype [index] do
[I] b={}
For j=1, # self. Blocktype [index] [j] do
B [I] [j].=self blocktype [index] [2 - I] [3 - j]
End
End
The self. The count=self. Count + 1
Return b
End
The local c={}
Rotate it 270 degree -
If (self. Count==2) then
For I=1, # self. Blocktype [index] do
[I] c={}
For j=1, # self. Blocktype [index] [j] do
C [I] [j].=self blocktype [j] [3 -] I
End
End
The self. The count=self. Count + 1
Return c
End
If (self. Count==3) then
Return the self. Blocktype
End
End
This has been an error don't know how to change

CodePudding user response:

Tetris?
Your code is too messy, just looked at it and found that, if I don't want to wrong, your index is a problem for certain, lua index began from 1, you inside some of the 2 - I, basic that cross-border,
With a relatively straightforward and, as well as robust approach, is to define the square of the four directions save all forms of performance, and then only for square type ID, the position of the square (which can be of block (0, 0) in a position to think the position of the square), as well as the square of the steering can describe the current state of the,
Finally, poking fun at once, high school students, college students' programming assignments will write so,
  • Related