Match.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:2k
源码类别:

游戏

开发平台:

Visual C++

  1. // Match.cpp: implementation of the Match class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "FiveChess.h"
  6. #include "Match.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. Match::Match()
  16. {
  17. for(int i=0;i<LW;i++)
  18. for(int j=0;j<LW;j++)
  19. {
  20. chessboard[i][j]=0;
  21. }
  22. }
  23. Match::~Match()
  24. {
  25. }
  26. void Match::Clear()
  27. {
  28. for(int i=0;i<LW;i++)
  29. for(int j=0;j<LW;j++)
  30. {
  31. chessboard[i][j]=0;
  32. }
  33. }
  34. BOOL Match::CanDown(int x,int y,int who)
  35. {
  36. if(x<0||x>=LW||y<0||y>=LW)
  37. return FALSE;
  38. if(chessboard[x][y]!=0)
  39. return FALSE;
  40. chessboard[x][y]=who;
  41. return TRUE;
  42. }
  43. BOOL Match::IsWin(int who,int pos[5][2])
  44. {
  45. int i,j;
  46. for(i=0;i<LW;i++)
  47. for(j=0;j<LW;j++)
  48. {
  49. if(chessboard[i][j]==who)
  50. {
  51. if(j+4<LW)//水平
  52. {
  53. if(chessboard[i][j+1]==who&&chessboard[i][j+2]==who&&chessboard[i][j+3]==who&&chessboard[i][j+4]==who)
  54. {
  55. for(int k=0;k<5;k++)
  56. {
  57. pos[k][0]=i;
  58. pos[k][1]=j+k;
  59. }
  60. return TRUE;
  61. }
  62. }
  63. if(i+4<LW)//垂直
  64. {
  65. if(chessboard[i+1][j]==who&&chessboard[i+2][j]==who&&chessboard[i+3][j]==who&&chessboard[i+4][j]==who)
  66. {
  67. for(int k=0;k<5;k++)
  68. {
  69. pos[k][0]=i+k;
  70. pos[k][1]=j;
  71. }
  72. return TRUE;
  73. }
  74. }
  75. if(i+4<LW&&j+4<LW)//东南向
  76. {
  77. if(chessboard[i+1][j+1]==who&&chessboard[i+2][j+2]==who&&chessboard[i+3][j+3]==who&&chessboard[i+4][j+4]==who)
  78. {
  79. for(int k=0;k<5;k++)
  80. {
  81. pos[k][0]=i+k;
  82. pos[k][1]=j+k;
  83. }
  84. return TRUE;
  85. }
  86. }
  87. if(i-4>0&&j+4<LW)//东北
  88. {
  89. if(chessboard[i-1][j+1]==who&&chessboard[i-2][j+2]==who&&chessboard[i-3][j+3]==who&&chessboard[i-4][j+4]==who)
  90. {
  91. for(int k=0;k<5;k++)
  92. {
  93. pos[k][0]=i-k;
  94. pos[k][1]=j+k;
  95. }
  96. return TRUE;
  97. }
  98. }
  99. }
  100. }
  101. return false;
  102. }