// if user has inputed, then do the responding work
 public void userHasInput(string userInput)
 {
     if (userInput.Equals(MoveLeftCommand))
     {
         tm.setState(tm.MoveLeftState);
         tm.MoveLeft(tv.GetNowBlock());
     }
     else if (userInput.Equals(MoveLeftCommand))
     {
         tm.setState(tm.MoveRightState);
         tm.MoveRight(tv.GetNowBlock(), tv.GetAllBlocks());
     }
     else if (userInput.Equals(MoveDownFastCommand))
     {
         tm.setState(tm.MoveDownFastState);
         tm.DropDownFast(tv.GetNowBlock(), tv.GetAllBlocks());
     }
     else if (userInput.Equals(RotateCommand))
     {
         tm.setState(tm.RotateState);
         tm.Rotate(tv.GetNowBlock(), tv.GetAllBlocks());
     }
 }
示例#2
0
 // move the block left
 public void MoveLeft(Blocks nowBlock)
 {
     if (nowBlock != null)
     {
         PictureBox[,] allBlocks = tv.GetAllBlocks();
         Point[]              nowBlockIndex    = nowBlock.GetAllCubesPosition();
         PictureBox[]         nowBlockPosition = nowBlock.GetAllCubes();
         System.Drawing.Color nowColor         = nowBlockPosition[0].BackColor;
         Panel panelOnShow = tv.GetPanel1();
         if (nowBlock.GetNowState() != States.Stop)
         {
             for (int i = 0; i < nowBlockIndex.Length; i++)
             {
                 //avoid to move out of range
                 int x = nowBlockIndex[i].Getx();
                 if (x <= 0)
                 {
                     throw new Exception();
                 }
                 int y = nowBlockIndex[i].Gety();
                 //avoid to touch the existed block
                 if (allBlocks[y, x - 1].BackColor != panelOnShow.BackColor && allBlocks[y, x - 1].BackColor != allBlocks[y, x].BackColor && !nowBlockPosition.Contains <PictureBox>(allBlocks[y, x - 1]))
                 {
                     throw new Exception();
                 }
             }
             //set the color of origin block to background color
             //compute the new position of block
             for (int i = 0; i < nowBlockIndex.Length; i++)
             {
                 nowBlockPosition[i].BackColor = panelOnShow.BackColor;
                 nowBlockIndex[i].Setx(nowBlockIndex[i].Getx() - 1);
             }
             //modify position of block
             for (int i = 0; i < nowBlockPosition.Length; i++)
             {
                 if (nowBlockIndex[i].Gety() < 0 || nowBlockIndex[i].Gety() > 12 || nowBlockIndex[i].Getx() < 0 || nowBlockIndex[i].Getx() > 8)
                 {
                     throw new Exception();
                 }
                 nowBlockPosition[i]           = allBlocks[nowBlockIndex[i].Gety(), nowBlockIndex[i].Getx()];
                 nowBlockPosition[i].BackColor = nowColor;
             }
             // set new info. in every store unit
             nowBlock.SetAllCubes(nowBlockPosition);
             nowBlock.SetCenter(nowBlockPosition[1]);
         }
     }
 }