新二十四点View.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:27k
源码类别:

游戏

开发平台:

Visual C++

  1. // 新二十四点View.cpp : implementation of the CMyView class
  2. //
  3. #include "stdafx.h"
  4. #include "新二十四点.h"
  5. #include "stdlib.h"
  6. #include "math.h"
  7. #include "新二十四点Doc.h"
  8. #include "CntrItem.h"
  9. #include "新二十四点View.h"
  10. #include "CalDlg.h"
  11. #include "calculator.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CMyView
  19. IMPLEMENT_DYNCREATE(CMyView, CView)
  20. BEGIN_MESSAGE_MAP(CMyView, CView)
  21. //{{AFX_MSG_MAP(CMyView)
  22. ON_WM_DESTROY()
  23. ON_WM_SETFOCUS()
  24. ON_WM_SIZE()
  25. ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
  26. ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
  27. ON_WM_LBUTTONDOWN()
  28. ON_COMMAND(ID_GO, OnGo)
  29. ON_WM_RBUTTONDOWN()
  30. ON_COMMAND(ID_GOCAL, OnGocal)
  31. //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CMyView construction/destruction
  35. // 
  36. // ipoint 是指+-=()的位置!
  37. // iipoint 是指用户输入的位置!
  38. CMyView::CMyView():ipoint(520,380),iipoint(50,300),PaiPoint(20,30),AnswerPoint(50,300)
  39. {
  40. lrtag=0;
  41. step=0;
  42. FaPai();
  43. m_pSelection = NULL;
  44. }
  45. CMyView::~CMyView()
  46. {
  47. }
  48. BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
  49. {
  50. // TODO: Modify the Window class or styles here by modifying
  51. //  the CREATESTRUCT cs
  52. return CView::PreCreateWindow(cs);
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CMyView drawing
  56. void CMyView::OnDraw(CDC* pDC)
  57. {
  58. CMyDoc* pDoc = GetDocument();
  59. ASSERT_VALID(pDoc);
  60. /////////show button;
  61. DrawButton(pDC,jia,ipoint);
  62. ipoint.x+=50;
  63. DrawButton(pDC,jian,ipoint);
  64. ipoint.x+=50;
  65. DrawButton(pDC,left,ipoint);
  66. ipoint.x+=50;
  67. DrawButton(pDC,equal,ipoint);
  68. ipoint.y+=50;
  69. ipoint.x-=50;
  70. DrawButton(pDC,right,ipoint);
  71. ipoint.x-=50;
  72. DrawButton(pDC,chu,ipoint);
  73. ipoint.x-=50;
  74. DrawButton(pDC,cheng,ipoint);
  75. ipoint.x+=150;
  76. DrawButton(pDC,goon,ipoint);
  77. //ipoint又回到原来的位置!!
  78. ipoint.x-=150;
  79. ipoint.y-=50;
  80. /////////////show pai
  81. ShowPai();
  82. ///////////
  83. CPoint s(490,300);
  84. ShowFonts("按右键求帮助!",40,20,s,255);
  85. ///////////
  86. //////////////////////////////////////////
  87. DrawLine(pDC,255,0,0,10,0,250,750,250);
  88. DrawLine(pDC,0,255,0,10,0,260,750,260);
  89. DrawLine(pDC,0,0,255,10,0,270,750,270);
  90. ///////////////////////////////////////////////
  91. if (m_pSelection == NULL)
  92. {
  93. POSITION pos = pDoc->GetStartPosition();
  94. m_pSelection = (CMyCntrItem*)pDoc->GetNextClientItem(pos);
  95. }
  96. if (m_pSelection != NULL)
  97. m_pSelection->Draw(pDC, CRect(10, 10, 210, 210));
  98. }
  99. void CMyView::OnInitialUpdate()
  100. {
  101. CView::OnInitialUpdate();
  102. // TODO: remove this code when final selection model code is written
  103. m_pSelection = NULL;    // initialize selection
  104. }
  105. void CMyView::OnDestroy()
  106. {
  107. // Deactivate the item on destruction; this is important
  108. // when a splitter view is being used.
  109.    CView::OnDestroy();
  110.    COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  111.    if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
  112.    {
  113.       pActiveItem->Deactivate();
  114.       ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  115.    }
  116. }
  117. /////////////////////////////////////////////////////////////////////////////
  118. // OLE Client support and commands
  119. BOOL CMyView::IsSelected(const CObject* pDocItem) const
  120. {
  121. // The implementation below is adequate if your selection consists of
  122. //  only CMyCntrItem objects.  To handle different selection
  123. //  mechanisms, the implementation here should be replaced.
  124. // TODO: implement this function that tests for a selected OLE client item
  125. return pDocItem == m_pSelection;
  126. }
  127. void CMyView::OnInsertObject()
  128. {
  129. // Invoke the standard Insert Object dialog box to obtain information
  130. //  for new CMyCntrItem object.
  131. COleInsertDialog dlg;
  132. if (dlg.DoModal() != IDOK)
  133. return;
  134. BeginWaitCursor();
  135. CMyCntrItem* pItem = NULL;
  136. TRY
  137. {
  138. // Create new item connected to this document.
  139. CMyDoc* pDoc = GetDocument();
  140. ASSERT_VALID(pDoc);
  141. pItem = new CMyCntrItem(pDoc);
  142. ASSERT_VALID(pItem);
  143. // Initialize the item from the dialog data.
  144. if (!dlg.CreateItem(pItem))
  145. AfxThrowMemoryException();  // any exception will do
  146. ASSERT_VALID(pItem);
  147.         if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
  148. pItem->DoVerb(OLEIVERB_SHOW, this);
  149. ASSERT_VALID(pItem);
  150. // As an arbitrary user interface design, this sets the selection
  151. //  to the last item inserted.
  152. // TODO: reimplement selection as appropriate for your application
  153. m_pSelection = pItem;   // set selection to last inserted item
  154. pDoc->UpdateAllViews(NULL);
  155. }
  156. CATCH(CException, e)
  157. {
  158. if (pItem != NULL)
  159. {
  160. ASSERT_VALID(pItem);
  161. pItem->Delete();
  162. }
  163. AfxMessageBox(IDP_FAILED_TO_CREATE);
  164. }
  165. END_CATCH
  166. EndWaitCursor();
  167. }
  168. void CMyView::OnCancelEditCntr()
  169. {
  170. // Close any in-place active item on this view.
  171. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  172. if (pActiveItem != NULL)
  173. {
  174. pActiveItem->Close();
  175. }
  176. ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  177. }
  178. // Special handling of OnSetFocus and OnSize are required for a container
  179. //  when an object is being edited in-place.
  180. void CMyView::OnSetFocus(CWnd* pOldWnd)
  181. {
  182. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  183. if (pActiveItem != NULL &&
  184. pActiveItem->GetItemState() == COleClientItem::activeUIState)
  185. {
  186. // need to set focus to this item if it is in the same view
  187. CWnd* pWnd = pActiveItem->GetInPlaceWindow();
  188. if (pWnd != NULL)
  189. {
  190. pWnd->SetFocus();   // don't call the base class
  191. return;
  192. }
  193. }
  194. CView::OnSetFocus(pOldWnd);
  195. }
  196. void CMyView::OnSize(UINT nType, int cx, int cy)
  197. {
  198. CView::OnSize(nType, cx, cy);
  199. COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  200. if (pActiveItem != NULL)
  201. pActiveItem->SetItemRects();
  202. }
  203. /////////////////////////////////////////////////////////////////////////////
  204. // CMyView diagnostics
  205. #ifdef _DEBUG
  206. void CMyView::AssertValid() const
  207. {
  208. CView::AssertValid();
  209. }
  210. void CMyView::Dump(CDumpContext& dc) const
  211. {
  212. CView::Dump(dc);
  213. }
  214. CMyDoc* CMyView::GetDocument() // non-debug version is inline
  215. {
  216. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
  217. return (CMyDoc*)m_pDocument;
  218. }
  219. #endif //_DEBUG
  220. /////////////////////////////////////////////////////////////////////////////
  221. // CMyView message handlers
  222. void CMyView::OnLButtonDown(UINT nFlags, CPoint point) 
  223. {
  224. CPoint ppp(0,300);
  225. CPoint pppp(50,500);
  226. char a[2];
  227. CClientDC dc(this);
  228. //刷屏
  229. int q=1;
  230. if(lrtag==1||step==0)
  231. DrawLine(&dc,255,255,255,200,0,400,410,400);
  232. // TODO: Add your message handler code here and/or call default
  233. ID id=MouseWhere(point);
  234. switch(id)
  235. {
  236. case jia:
  237. expr[step++]='+';
  238. ShowFonts("+",40,14,iipoint);
  239. iipoint.x+=40;
  240. break;
  241. case jian:
  242. expr[step++]='-';
  243. ShowFonts("-",40,14,iipoint);
  244. iipoint.x+=40;
  245. break;
  246. case cheng:
  247. expr[step++]='*';
  248. ShowFonts("*",40,14,iipoint);
  249. iipoint.x+=40;
  250. break;
  251. case chu:
  252. expr[step++]='/';
  253. ShowFonts("/",40,14,iipoint);
  254. iipoint.x+=40;
  255. break;
  256. case left:
  257. expr[step++]='(';
  258. ShowFonts("(",40,14,iipoint);
  259. iipoint.x+=40;
  260. break;
  261. case right:
  262. expr[step++]=')';
  263. ShowFonts(")",40,14,iipoint);
  264. iipoint.x+=40;
  265. break;
  266. case equal:
  267. expr[step++]='=';
  268. ShowFonts("=",40,14,iipoint);
  269. iipoint.x=50;
  270. iipoint.y=300;
  271. expr[step]=NULL;
  272. ShowFonts(expr,40,14,iipoint);
  273. postfix();
  274. DrawLine(&dc,255,255,255,200,0,400,410,400);
  275. if((eval()-24)<0.001&&(eval()-24)>-0.001)
  276. ShowFonts("wonderful",60,20,ppp,255);
  277. else 
  278. ShowFonts("error",60,20,ppp,255);
  279. step=0;
  280. break;
  281. case one:
  282. expr[step++]='0';
  283. sprintf(a,"%d",poke[0]);
  284. ShowFonts(a,40,14,iipoint,255);
  285. iipoint.x+=40;
  286. break;
  287. case two:
  288. expr[step++]='1';
  289. sprintf(a,"%d",poke[1]);
  290. ShowFonts(a,40,14,iipoint,0,255);
  291. iipoint.x+=40;
  292. break;
  293. case three:
  294. expr[step++]='2';
  295. sprintf(a,"%d",poke[2]);
  296. ShowFonts(a,40,14,iipoint,0,0,255);
  297. iipoint.x+=40;
  298. break;
  299. case four:
  300. expr[step++]='3';
  301. sprintf(a,"%d",poke[3]);
  302. ShowFonts(a,40,20,iipoint,122,122,122);
  303. iipoint.x+=40;
  304. break;
  305. case goon:
  306. FaPai();
  307. DrawLine(&dc,255,255,255,200,0,400,410,400);
  308. DrawLine(&dc,255,255,255,300,80,70,700,70);
  309. ShowPai();
  310. step=0;
  311. iipoint.x=50;
  312. iipoint.y=300;
  313. break;
  314. }
  315. CView::OnLButtonDown(nFlags, point);
  316. }
  317. ID CMyView::MouseWhere(CPoint point)
  318. {
  319. if(point.x>ipoint.x&&point.x<ipoint.x+40&&point.y>ipoint.y&&point.y<ipoint.y+40)
  320. return jia;
  321. if(point.x>ipoint.x+50&&point.x<ipoint.x+90&&point.y>ipoint.y&&point.y<ipoint.y+40)
  322. return jian;
  323. if(point.x>ipoint.x&&point.x<ipoint.x+40&&point.y>ipoint.y+50&&point.y<ipoint.y+90)
  324. return cheng;
  325. if(point.x>ipoint.x+50&&point.x<ipoint.x+90&&point.y>ipoint.y+50&&point.y<ipoint.y+90)
  326. return chu;
  327. if(point.x>ipoint.x+100&&point.x<ipoint.x+140&&point.y>ipoint.y&&point.y<ipoint.y+40)
  328. return left;
  329. if(point.x>ipoint.x+100&&point.x<ipoint.x+140&&point.y>ipoint.y+50&&point.y<ipoint.y+90)
  330. return right;
  331. if(point.x>ipoint.x+150&&point.x<ipoint.x+190&&point.y>ipoint.y&&point.y<ipoint.y+40)
  332. return equal;
  333. if(point.x>ipoint.x+150&&point.x<ipoint.x+190&&point.y>ipoint.y+50&&point.y<ipoint.y+90)
  334. return goon;
  335. if(point.x>PaiPoint.x&&point.x<PaiPoint.x+100&&point.y>PaiPoint.y&&point.y<PaiPoint.y+200)
  336. return one;
  337. if(point.x>PaiPoint.x+200&&point.x<PaiPoint.x+300&&point.y>PaiPoint.y&&point.y<PaiPoint.y+200)
  338. return two;
  339. if(point.x>PaiPoint.x+400&&point.x<PaiPoint.x+500&&point.y>PaiPoint.y&&point.y<PaiPoint.y+200)
  340. return three;
  341. if(point.x>PaiPoint.x+600&&point.x<PaiPoint.x+700&&point.y>PaiPoint.y&&point.y<PaiPoint.y+200)
  342. return four;
  343. else return none;
  344. }
  345. void CMyView::DrawButton(CDC*pDC,ID id,CPoint ipoint)
  346. {
  347. CBitmap bitmap;
  348. CDC dcMemory;
  349. dcMemory.CreateCompatibleDC(pDC);
  350. switch(id)
  351. {
  352. case jia:
  353. {
  354. bitmap.LoadBitmap(IDB_JIA);
  355. dcMemory.SelectObject(&bitmap);
  356. pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
  357. break;
  358. }
  359. case jian:
  360. {
  361. bitmap.LoadBitmap(IDB_JIAN);
  362. dcMemory.SelectObject(&bitmap);
  363. pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
  364. break;
  365. }
  366. case cheng:
  367. {
  368. bitmap.LoadBitmap(IDB_CHENG);
  369. dcMemory.SelectObject(&bitmap);
  370. pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
  371. break;
  372. }
  373. case chu:
  374. {
  375. bitmap.LoadBitmap(IDB_CHU);
  376. dcMemory.SelectObject(&bitmap);
  377. pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
  378. break;
  379. }
  380. case equal:
  381. { bitmap.LoadBitmap(IDB_EQUAL);
  382. dcMemory.SelectObject(&bitmap);
  383. pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
  384. break;
  385. }
  386. case left:
  387. { bitmap.LoadBitmap(IDB_LEFT);
  388. dcMemory.SelectObject(&bitmap);
  389. pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
  390. break;
  391. }
  392. case right:
  393. { bitmap.LoadBitmap(IDB_RIGHT);
  394. dcMemory.SelectObject(&bitmap);
  395. pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
  396. break;
  397. }
  398. case goon:
  399. { bitmap.LoadBitmap(IDB_GOON);
  400. dcMemory.SelectObject(&bitmap);
  401. pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
  402. break;
  403. }
  404. }
  405. }
  406. void CMyView::ShowFonts(char * a,int lfHeight,int lfwidth,CPoint point,int red,int green,int blue)
  407. {
  408. CClientDC dc(this);
  409. LOGFONT logfont;
  410. CFont font;
  411. logfont.lfHeight=lfHeight;
  412. logfont.lfWidth=lfwidth;
  413. logfont.lfEscapement=0;
  414. logfont.lfOrientation=0;
  415. logfont.lfWeight=FW_NORMAL;
  416. logfont.lfItalic=0;
  417. logfont.lfUnderline=0;
  418. logfont.lfStrikeOut=0;
  419. logfont.lfCharSet=ANSI_CHARSET;
  420. logfont.lfOutPrecision=OUT_DEFAULT_PRECIS;
  421. logfont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
  422. logfont.lfQuality=PROOF_QUALITY;
  423. logfont.lfPitchAndFamily=VARIABLE_PITCH|FF_ROMAN;
  424. strcpy(logfont.lfFaceName,"Times New Roman");
  425. font.CreateFontIndirect(&logfont);
  426.     CFont *oldfont=dc.SelectObject(&font);
  427. dc.SetTextColor(RGB(red,green,blue));
  428. dc.TextOut(point.x,point.y,a);
  429. dc.SelectObject(oldfont);
  430. }
  431. void CMyView::FaPai()
  432. {
  433. for(int i=0;i<4;i++)
  434. {
  435. for(int j=0;j<10;j+=rand()%8)
  436. {
  437. rand();
  438. }
  439. poke[i]=rand()%12+1;
  440. }
  441. }
  442. int  CMyView::Algorithum(short poke[4])
  443. {
  444. CClientDC dc(this);
  445. CPoint point=AnswerPoint;
  446. int a[4];//用来表示四个数的标号;
  447. int b[3];//用来表示三个符号;
  448. double ra[4];
  449. char istring[20];
  450. int i=0;
  451. int tag=0;
  452. int count=0;
  453. int p=0;
  454. m_sArray.RemoveAll();
  455. /////////////////////////////////////////////////////////////
  456. for(a[0]=0;a[0]<4;a[0]++)
  457. {
  458. for(a[1]=0;a[1]<4;a[1]++)
  459. {
  460. if(a[0]==a[1])
  461. continue;
  462. for(a[2]=0;a[2]<4;a[2]++)
  463. {
  464. if(a[2]==a[0]||a[2]==a[1])
  465. continue;
  466. for(a[3]=0;a[3]<4;a[3]++)
  467. {
  468. if(a[3]==a[2]||a[3]==a[1]||a[3]==a[0])
  469. continue;
  470. for(i=0;i<4;i++)
  471. {
  472. ra[i]=poke[a[i]]+0.0;
  473. }
  474. for(b[0]=0;b[0]<4;b[0]++)
  475. for(b[1]=0;b[1]<4;b[1]++)
  476. for(b[2]=0;b[2]<4;b[2]++)
  477. {
  478. for(i=0;i<4;i++)
  479. {
  480. ra[i]=poke[a[i]]+0.0;
  481. }
  482. //(((a0b0a1)b1a2)b2a3)
  483. tag=0;
  484. for(i=0;i<3;i++)
  485. {
  486. switch(b[i])
  487. {
  488. case 0: ra[i+1]=ra[i]+ra[i+1];break;
  489. case 1: ra[i+1]=ra[i]-ra[i+1];break;
  490. case 2: ra[i+1]=ra[i]*ra[i+1];break;
  491. case 3:
  492. if(fabs(ra[i+1])>0.0001)
  493. ra[i+1]=ra[i]/ra[i+1];
  494. else 
  495. tag=1;
  496. break;
  497. }
  498. if(tag==1)
  499. break;
  500. //解
  501. if(!tag&&i==2&&fabs(ra[3]-24.0)<0.0001)
  502. {
  503. istring[p++]='(';
  504. istring[p++]='(';
  505. if(poke[a[0]]/10==0)
  506. istring[p++]=48+poke[a[0]];
  507. }
  508. else
  509. {
  510. istring[p++]=poke[a[0]]/10+48;
  511. istring[p++]=poke[a[0]]%10+48;
  512. }
  513. switch(b[0])
  514. {
  515. case 0: istring[p++]='+';break;
  516. case 1: istring[p++]='-';break;
  517. case 2: istring[p++]='*';break;
  518. case 3: istring[p++]='/';break;
  519. }
  520. if(poke[a[1]]/10==0)
  521. istring[p++]=48+poke[a[1]];
  522. }
  523. else
  524. {
  525. istring[p++]=poke[a[1]]/10+48;
  526. istring[p++]=poke[a[1]]%10+48;
  527. }
  528. istring[p++]=')';
  529. switch(b[1])
  530. {
  531. case 0: istring[p++]='+';break;
  532. case 1: istring[p++]='-';break;
  533. case 2: istring[p++]='*';break;
  534. case 3: istring[p++]='/';break;
  535. }
  536. if(poke[a[2]]/10==0)
  537. istring[p++]=48+poke[a[2]];
  538. }
  539. else
  540. {
  541. istring[p++]=poke[a[2]]/10+48;
  542. istring[p++]=poke[a[2]]%10+48;
  543. }
  544. istring[p++]=')';
  545. switch(b[2])
  546. {
  547. case 0: istring[p++]='+';break;
  548. case 1: istring[p++]='-';break;
  549. case 2: istring[p++]='*';break;
  550. case 3: istring[p++]='/'; break;
  551. }
  552. if(poke[a[3]]/10==0)
  553. istring[p++]=48+poke[a[3]];
  554. }
  555. else
  556. {
  557. istring[p++]=poke[a[3]]/10+48;
  558. istring[p++]=poke[a[3]]%10+48;
  559. }
  560. istring[p++]='=';
  561. istring[p++]='2';
  562. istring[p++]='4';
  563. istring[p]=NULL;
  564. bool having=false;
  565. for(int i=0;i<m_sArray.GetSize();i++)
  566. {
  567. if(m_sArray[i]==istring)
  568. having=true;
  569. }
  570. if(having==false)
  571. {
  572. m_sArray.Add(istring);
  573. ShowFonts(istring,40,20,point);
  574. point.y+=40;
  575. }
  576. count++;
  577. p=0;
  578. }
  579. }
  580. //(a0b0a1)b1(a2b2a3)
  581. tag=0;
  582. for(i=0;i<4;i++)
  583. {
  584. ra[i]=poke[a[i]];
  585. }
  586. switch(b[0])
  587. {
  588. case 0: ra[1]=ra[0]+ra[1];break;
  589. case 1: ra[1]=ra[0]-ra[1];break;
  590. case 2: ra[1]=ra[0]*ra[1];break;
  591. case 3:
  592. if(ra[1]!=0)
  593. ra[1]=(ra[0]+0.0)/ra[1];
  594. else 
  595. tag=1;
  596. break;
  597. }
  598. switch(b[2])
  599. {
  600. case 0: ra[2]=ra[2]+ra[3];break;
  601. case 1: ra[2]=ra[2]-ra[3];break;
  602. case 2: ra[2]=ra[2]*ra[3];break;
  603. case 3:
  604. if(ra[3]!=0)
  605. ra[2]=(ra[2]+0.0)/ra[3];
  606. else 
  607. tag=1;
  608. break;
  609. }
  610. switch(b[1])
  611. {
  612. case 0: ra[3]=ra[1]+ra[2];break;
  613. case 1: ra[3]=ra[1]-ra[2];break;
  614. case 2: ra[3]=ra[1]*ra[2];break;
  615. case 3:
  616. if(ra[2]!=0)
  617. ra[3]=(ra[1]+0.0)/ra[2];
  618. else 
  619. tag=1;
  620. break;
  621. }
  622. //解
  623. if(!tag&&fabs(ra[3]-24.0)<0.0001)
  624. {
  625. istring[p++]='(';
  626. if(poke[a[0]]/10==0)
  627. istring[p++]=48+poke[a[0]];
  628. }
  629. else
  630. {
  631. istring[p++]=poke[a[0]]/10+48;
  632. istring[p++]=poke[a[0]]%10+48;
  633. }
  634. switch(b[0])
  635. {
  636. case 0: istring[p++]='+';break;
  637. case 1: istring[p++]='-';break;
  638. case 2: istring[p++]='*';break;
  639. case 3: istring[p++]='/';break;
  640. }
  641. if(poke[a[1]]/10==0)
  642. istring[p++]=48+poke[a[1]];
  643. }
  644. else
  645. {
  646. istring[p++]=poke[a[1]]/10+48;
  647. istring[p++]=poke[a[1]]%10+48;
  648. }
  649. istring[p++]=')';
  650. switch(b[1])
  651. {
  652. case 0: istring[p++]='+';break;
  653. case 1: istring[p++]='-';break;
  654. case 2: istring[p++]='*';break;
  655. case 3: istring[p++]='/';break;
  656. }
  657. istring[p++]='(';
  658. if(poke[a[2]]/10==0)
  659. istring[p++]=48+poke[a[2]];
  660. }
  661. else
  662. {
  663. istring[p++]=poke[a[2]]/10+48;
  664. istring[p++]=poke[a[2]]%10+48;
  665. }
  666. switch(b[2])
  667. {
  668. case 0: istring[p++]='+';break;
  669. case 1: istring[p++]='-';break;
  670. case 2: istring[p++]='*';break;
  671. case 3: istring[p++]='/';break;
  672. }
  673. if(poke[a[3]]/10==0)
  674. istring[p++]=48+poke[a[3]];
  675. }
  676. else
  677. {
  678. istring[p++]=poke[a[3]]/10+48;
  679. istring[p++]=poke[a[3]]%10+48;
  680. }
  681. istring[p++]=')';
  682. istring[p++]='=';
  683. istring[p++]='2';
  684. istring[p++]='4';
  685. istring[p]=NULL;
  686. bool having=false;
  687. for(int i=0;i<m_sArray.GetSize();i++)
  688. {
  689. if(m_sArray[i]==istring)
  690. having=true;
  691. }
  692. if(having==false)
  693. {
  694. m_sArray.Add(istring);
  695. ShowFonts(istring,40,20,point);
  696. point.y+=40;
  697. }
  698. p=0;
  699. count++;
  700. }
  701. ///////////////////////////////(a0b0(a1b1a2))b2a3
  702. tag=0;
  703. p=0;
  704. for(i=0;i<4;i++)
  705. {
  706. ra[i]=poke[a[i]];
  707. }
  708. switch(b[1])
  709. {
  710. case 0: ra[1]=ra[1]+ra[2];break;
  711. case 1: ra[1]=ra[1]-ra[2];break;
  712. case 2: ra[1]=ra[1]*ra[2];break;
  713. case 3:
  714. if(ra[2]!=0)
  715. ra[1]=(ra[1]+0.0)/ra[2];
  716. else 
  717. tag=1;
  718. break;
  719. }
  720. switch(b[0])
  721. {
  722. case 0: ra[0]=ra[0]+ra[1];break;
  723. case 1: ra[0]=ra[0]-ra[1];break;
  724. case 2: ra[0]=ra[0]*ra[1];break;
  725. case 3:
  726. if(ra[1]!=0)
  727. ra[0]=(ra[0]+0.0)/ra[1];
  728. else tag=1;
  729. break;
  730. }
  731. switch(b[2])
  732. {
  733. case 0: ra[3]=ra[0]+ra[3];break;
  734. case 1: ra[3]=ra[0]-ra[3];break;
  735. case 2: ra[3]=ra[0]*ra[3];break;
  736. case 3:
  737. if(ra[3]!=0)
  738. ra[3]=(ra[0]+0.0)/ra[3];
  739. else tag=1;
  740. break;
  741. }
  742. //解
  743. if(!tag&&(ra[3]-24.0)<0.0001&&(ra[3]-24.0)>-0.0001)
  744. {
  745. istring[p++]='(';
  746. if(poke[a[0]]/10==0)
  747. istring[p++]=48+poke[a[0]];
  748. }
  749. else
  750. {
  751. istring[p++]=poke[a[0]]/10+48;
  752. istring[p++]=poke[a[0]]%10+48;
  753. }
  754. switch(b[0])
  755. {
  756. case 0: istring[p++]='+';break;
  757. case 1: istring[p++]='-';break;
  758. case 2: istring[p++]='*';break;
  759. case 3: istring[p++]='/';break;
  760. }
  761. istring[p++]='(';
  762. if(poke[a[1]]/10==0)
  763. istring[p++]=48+poke[a[1]];
  764. }
  765. else
  766. {
  767. istring[p++]=poke[a[1]]/10+48;
  768. istring[p++]=poke[a[1]]%10+48;
  769. }
  770. switch(b[1])
  771. {
  772. case 0: istring[p++]='+';break;
  773. case 1: istring[p++]='-';break;
  774. case 2: istring[p++]='*';break;
  775. case 3: istring[p++]='/';break;
  776. }
  777. if(poke[a[2]]/10==0)
  778. istring[p++]=48+poke[a[2]];
  779. }
  780. else
  781. {
  782. istring[p++]=poke[a[2]]/10+48;
  783. istring[p++]=poke[a[2]]%10+48;
  784. }
  785. istring[p++]=')';
  786. istring[p++]=')';
  787. switch(b[2])
  788. {
  789. case 0: istring[p++]='+';break;
  790. case 1: istring[p++]='-';break;
  791. case 2: istring[p++]='*';break;
  792. case 3: istring[p++]='/';break;
  793. }
  794. if(poke[a[3]]/10==0)
  795. istring[p++]=48+poke[a[3]];
  796. }
  797. else
  798. {
  799. istring[p++]=poke[a[3]]/10+48;
  800. istring[p++]=poke[a[3]]%10+48;
  801. }
  802. istring[p++]='=';
  803. istring[p++]='2';
  804. istring[p++]='4';
  805. istring[p]=NULL;
  806. bool having=false;
  807. for(int i=0;i<m_sArray.GetSize();i++)
  808. {
  809. if(m_sArray[i]==istring)
  810. having=true;
  811. }
  812. if(having==false)
  813. {
  814. m_sArray.Add(istring);
  815. ShowFonts(istring,40,20,point);
  816. point.y+=40;
  817. }
  818. p=0;
  819. count++;
  820. }
  821. ///////////////////////////////a0b0(a1b1(a2b2a3))
  822. tag=0;
  823. p=0;
  824. for(i=0;i<4;i++)
  825. {
  826. ra[i]=poke[a[i]];
  827. }
  828. switch(b[2])
  829. {
  830. case 0: ra[2]=ra[2]+ra[3];break;
  831. case 1: ra[2]=ra[2]-ra[3];break;
  832. case 2: ra[2]=ra[2]*ra[3];break;
  833. case 3:
  834. if(ra[3]!=0)
  835. ra[2]=(ra[2]+0.0)/ra[3];
  836. else tag=1;
  837. break;
  838. }
  839. switch(b[1])
  840. {
  841. case 0: ra[1]=ra[1]+ra[2];break;
  842. case 1: ra[1]=ra[1]-ra[2];break;
  843. case 2: ra[1]=ra[1]*ra[2];break;
  844. case 3:
  845. if(ra[2]!=0)
  846. ra[1]=(ra[1]+0.0)/ra[2];
  847. else tag=1;
  848. break;
  849. }
  850. switch(b[0])
  851. {
  852. case 0: ra[0]=ra[0]+ra[1];break;
  853. case 1: ra[0]=ra[0]-ra[1];break;
  854. case 2: ra[0]=ra[0]*ra[1];break;
  855. case 3:
  856. if(ra[1]!=0)
  857. ra[0]=(ra[0]+0.0)/ra[1];
  858. else tag=1;
  859. break;
  860. }
  861. //解a0b0(a1b1(a2b2a3))
  862. if(!tag&&(ra[0]-24.0)<0.0001&&(ra[0]-24.0)>-0.0001)
  863. {
  864. if(poke[a[0]]/10==0)
  865. istring[p++]=48+poke[a[0]];
  866. }
  867. else
  868. {
  869. istring[p++]=poke[a[0]]/10+48;
  870. istring[p++]=poke[a[0]]%10+48;
  871. }
  872. switch(b[0])
  873. {
  874. case 0: istring[p++]='+';break;
  875. case 1: istring[p++]='-';break;
  876. case 2: istring[p++]='*';break;
  877. case 3: istring[p++]='/';break;
  878. }
  879. istring[p++]='(';
  880. if(poke[a[1]]/10==0)
  881. istring[p++]=48+poke[a[1]];
  882. }
  883. else
  884. {
  885. istring[p++]=poke[a[1]]/10+48;
  886. istring[p++]=poke[a[1]]%10+48;
  887. }
  888. switch(b[1])
  889. {
  890. case 0: istring[p++]='+';break;
  891. case 1: istring[p++]='-';break;
  892. case 2: istring[p++]='*';break;
  893. case 3: istring[p++]='/';break;
  894. }
  895. istring[p++]='(';
  896. if(poke[a[2]]/10==0)
  897. istring[p++]=48+poke[a[2]];
  898. }
  899. else
  900. {
  901. istring[p++]=poke[a[2]]/10+48;
  902. istring[p++]=poke[a[2]]%10+48;
  903. }
  904. switch(b[2])
  905. {
  906. case 0: istring[p++]='+';break;
  907. case 1: istring[p++]='-';break;
  908. case 2: istring[p++]='*';break;
  909. case 3: istring[p++]='/';break;
  910. }
  911. if(poke[a[3]]/10==0)
  912. istring[p++]=48+poke[a[3]];
  913. }
  914. else
  915. {
  916. istring[p++]=poke[a[3]]/10+48;
  917. istring[p++]=poke[a[3]]%10+48;
  918. }
  919. istring[p++]=')';
  920. istring[p++]=')';
  921. istring[p++]='=';
  922. istring[p++]='2';
  923. istring[p++]='4';
  924. istring[p]=NULL;
  925. bool having=false;
  926. for(int i=0;i<m_sArray.GetSize();i++)
  927. {
  928. if(m_sArray[i]==istring)
  929. having=true;
  930. }
  931. if(having==false)
  932. {
  933. m_sArray.Add(istring);
  934. ShowFonts(istring,40,20,point);
  935. point.y+=40;
  936. }
  937. p=0;
  938. count++;
  939. }
  940. }
  941. }
  942. }
  943. }
  944. }
  945. point.x=0;
  946. if(count==0)
  947. ShowFonts("there is no answer at all",40,20,point,255);
  948. return count;
  949. }
  950. void CMyView::DrawLine(CDC* pDC,int red,int green ,int blue,int linewidth,int x1,int y1,int x2,int y2 )
  951. {
  952. CPen pen(PS_SOLID,linewidth,RGB(red,green,blue));
  953. CPen *oldpen=pDC->SelectObject(&pen);
  954. pDC->MoveTo(x1,y1);
  955. pDC->LineTo(x2,y2);
  956. pDC->SelectObject(oldpen);
  957. }
  958. //////////////////////////////////////?????????????????????????
  959. void CMyView::OnGo() 
  960. {
  961. }
  962. void CMyView::ShowPai()
  963. {
  964. CPoint point=PaiPoint;
  965. char a[2];
  966. int i;
  967. for(i=0;i<4;i++)
  968. {
  969. sprintf(a,"%d",poke[i]);
  970. switch(i)
  971. { case 0:
  972. ShowFonts(a,180,50,point,255);break;
  973. case 1:
  974. ShowFonts(a,180,50,point,0,255);break;
  975. case 2:
  976. ShowFonts(a,180,50,point,0,0,255);break;
  977. case 3:
  978. ShowFonts(a,180,50,point,122,122,122);break;
  979. }
  980. point.x+=200;
  981. }
  982. }
  983. void CMyView::OnRButtonDown(UINT nFlags, CPoint point) 
  984. {
  985. CClientDC dc(this);
  986. // TODO: Add your message handler code here and/or call default
  987. step=0;
  988. //step=0表示清除expr[]中的元素!!
  989. DrawLine(&dc,255,255,255,200,0,400,410,400);
  990. Algorithum(poke);
  991. lrtag=1;
  992. CView::OnRButtonDown(nFlags, point);
  993. }
  994. void CMyView::OnGocal() 
  995. {
  996. // TODO: Add your command handler code here
  997. CCalDlg dlg(this);
  998. dlg.DoModal();
  999. }