学习C#从俄罗斯方块开始(二) 联系客服

发布时间 : 星期日 文章学习C#从俄罗斯方块开始(二)更新完毕开始阅读e1a4075b804d2b160b4ec094

///

/// 变化方块 /// private void ChangeTricks() { if (CurrentStatusNum < 3) { CurrentStatusNum++; } else { CurrentStatusNum = 0; } for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { 再接着是检测砖块是否可以向下移动、向左移动、向右移动。思路很简单。看看他的要运动的方向的背景下个位置是不是为1.如果不是。那么就返回true.否则是false: view plaincopy to clipboardprint? 1. ///

2. /// 检测是否可以向下了 3. ///

4. /// 5. private bool CheckIsDown() 6. {

7. for (int y = 0; y < 4; y++) 8. {

9. for (int x = 0; x < 4; x++) 10. {

11. if (CurrentTrick[y, x] == 1) 12. {

13. //超过了背景

14. if (y + CurrentY + 1 >= 20) 15. {

16. return false; 17. }

18. if (x + CurrentX >= 14) 19. {

20. CurrentX = 13 - x; 21. }

22. if (bgGraoud[y + CurrentY + 1, x + CurrentX] == 1

)

23. {

24. return false; 25. } 26. } 27. } 28. }

29. return true; 30. }

31. ///

32. /// 检测是否可以左移 33. ///

34. /// 35. private bool CheckIsLeft() 36. {

37. for (int y = 0; y < 4; y++) 38. {

39. for (int x = 0; x < 4; x++) 40. {

41. if (CurrentTrick[y, x] == 1) 42. {

43. if (x + CurrentX - 1 < 0) 44. {

45. return false; 46. }

47. if (bgGraoud[y + CurrentY, x + CurrentX - 1] == 1

)

48. {

49. return false; 50. } 51. } 52. } 53. }

54. return true;

55. }

56. ///

57. /// 检测是否可以右移 58. ///

59. /// 60. private bool CheckIsRight() 61. {

62. for (int y = 0; y < 4; y++) 63. {

64. for (int x = 0; x < 4; x++) 65. {

66. if (CurrentTrick[y, x] == 1) 67. {

68. if (x + CurrentX + 1 >= 14) 69. {

70. return false; 71. }

72. if (bgGraoud[y + CurrentY, x + CurrentX+1] == 1)

73. {

74. return false; 75. } 76. } 77. } 78. }

79. return true; 80. }

///

/// 检测是否可以向下了 /// /// private bool CheckIsDown() { for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { if (CurrentTrick[y, x] == 1) { //超过了背景 if (y + CurrentY + 1 >= 20) { return false; 下面是绘制函数:没啥思路,循环画出即可

view plaincopy to clipboardprint?

1. private void Draw() 2. {

3. Graphics g = Graphics.FromImage(myImage); 4. g.Clear(this.BackColor);

5. for (int bgy = 0; bgy < 20; bgy++) 6. {

7. for (int bgx = 0; bgx < 14; bgx++) 8. {

9. if (bgGraoud[bgy, bgx] == 1) 10. { 11.

12. g.FillRectangle(new SolidBrush(Color.Blue), bgx *

20, bgy * 20, 20, 20); 13. } 14. } 15. }

16. //绘制当前的图片

17. for (int y = 0; y < 4; y++) 18. {

19. for (int x = 0; x < 4; x++) 20. {

21. if (CurrentTrick[y, x] == 1) 22. {

23. g.FillRectangle(new SolidBrush(Color.Blue), (x +

CurrentX) * 20, (y + CurrentY) * 20, 20, 20); 24. } 25. } 26. }