// MxCubesView.cpp : implementation of the CMxCubesView class
// Download by http://www.codefans.net
#include "stdafx.h"
#include "MxCubes.h"
#include "MxCubesDoc.h"
#include "MxCubesView.h"
#include "WordBase.H"
#include "Cube.h"
#include "SetStepDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMxCubesView
IMPLEMENT_DYNCREATE(CMxCubesView, CView)
BEGIN_MESSAGE_MAP(CMxCubesView, CView)
//{{AFX_MSG_MAP(CMxCubesView)
ON_WM_ERASEBKGND()
ON_COMMAND(ID_SYSTEM_SETBKBNDCOLOR, OnSystemSetbkbndcolor)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_FILE_SET, OnFileSet)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
ON_COMMAND(ID_FILE_PRINT_SETUP, OnFilePrintSetup)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_COMMAND(ID_FILE_RESTORE, OnFileRestore)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMxCubesView construction/destruction
CMxCubesView::CMxCubesView()
{
// TODO: add construction code here
BACKGROUND = RGB(0,0,0);
m_nDownButton = -1;
m_xBtnDefColor = RGB(192,192,192);
m_bOK = TRUE;
RANDSTEP = 10;
}
CMxCubesView::~CMxCubesView()
{
}
BOOL CMxCubesView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMxCubesView drawing
void CMxCubesView::OnDraw(CDC* pDC)
{
CMxCubesDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDC dc;
CBitmap xBMP;
CBitmap* pxSavedBMP = NULL;
CRect xClientRect;
GetClientRect(&xClientRect);
if(pDC->IsPrinting()) return;
if(!dc.CreateCompatibleDC(pDC)) return;
if(!xBMP.CreateCompatibleBitmap(pDC, xClientRect.Width(), xClientRect.Height())) return;
OnPrepareDC(&dc, NULL);
pxSavedBMP = dc.SelectObject(&xBMP);
// 下面开始用dc绘图
dc.FillSolidRect(&xClientRect, BACKGROUND);
DrawView(&dc);
// m_xCube.Show(&dc);
// 显示到屏幕
pDC->BitBlt(0,0,xClientRect.Width(),xClientRect.Height(),&dc,0,0, SRCCOPY);
dc.SelectObject(pxSavedBMP);
}
/////////////////////////////////////////////////////////////////////////////
// CMxCubesView printing
BOOL CMxCubesView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMxCubesView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMxCubesView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMxCubesView diagnostics
#ifdef _DEBUG
void CMxCubesView::AssertValid() const
{
CView::AssertValid();
}
void CMxCubesView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMxCubesDoc* CMxCubesView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMxCubesDoc)));
return (CMxCubesDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMxCubesView message handlers
BOOL CMxCubesView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE; // CView::OnEraseBkgnd(pDC);
}
void CMxCubesView::OnSystemSetbkbndcolor()
{
// TODO: Add your command handler code here
CColorDialog xCD;
if(xCD.DoModal() == IDOK)
{
BACKGROUND = xCD.GetColor();
Invalidate();
}
}
void CMxCubesView::DrawView(CDC *pDC)
{
CRect xCR; // Client Rect
GetClientRect(&xCR);
CRect xCtrlR; // Control Rect
xCtrlR = CRect(3*xCR.Width()/4,xCR.Height()/4,7*xCR.Width()/8, 3*xCR.Height()/4);
pDC->FillRect(&xCtrlR, &CBrush(m_xBtnDefColor));
// CRect xBR[4]; // Button Rect
int n;
int W = xCtrlR.Width() ;
int H = xCtrlR.Height();
int L = xCtrlR.left;
int T = xCtrlR.top ;
for(n=0; n<4; n++)
{
m_xBR[n] = CRect(L+W/6,T+H/16+n*7*H/28,L+5*W/6,T+H/16+int((n+0.5)*7*H/28));
pDC->DrawEdge(&m_xBR[n], EDGE_RAISED, BF_RECT);
PutTitle(pDC, n, true);
}
// 画魔方的轮廓
POINT V0;
V0.x = xCR.Width()/4;
V0.y = 10*xCR.Height()/21;
int nSL;
int nMin;
if(xCR.Width()<xCR.Height())
nMin = xCR.Width();
else
nMin = xCR.Height();
if(::GetSystemMetrics(SM_CXSCREEN)<1000)
nSL = nMin/3;
else
nSL = nMin/4;
m_xCube.ShowCube(pDC, V0, nSL);
m_xCubeRect = CRect(V0.x-5,V0.y-int(0.8*nSL),V0.x+5+int(1.8*nSL),V0.y+nSL+5);
}
void CMxCubesView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int n;
SetCapture();
for(n=0; n<4; n++)
{
if(!m_xBR[n].PtInRect(point)) continue;
m_nDownButton = n;
CDC* pDC = GetDC();
pDC->FillSolidRect(&m_xBR[m_nDownButton], m_xBtnDefColor);
pDC->DrawEdge(&m_xBR[n], EDGE_SUNKEN, BF_RECT);
PutTitle(pDC, m_nDownButton, false);
ReleaseDC(pDC);
break;
}
if(n<4) goto ENDTHIS;
for(n=0; n<9; n++)
{
if(!m_xCube.m_xClickOgram[n].PtInOgram(point)) continue;
m_xCube.RgnClicked(n);
m_xCube.m_nStep = 20;
InvalidateRect(&m_xCubeRect);
JudgeOK();
break;
}
ENDTHIS:
CView::OnLButtonDown(nFlags, point);
}
void CMxCubesView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_nDownButton >= 0)
{
if(m_xBR[m_nDownButton].PtInRect(point))
{
m_xCube.Turnto(m_nDownButton); // 0~3: left right up down
InvalidateRect(&m_xCubeRect);
}
CDC* pDC = GetDC();
pDC->FillSolidRect(&m_xBR[m_nDownButton], m_xBtnDefColor);
pDC->DrawEdge(&m_xBR[m_nDownButton], EDGE_RAISED, BF_RECT);
PutTitle(pDC, m_nDownButton, true);
m_nDownButton = -1;
ReleaseDC(pDC);
}
ReleaseCapture();
CView::OnLButtonUp(nFlags, point);
}
void CMxCubesView::PutTitle(CDC *pDC, int n, bool bRaised)
{
static char title[20];
static short ccc[16] ;
static short turn[16] ;
CWordBase::GetTurn(turn);
switch(n)
{
case 0:
strcpy(title, "向左");
CWordBase::GetLeft(ccc);
break;
case 1:
strcpy(title, "向右");
CWordBase::GetRight(ccc);
break;
case 2:
strcpy(title, "向上");
CWordBase::GetUp(ccc);
break;
case 3:
strcpy(title, "向下");
CWordBase::GetDown(ccc);
break;
default:
return;
}
const int wordlen = 16;
CPoint c = m_xBR[n].CenterPoint();
int x,y,k,cnt,off;
cnt = 0;
if(bRaised) off = 0;
else off = 1;
for(x=0; x<wordlen; x++)
{
k = 1;
for(y=0; y<wordlen; y++)
{
if(turn[cnt] & k) pDC->SetPixelV(c.x-wordlen-wordlen/4+x+off,c.y-wordlen/2+y+off,RGB(0,0,255));
k = k<<1;
}
cnt++;
}
cnt = 0;
for(x=0; x<wordlen; x++)
{
k = 1;
for(y=0; y<wordlen; y++)
{
if(ccc[cnt] & k) pDC->SetPixelV(c.x+wordlen/4+x+off,c.y-wordlen/2+y+off,RGB(255,0,0));
k = k<<1;
}
cnt++;
}
}
void CMxCubesView::OnFileNew()
{
// TODO: Add your command handler code here
// InitMxCubes();
m_xCube.Randomize(RANDSTEP);
InvalidateRect(&m_xCubeRect);
JudgeOK();
}
void CMxCubesView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int n;
static HCURSOR xSave = GetCursor();
for(n=0; n<9; n++)
{
if(!m_xCube.m_xClickOgram[n].PtInOgram(point)) continue;
没有合适的资源?快使用搜索试试~ 我知道了~
VC开发魔方游戏.zip
共35个文件
h:9个
cpp:8个
ico:5个
需积分: 5 0 下载量 57 浏览量
2024-09-21
11:10:00
上传
评论
收藏 37KB ZIP 举报
温馨提示
VC++6.0编写的游戏程序,供学习参考
资源推荐
资源详情
资源评论
收起资源包目录
VC开发魔方游戏.zip (35个子文件)
VC开发魔方游戏
新生代搜索工具条.url 275B
MxCubesDoc.cpp 2KB
WordBase.h 2KB
MxCubes.dsp 5KB
Cube.h 2KB
MxCubesView.h 3KB
MxCubesView.cpp 10KB
MxCubes.aps 29KB
MainFrm.cpp 2KB
各类原创教程下载.url 355B
MxCubes.cpp 4KB
res
front.cur 326B
MxCubesDoc.ico 1KB
MxCubes.ico 1KB
right.ico 766B
Toolbar.bmp 958B
up.ico 766B
MxCubes.rc2 399B
cursor1.cur 326B
front.ico 1KB
right.cur 326B
Resource.h 1008B
MxCubes.clw 2KB
MainFrm.h 1KB
MxCubes.h 1KB
MxCubes.dsw 539B
SetStepDlg.cpp 1KB
StdAfx.cpp 209B
WordBase.cpp 1KB
黑软天下.url 345B
MxCubes.rc 10KB
Cube.cpp 8KB
StdAfx.h 999B
MxCubesDoc.h 1KB
SetStepDlg.h 1KB
共 35 条
- 1
资源评论
fanxbl957
- 粉丝: 639
- 资源: 1135
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功