⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 24pointsdlg.cpp

📁 简单的游戏24点
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 24pointsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "24points.h"
#include "24pointsDlg.h"
#include "Parse.h"
#include <math.h>
#include ".\24pointsdlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
public:
	virtual BOOL OnInitDialog();
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy24pointsDlg dialog
int CMy24pointsDlg::CursorID[]={IDC_CURSOR_ADD,IDC_CURSOR_SUB,IDC_CURSOR_MULT,
IDC_CURSOR_DIVIDE,IDC_CURSOR_LPAREN,IDC_CURSOR_RPAREN};

CMy24pointsDlg::CMy24pointsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy24pointsDlg::IDD, pParent),m_TLP(10,10),
	m_shuffle(TRUE),m_lapse(0),colockRect(239,128,305,194),m_operators(0),
	objPreRect(0,0,0,0),symPreRect(0,0,0,0)
{
	m_maxElapse=200;
	m_index=7;
	m_card_index=-1;
	//{{AFX_DATA_INIT(CMy24pointsDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_mouseDown=FALSE;
	m_HCursor=AfxGetApp()->LoadStandardCursor(IDC_ARROW);

	int height=100;
	m_SymbolRect[0]=CRect(m_TLP.x,m_TLP.y+height,m_TLP.x+30,m_TLP.y+height+30);
	m_SymbolRect[1]=CRect(m_TLP.x+30,m_TLP.y+height,m_TLP.x+60,m_TLP.y+height+30);
	m_SymbolRect[2]=CRect(m_TLP.x+60,m_TLP.y+height,m_TLP.x+90,m_TLP.y+height+30);
	m_SymbolRect[3]=CRect(m_TLP.x+90,m_TLP.y+height,m_TLP.x+120,m_TLP.y+height+30);
	m_SymbolRect[4]=CRect(m_TLP.x+120,m_TLP.y+height,m_TLP.x+150,m_TLP.y+height+30);
	m_SymbolRect[5]=CRect(m_TLP.x+150,m_TLP.y+height,m_TLP.x+180,m_TLP.y+height+30);

	node*head=new node;
	head->m_rect=CRect(m_TLP.x,m_TLP.y+height+40, m_TLP.x+10,m_TLP.y+height+50);
	head->m_str[0]=':';
	head->m_str[1]='=';
	m_objArray.Add(head);
}

void CMy24pointsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy24pointsDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy24pointsDlg, CDialog)
	//{{AFX_MSG_MAP(CMy24pointsDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_BN_CLICKED(IDC_RE_DO, OnReDo)
	ON_BN_CLICKED(IDC_SUBMIT, OnSubmit)
	ON_BN_CLICKED(IDC_SHOE_EXPRESSION, OnShoeExpression)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
//	ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy24pointsDlg message handlers

BOOL CMy24pointsDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	// TODO: Add extra initialization here
	SetTimer(2,m_maxElapse,NULL);
	m_ok_button.Create("发牌",WS_CHILD|WS_VISIBLE,CRect(198,202,248,227),this,IDOK);
	m_cancel_button.Create("退出",WS_CHILD|WS_VISIBLE,CRect(258,202,308,227),this,IDCANCEL);
	m_submit_button.Create("提交",WS_CHILD|WS_VISIBLE,CRect(18,202,68,227),this,IDC_SUBMIT);
	m_redo_button.Create("重做",WS_CHILD|WS_VISIBLE,CRect(78,202,128,227),this,IDC_RE_DO);
	m_show_button.Create("提示",WS_CHILD|WS_VISIBLE,CRect(138,202,188,227),this,IDC_SHOE_EXPRESSION);
	m_result.Create("",WS_CHILD|WS_VISIBLE,CRect(18,180,245,200),this,IDC_STATIC_RESULT);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy24pointsDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMy24pointsDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CPaintDC dc(this);
		m_ok_button.ShowWindow(SW_SHOW);
		m_cancel_button.ShowWindow(SW_SHOW);
		cards.Draw(&dc,m_TLP,m_shuffle);
		DrawSyms(&dc);
		DrawFormula(&dc,CPoint(0,0));
		if(m_index<6)
		{
			if(m_mouseDown)
			{
				CPen pen;
				pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
				CPen*oldPen=dc.SelectObject(&pen);
				dc.MoveTo(m_SymbolRect[m_index].left,m_SymbolRect[m_index].bottom);
				dc.LineTo(m_SymbolRect[m_index].left,m_SymbolRect[m_index].top);
				dc.LineTo(m_SymbolRect[m_index].right,m_SymbolRect[m_index].top);
				pen.DeleteObject();
				pen.CreatePen(PS_SOLID,1,RGB(255,255,255));
				dc.SelectObject(&pen);
				dc.LineTo(m_SymbolRect[m_index].right,m_SymbolRect[m_index].bottom);
				dc.LineTo(m_SymbolRect[m_index].left,m_SymbolRect[m_index].bottom);
				pen.DeleteObject();
				dc.SelectObject(oldPen);
			}
			else
			{
				CPen pen;
				pen.CreatePen(PS_SOLID,1,RGB(255,255,255));
				CPen*oldPen=dc.SelectObject(&pen);
				dc.MoveTo(m_SymbolRect[m_index].left,m_SymbolRect[m_index].bottom);
				dc.LineTo(m_SymbolRect[m_index].left,m_SymbolRect[m_index].top);
				dc.LineTo(m_SymbolRect[m_index].right,m_SymbolRect[m_index].top);
				pen.DeleteObject();
				pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
				dc.SelectObject(&pen);
				dc.LineTo(m_SymbolRect[m_index].right,m_SymbolRect[m_index].bottom);
				dc.LineTo(m_SymbolRect[m_index].left,m_SymbolRect[m_index].bottom);
				pen.DeleteObject();
				dc.SelectObject(oldPen);
			}
		}
		if(m_lapse>0)
		{
			dc.SelectStockObject(LTGRAY_BRUSH);
			dc.Ellipse(&colockRect);
			CPoint p=colockRect.CenterPoint();
			int l=colockRect.Width()/2-2;
			double x=p.x+cos(m_lapse*3.14159/180-1.57028)*l;
			double y=p.y+sin(m_lapse*3.14159/180-1.57028)*l;
			dc.MoveTo(p);
			dc.LineTo(x,y);

			dc.MoveTo(p.x,p.y-l-2);
			dc.LineTo(p.x,p.y-l+6);

			dc.MoveTo(p.x+l+2,p.y);
			dc.LineTo(p.x+l-6,p.y);
			
			dc.MoveTo(p.x,p.y+l+2);
			dc.LineTo(p.x,p.y+l-6);
			
			dc.MoveTo(p.x-l-2,p.y);
			dc.LineTo(p.x-l+6,p.y);
		}
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMy24pointsDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMy24pointsDlg::OnTimer(UINT nIDEvent) 
{
	if(	nIDEvent==1)
	{
		((CStatic*)GetDlgItem(IDC_STATIC_RESULT))->SetWindowText("");
		KillTimer(1);
	}
	else if(nIDEvent==2)
	{
		if(m_lapse<360)
		{
			m_lapse++;
			InvalidateRect(&colockRect,FALSE);
		}
		else
		{
			KillTimer(2),m_lapse=0;
			Invalidate();
			CString str;
			cards.GetResult(str);
			CStatic*pStatic=(CStatic*)GetDlgItem(IDC_STATIC_RESULT);
			pStatic->SetWindowText(str);
			CButton*pbut=(CButton*)GetDlgItem(IDC_SHOE_EXPRESSION);
			pbut->EnableWindow(FALSE);
			pbut=(CButton*)GetDlgItem(IDC_RE_DO);
			pbut->EnableWindow(FALSE);
			pbut=(CButton*)GetDlgItem(IDC_SUBMIT);
			pbut->EnableWindow(FALSE);			
		}
	}
	CDialog::OnTimer(nIDEvent);
}

void CMy24pointsDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_card_index=-1;
	strGot="";
	m_mouseDown=TRUE;
	hitNode=0;
	int i;
//////////////////////////////////////////////////
	for(i=1;i<m_objArray.GetSize();i++)
	{
		node*p=(node*)m_objArray.GetAt(i);
		if(p->m_rect.PtInRect(point))
		{
			CClientDC dc(this);
			p->m_mouse_in=2;
			p->Draw(&dc);
			strGot=p->m_str;
			hitNode=p;
		}
	}
//////////////////////////////////////////////////////
	for(i=0;i<4;i++)
	{
		if(cards.m_index_set.find(i)!=cards.m_index_set.end())
			continue;
		if(GetCardsRect(i).PtInRect(point))
		{
			int num=cards.m_deck[cards.m_got_cards[i]].point-IDB_DIAMAND_02+1;
			if(num==13)
				num=0;
			m_HCursor=AfxGetApp()->LoadCursor (num+IDC_CURSOR_01);
			strGot.Format("%d",num+1);
			m_card_index=i;
			break;
		}
	}
	if(strGot.GetLength()==0)
	{
		for(i=0;i<6;i++)
		{
			if(m_SymbolRect[i].PtInRect(point))
			{
				m_HCursor=AfxGetApp()->LoadCursor (CursorID[i]);
				char s[]="+-*/()";
				strGot.Insert(0,s[i]);
				break;
			}
		}
	}
	for(i=0;i<6;i++)
	{
		if(m_SymbolRect[i].PtInRect(point))
		{
			CPen pen;
			CClientDC dc(this);
			pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
			CPen*oldPen=dc.SelectObject(&pen);
			dc.MoveTo(m_SymbolRect[i].left,m_SymbolRect[i].bottom);
			dc.LineTo(m_SymbolRect[i].left,m_SymbolRect[i].top);
			dc.LineTo(m_SymbolRect[i].right,m_SymbolRect[i].top);
			pen.DeleteObject();
			pen.CreatePen(PS_SOLID,1,RGB(255,255,255));
			dc.SelectObject(&pen);
			dc.LineTo(m_SymbolRect[i].right,m_SymbolRect[i].bottom);
			dc.LineTo(m_SymbolRect[i].left,m_SymbolRect[i].bottom);
			pen.DeleteObject();
			dc.SelectObject(oldPen);
		}
	}
	CDialog::OnLButtonDown(nFlags, point);
}

void CMy24pointsDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	int i=7;
	if(!m_mouseDown)
	{//鼠标进入那个符号去
		for(i=0;i<6;i++)
			if(m_SymbolRect[i].PtInRect(point))
				break;
	}
	m_index=i;
	if(m_index<6&&!m_mouseDown)
	{
		CRect rect;
		rect.left=m_SymbolRect[m_index].left;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -