?? shape.cs
字號:
using System;
using System.Drawing;
namespace Employee
{
/// <summary>
/// Shape 的摘要說明。
/// </summary>
public class Shape
{
public Shape()
{
//
// TODO: 在此處添加構造函數邏輯
//
}
public Shape(int index)
{
Create(index);
}
private Block[] blockList;
private int indexDef;
private Point ptPosition;
private struct TETRIS
{
public int[,] def;
public int size;
}
private static TETRIS[] tetrisDef;
public static void InitTetrisDefine()
{
tetrisDef = new TETRIS[7];
/*
for (int i=0; i<7; i++)
{
for (int m=0; m<4; m++)
{
for (int n=0; n<4; n++)
{
tetrisDef[i].def[m,n] = 0;
}
}
}
*/
tetrisDef[0].def = new int[4,4];
tetrisDef[0].def[1,0] = 8; // 0800
tetrisDef[0].def[1,1] = 8; // 0800
tetrisDef[0].def[1,2] = 8; // 0800
tetrisDef[0].def[1,3] = 8; // 0800
tetrisDef[0].size = 4;
tetrisDef[1].def = new int[3,3];
tetrisDef[1].def[1,0] = 8; // 088
tetrisDef[1].def[1,1] = 8; // 080
tetrisDef[1].def[1,2] = 8; // 080
tetrisDef[1].def[2,0] = 8;
tetrisDef[1].size = 3;
tetrisDef[2].def = new int[3,3];
tetrisDef[2].def[1,0] = 8; // 880
tetrisDef[2].def[1,1] = 8; // 080
tetrisDef[2].def[1,2] = 8; // 080
tetrisDef[2].def[0,0] = 8;
tetrisDef[2].size = 3;
tetrisDef[3].def = new int[3,3];
tetrisDef[3].def[1,0] = 8; // 080
tetrisDef[3].def[0,1] = 8; // 888
tetrisDef[3].def[1,1] = 8; // 000
tetrisDef[3].def[2,1] = 8;
tetrisDef[3].size = 3;
tetrisDef[4].def = new int[3,3];
tetrisDef[4].def[0,0] = 8; // 880
tetrisDef[4].def[1,0] = 8; // 088
tetrisDef[4].def[1,1] = 8; // 000
tetrisDef[4].def[2,1] = 8;
tetrisDef[4].size = 3;
tetrisDef[5].def = new int[3,3];
tetrisDef[5].def[1,0] = 8; // 088
tetrisDef[5].def[2,0] = 8; // 880
tetrisDef[5].def[0,1] = 8; // 000
tetrisDef[5].def[1,1] = 8;
tetrisDef[5].size = 3;
tetrisDef[6].def = new int[2,2];
tetrisDef[6].def[0,0] = 8; // 88
tetrisDef[6].def[0,1] = 8; // 88
tetrisDef[6].def[1,0] = 8;
tetrisDef[6].def[1,1] = 8;
tetrisDef[6].size = 2;
}
public void Create(int index)
{
indexDef = index;
blockList = new Block[4];
int count = 0;
for (int i=0; i<tetrisDef[index].size; i++)
{
for (int j=0; j<tetrisDef[index].size; j++)
{
if (tetrisDef[index].def[i,j] != 0)
{
blockList[count] = new Block(index, i, j);
count++;
if (count > 4) return;
}
}
}
}
public void Copy(Shape s)
{
ptPosition = s.Position;
for (int i=0; i<4; i++)
{
blockList[i].Position = s.GetBlock(i).Position;
}
}
public Point Position
{
get
{
return ptPosition;
}
set
{
ptPosition = value;
}
}
public int IndexDef
{
get
{
return indexDef;
}
}
public void Draw(Graphics g)
{
Draw(g, false);
}
public void Draw(Graphics g, Size sz)
{
Point pt = new Point((sz.Width - tetrisDef[indexDef].size * Block.Size) / 2,
(sz.Height - tetrisDef[indexDef].size * Block.Size) / 2);
for (int i=0; i<blockList.GetLength(0); i++)
{
blockList[i].Draw(g, pt, false);
}
}
public void Draw(Graphics g, bool clear)
{
for (int i=0; i<blockList.GetLength(0); i++)
{
blockList[i].Draw(g, new Point(ptPosition.X * Block.Size, ptPosition.Y * Block.Size), clear);
}
}
public void Roate()
{
for (int i=0; i<blockList.GetLength(0); i++)
{
Point pt = blockList[i].Position;
int temp = pt.X;
pt.X = tetrisDef[indexDef].size - pt.Y - 1;
pt.Y = temp;
blockList[i].Position = pt;
}
}
public Block GetBlock(int index)
{
return blockList[index];
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -