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

游戏

开发平台:

Visual C++

  1. // russiaView.cpp : implementation of the CRussiaView class
  2. //
  3. #include "stdAfx.h"
  4. #include "russia.h"
  5. #include "destinate.h"
  6. #include "russiaDoc.h"
  7. #include "russiaView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. const int TimerID=1;
  14. int dead=0;
  15. Block everblock;
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CRussiaView
  18. IMPLEMENT_DYNCREATE(CRussiaView, CView)
  19. BEGIN_MESSAGE_MAP(CRussiaView, CView)
  20. //{{AFX_MSG_MAP(CRussiaView)
  21. ON_WM_KEYDOWN()
  22. ON_WM_TIMER()
  23. ON_COMMAND(ID_NEWGAME, OnNewgame)
  24. ON_COMMAND(ID_SAVEGAME, OnSavegame)
  25. ON_COMMAND(ID_HEROLIST, OnHerolist)
  26. //}}AFX_MSG_MAP
  27. // Standard printing commands
  28. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  29. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  30. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CRussiaView construction/destruction
  34. CRussiaView::CRussiaView()
  35. {
  36. width=20;
  37. // TODO: add construction code here
  38. }
  39. CRussiaView::~CRussiaView()
  40. {
  41. }
  42. BOOL CRussiaView::PreCreateWindow(CREATESTRUCT& cs)
  43. {
  44. // TODO: Modify the Window class or styles here by modifying
  45. //  the CREATESTRUCT cs
  46. return CView::PreCreateWindow(cs);
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CRussiaView drawing
  50. void CRussiaView::OnDraw(CDC* pDC)
  51. {
  52. CRussiaDoc* pDoc = GetDocument();
  53. ASSERT_VALID(pDoc);
  54. DrawBlocks(pDC);
  55. DrawEdge(pDC);
  56. //SetTimer(TimerID,4000,NULL);
  57. // TODO: add draw code for native data here
  58. }
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CRussiaView printing
  61. BOOL CRussiaView::OnPreparePrinting(CPrintInfo* pInfo)
  62. {
  63. // default preparation
  64. return DoPreparePrinting(pInfo);
  65. }
  66. void CRussiaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  67. {
  68. // TODO: add extra initialization before printing
  69. }
  70. void CRussiaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  71. {
  72. // TODO: add cleanup after printing
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CRussiaView diagnostics
  76. #ifdef _DEBUG
  77. void CRussiaView::AssertValid() const
  78. {
  79. CView::AssertValid();
  80. }
  81. void CRussiaView::Dump(CDumpContext& dc) const
  82. {
  83. CView::Dump(dc);
  84. }
  85. CRussiaDoc* CRussiaView::GetDocument() // non-debug version is inline
  86. {
  87. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRussiaDoc)));
  88. return (CRussiaDoc*)m_pDocument;
  89. }
  90. #endif //_DEBUG
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CRussiaView message handlers
  93. void CRussiaView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  94. {
  95. // TODO: Add your message handler code here and/or call default
  96. CClientDC dc(this);
  97. switch(nChar)
  98. {
  99. case VK_DOWN:
  100. {
  101. everblock.ChangeFalse();
  102. everblock.Down();
  103. everblock.ChangeTrue();
  104. DrawBlocks(&dc);
  105. break;
  106. }
  107. case VK_LEFT:
  108. {
  109. everblock.ChangeFalse();
  110. everblock.Left();
  111. everblock.ChangeTrue();
  112. DrawBlocks(&dc);
  113. break;
  114. }
  115. case VK_RIGHT:
  116. {
  117. everblock.ChangeFalse();
  118. everblock.Right();
  119. everblock.ChangeTrue();
  120. DrawBlocks(&dc);
  121. break;
  122. }
  123. case VK_UP:
  124. {
  125. everblock.ChangeFalse();
  126. everblock.Shift();
  127. everblock.ChangeTrue();
  128. DrawBlocks(&dc);
  129. break;
  130. }
  131. default:
  132. break;
  133. }
  134. //if(!SetArray(everblock))
  135. /*
  136. if(!everblock.DownOK())
  137. {
  138. if(ExamArray()==false)
  139. {
  140. KillTimer(TimerID);
  141. MessageBox(" you are dead");
  142. }
  143. else
  144. {
  145. everblock.ChangeTrue();
  146. BreakBlock();
  147. DrawBlocks(&dc);
  148. everblock.Generate();
  149. everblock.ChangeTrue();
  150. DrawBlocks(&dc);
  151. }
  152. }
  153. */
  154. CView::OnKeyDown(nChar, nRepCnt, nFlags);
  155. }
  156. void CRussiaView::OnTimer(UINT nIDEvent) 
  157. {
  158. // TODO: Add your message handler code here and/or call default
  159. CClientDC dc(this);
  160. if(nIDEvent==TimerID)
  161. {
  162. if(!everblock.DownOK())
  163. {
  164. everblock.ChangeTrue();
  165. BreakBlock();
  166. DrawBlocks(&dc);
  167. if(ExamArray()==false||dead)
  168. {
  169. KillTimer(TimerID);
  170. dead=0;
  171. MessageBox(" you are dead");
  172. }
  173. else
  174. {
  175. everblock.Generate();
  176. if(!everblock.Possiable())
  177. dead=1;
  178. everblock.ChangeTrue();
  179. DrawBlocks(&dc);
  180. }
  181. }
  182. else
  183. {
  184. everblock.ChangeFalse();
  185. everblock.Down();
  186. everblock.ChangeTrue();
  187. DrawBlocks(&dc);
  188. }
  189. }
  190. CView::OnTimer(nIDEvent);
  191. }
  192. void CRussiaView::WinHelp(DWORD dwData, UINT nCmd) 
  193. {
  194. // TODO: Add your specialized code here and/or call the base class
  195. CView::WinHelp(dwData, nCmd);
  196. }
  197. void CRussiaView::DrawWhiteBlocks(CDC * pDC,CRect& rect)
  198. {
  199. CBrush backbrush,*oldbrush;
  200. backbrush.CreateSolidBrush(RGB(255,255,255));
  201. oldbrush=pDC->SelectObject(&backbrush);
  202. pDC->Rectangle(rect);
  203. pDC->SelectObject(oldbrush);
  204. }
  205. void CRussiaView::DrawColorBlocks(CDC * pDC,CRect &rect)
  206. {
  207. CBrush brush,*oldbrush;
  208. brush.CreateSolidBrush(RGB(255,123,0));
  209. oldbrush=pDC->SelectObject(&brush);
  210. pDC->Rectangle(rect);
  211. pDC->SelectObject(oldbrush);
  212. }
  213. void CRussiaView::DrawEdge(CDC * pDC)
  214. {
  215. int i;
  216. CRect rect;
  217. for(i=0;i<ROW;i++)
  218. {
  219. rect.top=width*i;
  220. rect.bottom=width*(i+1);
  221. rect.left=0;
  222. rect.right=width;
  223. DrawColorBlocks(pDC,rect);
  224. }
  225. for(i=0;i<ROW;i++)
  226. {
  227. rect.top=width*i;
  228. rect.bottom=width*(i+1);
  229. rect.left=width*(COL-1);
  230. rect.right=width*COL;
  231. DrawColorBlocks(pDC,rect);
  232. }
  233. for(i=0;i<COL;i++)
  234. {
  235. rect.top=width*(ROW-1);
  236. rect.bottom=width*ROW;
  237. rect.left=i*width;
  238. rect.right=width*(i+1);
  239. DrawColorBlocks(pDC,rect);
  240. }
  241. }
  242. void CRussiaView::DrawBlocks(CDC * pDC)
  243. {
  244. CBrush brush;
  245. CRect rect;
  246. int i=0,j=0;
  247. for(i=0;i<ROW-1;i++)
  248. {
  249. rect.top=width*i;
  250. rect.bottom=width*(i+1);
  251. for(j=1;j<COL-1;j++)
  252. {
  253. rect.left=width*j;
  254. rect.right=width*(j+1);
  255. if(Array[i][j].takeup)
  256. {
  257. DrawColorBlocks(pDC,rect);
  258. }
  259. else
  260. {
  261. DrawWhiteBlocks(pDC,rect);
  262. }
  263. }
  264. }
  265. }
  266. void CRussiaView::OnNewgame() 
  267. {
  268. // TODO: Add your command handler code here
  269. MessageBox(" are you ready");
  270. everblock.Generate();
  271. InitArray();
  272. SetTimer(TimerID,1000,NULL);
  273. }
  274. void CRussiaView::OnSavegame() 
  275. {
  276. // TODO: Add your command handler code here
  277. MessageBox(" do you want to save game?");
  278. }
  279. void CRussiaView::OnHerolist() 
  280. {
  281. MessageBox(" the hero is listed");
  282. // TODO: Add your command handler code here
  283. }