最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于C#實(shí)現(xiàn)俄羅斯方塊游戲

 更新時(shí)間:2017年06月06日 11:22:04   作者:默默地EEer  
這篇文章主要為大家詳細(xì)介紹了基于C#實(shí)現(xiàn)俄羅斯方塊游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

最近在看C#,寫了一個(gè)很水的方塊游戲練手。

代碼:

namespace game
{
 class Square
 {
 public Square()
 {
 state = 0;
 positionY = 0;
 positionX = 0;
 }
 public Square(int InitShapeCnt, int InitState)
 {
 state = InitState;
 positionY = 0;
 positionX = 0;
 InitShape(InitShapeCnt);


 }
 public void InitShape(int ShapeCnt)
 {
 if (ShapeCnt > 6 || ShapeCnt < 0)
 return;
 else
 {
 switch (ShapeCnt)
 {
  case (0):
  Shape = LeftLShape;
  break;
  case (1):
  Shape = RightLShape;
  break;
  case (2):
  Shape = RightZShape;
  break;
  case (3):
  Shape = LeftZShape;
  break;
  case (4):
  Shape = lShape;
  break;
  case (5):
  Shape = TuShape;
  break;
  case (6):
  Shape = TianShape;
  break;
  default:
  break;
 }
 }
 }

 //方向 外形 顏色
 public int[, ,,] Shape = new int[4, 4, 4, 2];
 private int state; //方向
 public int State
 {
 get
 {
 return (state);
 }
 set
 {
 state = value;
 }
 }


 public void DrawSquare(ref Graphics dc)
 {

 for (int Cnt1 = 0; Cnt1<4; Cnt1++)
 {
 for(int Cnt2=0;Cnt2<4;Cnt2++)
 {
  //Shape[State][Cnt1][Cnt2][1] = 0;
  if (Shape[state, Cnt1, Cnt2, 0] == 1)
  {
  SolidBrush Brush;
  switch(Shape[state, Cnt1, Cnt2, 1])
  {
  case (1):
  Brush = new SolidBrush(Color.Red);
  break;
  case (2):
  Brush = new SolidBrush(Color.Blue);
  break;
  case (3):
  Brush = new SolidBrush(Color.Yellow);
  break;
  case (4):
  Brush = new SolidBrush(Color.Green);
  break;
  case (5):
  Brush = new SolidBrush(Color.Tan);
  break;
  case (6):
  Brush = new SolidBrush(Color.Honeydew);
  break;
  case (7):
  Brush = new SolidBrush(Color.ForestGreen);
  break;
  default:
  Brush = new SolidBrush(Color.Red);
  break;
  
  }
  dc.FillRectangle(Brush, new Rectangle((positionX*16+16*Cnt2), (positionY*16+16*Cnt1), 16, 16));
  }
 }
 }
 }
 private int positionX;
 public int PositionX
 {
 get
 {
 return (positionX);
 }
 set
 {
 positionX = value;
 }
 }

 private int positionY;
 public int PositionY
 {
 get
 {
 return (positionY);
 }
 set
 {
 positionY = value;
 }
 }


 public void Switch(GameCtrl game)
 {
 if (CoverEdge(game))
 state = (state + 1) % 4;
 
 }
 public void AddX(GameCtrl game)
 {
 //判斷右側(cè)
 if(RightEdge(game))
 positionX++;
 }
 public bool AddY(GameCtrl game)
 {
 if (this.Land(game) == false)
 {
 positionY++;
 return (true);
 }
 else
 return(false);
 
 
 }
 public void SubX(GameCtrl game)
 {
 //判斷右側(cè)
 if (LeftEdge(game))
 positionX--;
 }
 public void SubY()
 {

 }

 private bool Land(GameCtrl game)
 {
 for (int i = 3; i >= 0; i--)
 {
 int rowNum = 21 - this.PositionY - i;
 for (int j = 0; j < 4; j++)
 {
  int colNum = this.PositionX + j + 3;

  if (this.Shape[this.State, i, j, 0] == 1)
  {
  if (game.GameBox[rowNum][colNum, 0] == 1)
  {
  game.AddBox(this);  
  return (true);
  }
  }

 }
 }

 return (false);

 }

 private bool RightEdge(GameCtrl game)
 {
 //判斷右側(cè)
 for (int i = 3; i >= 0; i--)
 {
 int rowNum = this.PositionX + i + 4;
 for (int j = 0; j < 4; j++)
 {
  int colNum = 22-this.PositionY-j;

  if (this.Shape[this.State, j, i, 0] == 1)
  {
  if (game.GameBox[colNum][rowNum, 0] == 1)
  {
  return (false);
  }
  }
 }

 }
 return (true);


 }

 private bool LeftEdge(GameCtrl game)
 {
 //判斷左側(cè)
 for (int i = 0; i < 4; i++)
 {
 int rowNum = this.PositionX + i +2;
 for (int j = 0; j < 4; j++)
 {

  int colNum = 22 - this.PositionY - j;

  if (this.Shape[this.State, j, i, 0] == 1)
  {
  if (game.GameBox[colNum][rowNum, 0] == 1)
  {
  return (false);
  }
  }
 }

 }
 return (true);


 }

 private bool CoverEdge(GameCtrl game)
 {
 //判斷變行是否有覆蓋
 int preState = (this.State + 1) % 4;
 for (int i = 0; i < 4; i++)
 {
 int rowNum = this.PositionX + i + 3;
 for (int j = 0; j < 4; j++)
 {

  int colNum = 22 - this.PositionY - j;

  if (this.Shape[preState, j, i, 0] == 1)
  {
  if (game.GameBox[colNum][rowNum, 0] == 1)
  {
  return (false);
  }
  }
 }

 }
 return (true);
 //return (false);


 }
 private int[, , ,] LeftLShape = {
  {{{1,1},{0,0},{0,0},{0,0}},
  {{1,1},{0,0},{0,0},{0,0}},
  {{1,1},{1,1},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{1,1},{1,1},{1,1},{0,0}},
  {{1,1},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{0,0},{1,1},{1,1},{0,0}},
  {{0,0},{0,0},{1,1},{0,0}},
  {{0,0},{0,0},{1,1},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{1,1},{0,0}},
  {{1,1},{1,1},{1,1},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}}
   };

 private int[, , ,] RightLShape = {
  {{{0,0},{0,0},{1,2},{0,0}},
  {{0,0},{0,0},{1,2},{0,0}},
  {{0,0},{1,2},{1,2},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{0,0},{0,0},{0,0},{0,0}},
  {{1,2},{0,0},{0,0},{0,0}},
  {{1,2},{1,2},{1,2},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{1,2},{1,2},{0,0},{0,0}},
  {{1,2},{0,0},{0,0},{0,0}},
  {{1,2},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{1,2},{1,2},{1,2},{0,0}},
  {{0,0},{0,0},{1,2},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}}


  };
 private int[, , ,] LeftZShape = {
  {{{1,3},{1,3},{0,0},{0,0}},
  {{0,0},{1,3},{1,3},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{0,0},{1,3},{0,0},{0,0}},
  {{1,3},{1,3},{0,0},{0,0}},
  {{1,3},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{1,3},{1,3},{0,0},{0,0}},
  {{0,0},{1,3},{1,3},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{0,0},{1,3},{0,0},{0,0}},
  {{1,3},{1,3},{0,0},{0,0}},
  {{1,3},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}}
  };

 private int[, , ,] RightZShape = {
  {{{0,0},{1,4},{1,4},{0,0}},
  {{1,4},{1,4},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{1,4},{0,0},{0,0},{0,0}},
  {{1,4},{1,4},{0,0},{0,0}},
  {{0,0},{1,4},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{0,0},{1,4},{1,4},{0,0}},
  {{1,4},{1,4},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{1,4},{0,0},{0,0},{0,0}},
  {{1,4},{1,4},{0,0},{0,0}},
  {{0,0},{1,4},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}}
  };

 private int[, , ,] lShape = {
  {{{1,6},{0,0},{0,0},{0,0}},
  {{1,6},{0,0},{0,0},{0,0}},
  {{1,6},{0,0},{0,0},{0,0}},
  {{1,6},{0,0},{0,0},{0,0}}},

  {{{0,0},{0,0},{0,0},{0,0}},
  {{1,6},{1,6},{1,6},{1,6}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}},

  {{{1,6},{0,0},{0,0},{0,0}},
  {{1,6},{0,0},{0,0},{0,0}},
  {{1,6},{0,0},{0,0},{0,0}},
  {{1,6},{0,0},{0,0},{0,0}}},

  {{{0,0},{0,0},{0,0},{0,0}},
  {{1,6},{1,6},{1,6},{1,6}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}}
  };
 private int[, , ,] TuShape = {
  {{{0,0},{1,7},{0,0},{0,0}},
  {{1,7},{1,7},{1,7},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}
  },

  {{{0,0},{1,7},{0,0},{0,0}},
  {{1,7},{1,7},{0,0},{0,0}},
  {{0,0},{1,7},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}
  },

  {{{0,0},{0,0},{0,0},{0,0}},
  {{1,7},{1,7},{1,7},{0,0}},
  {{0,0},{1,7},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}
  },

  {{{0,0},{1,7},{0,0},{0,0}},
  {{0,0},{1,7},{1,7},{0,0}},
  {{0,0},{1,7},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}
  },
  };
 private int[, , ,] TianShape = {
  {
  {{1,5},{1,5},{0,0},{0,0}},
  {{1,5},{1,5},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}
  },

  {
  {{1,5},{1,5},{0,0},{0,0}},
  {{1,5},{1,5},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}
  },

  {
  {{1,5},{1,5},{0,0},{0,0}},
  {{1,5},{1,5},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}
  },

  {
  {{1,5},{1,5},{0,0},{0,0}},
  {{1,5},{1,5},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}},
  {{0,0},{0,0},{0,0},{0,0}}
  }
  };
 }
 class GameCtrl
 {
 public List<int[,]> GameBox = new List<int[,]>();

 public int gameSclpe;

 public GameCtrl()
 {
 gameSclpe = 0;
 this.InitBox();
 }
 public void InitBox()
 {
 int[,] InitZore = new int[18, 2] { { 1, 0 }, { 1, 0 }, { 1, 0 },{ 0, 0 }, { 0, 0 }, { 0, 0 },
   { 0, 0 }, { 0, 0 }, { 0, 0 },{ 0, 0 }, { 0, 0 }, { 0, 0 }, 
   { 0, 0 }, { 0, 0 }, { 0, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 }};

 int[,] InitOne = new int[18, 2] { { 1, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 },
   { 1, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 },
   { 1, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 } };
 GameBox.Add(InitOne);
 GameBox.Add(InitOne);
 GameBox.Add(InitOne);
 for (int Cnt = 0; Cnt < 20; Cnt++)
 GameBox.Add(InitZore);

 }
 public void ClrBox()
 {
 GameBox.Clear();
 }

 public void AddBox(Square landSquare)
 {
 for (int i = 0; i < 4; i++)
 {
 int rowNum = 22 - landSquare.PositionY - i;
 int[,] ShapeRow = new int[18, 2];

 for(int j =0;j<18;j++)
 {
  if (GameBox[rowNum][j, 0] == 1)
  {
  ShapeRow[j, 0] = 1;
  ShapeRow[j, 1] = GameBox[rowNum][j, 1];
  }
 }
 for (int j = 0; j < 4; j++)
 {

  int colNum = landSquare.PositionX + j+3;
  if (landSquare.Shape[landSquare.State, i, j, 0] == 1)
  {
  ShapeRow[colNum, 0] = 1;
  ShapeRow[colNum, 1] = landSquare.Shape[landSquare.State, i, j, 1];
 
  }
 
  
 }
 GameBox[rowNum] = ShapeRow;

 }
 SubBox();
 }


 private void SubBox()
 {
 int[,] InitZore = new int[18, 2] { { 1, 0 }, { 1, 0 }, { 1, 0 },{ 0, 0 }, { 0, 0 }, { 0, 0 },
   { 0, 0 }, { 0, 0 }, { 0, 0 },{ 0, 0 }, { 0, 0 }, { 0, 0 }, 
   { 0, 0 }, { 0, 0 }, { 0, 0 }, { 1, 0 }, { 1, 0 }, { 1, 0 }};
 int Cnt;
 for (Cnt = 3; Cnt < 23; Cnt++)
 {
 int ColSum,Cnt2;
 for (ColSum = 0, Cnt2 = 3; Cnt2 < 15;Cnt2++ )
  ColSum += GameBox[Cnt][Cnt2, 0];
 if(ColSum==12)
 {
  this.gameSclpe++;
  GameBox.RemoveAt(3);
  GameBox.Add(InitZore);
  Cnt--;
 }
 }

 
 }

 public void BoxDraw(ref Graphics dc)
 {
 for (int Cnt1 = 3; Cnt1 < 23; Cnt1++)
 {
 for (int Cnt2 = 3; Cnt2 < 15; Cnt2++)
 {
  if (GameBox[Cnt1][Cnt2, 0] == 1)
  {
  SolidBrush Brush;
  switch (GameBox[Cnt1][Cnt2, 1])
  {
  case (1):
  Brush = new SolidBrush(Color.Red);
  break;
  case (2):
  Brush = new SolidBrush(Color.Blue);
  break;
  case (3):
  Brush = new SolidBrush(Color.Yellow);
  break;
  case (4):
  Brush = new SolidBrush(Color.Green);
  break;
  case (5):
  Brush = new SolidBrush(Color.Tan);
  break;
  case (6):
  Brush = new SolidBrush(Color.Honeydew);
  break;
  case (7):
  Brush = new SolidBrush(Color.ForestGreen);
  break;
  default:
  Brush = new SolidBrush(Color.Red);
  break;

  }
  dc.FillRectangle(Brush, new Rectangle((Cnt2-3)* 16, (22 - Cnt1) * 16, 16, 16));
  }
 }
 }

 
 }
 }

 
}

更多俄羅斯方塊精彩文章請點(diǎn)擊專題:俄羅斯方塊游戲集合 進(jìn)行學(xué)習(xí)。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 簡單介紹C# 中的擴(kuò)展方法

    簡單介紹C# 中的擴(kuò)展方法

    這篇文章主要介紹了C# 中的擴(kuò)展方法的相關(guān)資料,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • C#怎么給PDF添加背景圖片

    C#怎么給PDF添加背景圖片

    無論是辦公還是日常生活中都經(jīng)常會(huì)用到,很多時(shí)候,PDF文件的背景色都是白色,看多了難免覺得累,更換PDF的背景不僅可以讓眼睛看起來更舒服,還可以讓PDF文件看上去更美觀。這篇文章我主要寫的是如何使用C# 給PDF文件添加圖片背景
    2016-02-02
  • C#入門之索引器使用實(shí)例

    C#入門之索引器使用實(shí)例

    這篇文章主要介紹了C#的索引器使用方法,對此,C#初學(xué)者應(yīng)予以牢固掌握,需要的朋友可以參考下
    2014-08-08
  • C#11新特性使用案例詳解

    C#11新特性使用案例詳解

    這篇文章主要為大家介紹了C#11新特性的使用案例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • 一篇文章看懂C#中的協(xié)變、逆變

    一篇文章看懂C#中的協(xié)變、逆變

    這篇文章主要給大家介紹了如何通過一篇文章看懂C#中協(xié)變、逆變的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • C#操作config文件的具體方法

    C#操作config文件的具體方法

    這篇文章介紹了在C#中對config文件的操作,有需要的朋友可以參考一下
    2013-07-07
  • c#讀取excel方法實(shí)例分析

    c#讀取excel方法實(shí)例分析

    這篇文章主要介紹了c#讀取excel方法,實(shí)例分析了C#讀取excel文件的原理與相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • C#中Clone一個(gè)對象的值到另一個(gè)對象案例

    C#中Clone一個(gè)對象的值到另一個(gè)對象案例

    這篇文章主要介紹了C#中Clone一個(gè)對象的值到另一個(gè)對象案例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • Unity實(shí)現(xiàn)虛擬搖桿

    Unity實(shí)現(xiàn)虛擬搖桿

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)虛擬搖桿,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • C# 多線程更新界面的錯(cuò)誤的解決方法

    C# 多線程更新界面的錯(cuò)誤的解決方法

    這篇文章主要介紹了C# 多線程更新界面的錯(cuò)誤方法,由于一個(gè)線程的程序,如果調(diào)用一個(gè)功能是阻塞的,那么就會(huì)影響到界面的更新,導(dǎo)致使用人員操作不便。所以往往會(huì)引入雙線程的工作的方式,主線程負(fù)責(zé)更新界面和調(diào)度,而次線程負(fù)責(zé)做一些阻塞的工作,便有了下面春雨里方法
    2021-10-10

最新評論

台山市| 昭通市| 当阳市| 眉山市| 寻甸| 和顺县| 连江县| 蒙山县| 山阳县| 壶关县| 怀来县| 昆山市| 灌云县| 肇州县| 文水县| 土默特右旗| 拉萨市| 县级市| 南川市| 太仓市| 乌恰县| 阿图什市| 萨嘎县| 铅山县| 望江县| 琼中| 福贡县| 德化县| 长治县| 玉溪市| 闻喜县| 宜都市| 武定县| 清流县| 留坝县| 娱乐| 普格县| 长乐市| 清原| 内乡县| 温泉县|