📄 4_1view.cpp
字号:
// 4_1View.cpp : implementation of the CMy4_1View class
//
#include "stdafx.h"
#include "4_1.h"
#include "4_1Doc.h"
#include "4_1View.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy4_1View
IMPLEMENT_DYNCREATE(CMy4_1View, CView)
BEGIN_MESSAGE_MAP(CMy4_1View, CView)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CMy4_1View)
ON_COMMAND(ID_MENU_START, OnMenuStart)
ON_WM_TIMER()
ON_WM_KEYDOWN()
ON_COMMAND(ID_MENU_PAUSE, OnMenuPause)
ON_UPDATE_COMMAND_UI(ID_MENU_PAUSE, OnUpdateMenuPause)
ON_COMMAND(ID_VIEW_1, OnView1)
ON_COMMAND(ID_VIEW_2, OnView2)
ON_UPDATE_COMMAND_UI(ID_VIEW_1, OnUpdateView1)
ON_UPDATE_COMMAND_UI(ID_VIEW_2, OnUpdateView2)
ON_COMMAND(ID_MENU_DSTART, OnMenuDstart)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_MENU_TSTART, OnMenuTstart)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMy4_1View construction/destruction
CMy4_1View::CMy4_1View()
{
// TODO: add construction code here
fenmian.LoadBitmap(IDB_BITMAP1);
for(int i=0;i<3;i++)
xuanze[i].LoadBitmap(IDB_BITMAP7+i);
start=false;
m_bPause=false;
view=1;
player=1;
ixuanze=1;
}
CMy4_1View::~CMy4_1View()
{
}
BOOL CMy4_1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMy4_1View drawing
void CMy4_1View::OnDraw(CDC* pDC)
{
AfxGetMainWnd()->CenterWindow();
CMy4_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDC Dc;
if(Dc.CreateCompatibleDC(pDC)==FALSE)
AfxMessageBox("Can't create DC");
//没有开始,显示封面
if( !start)
{
Dc.SelectObject(fenmian);
pDC->BitBlt(0,0,500,550,&Dc,0,0,SRCCOPY);
Dc.SelectObject(xuanze[ixuanze-1]);
pDC->BitBlt(200,350,150,150,&Dc,0,0,SRCCOPY);
}
//显示背景
else
{
if(view==1)
{
if(player==1)
russia.DrawJiemian1(0,0,pDC);
if(player==2)
{
russia.DrawJiemian1(500,0,pDC);
russia2.DrawJiemian1(0,0,pDC);
}
}
if(view==2)
{
if(player==1)
russia.DrawJiemian2(0,0,pDC);
if(player==2)
{
russia.DrawJiemian2(253,0,pDC);
russia2.DrawJiemian2(0,0,pDC);
}
}
if(player==3)
russia0.DrawJiemian(pDC);
}
}
/////////////////////////////////////////////////////////////////////////////
// CMy4_1View printing
BOOL CMy4_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy4_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy4_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy4_1View diagnostics
#ifdef _DEBUG
void CMy4_1View::AssertValid() const
{
CView::AssertValid();
}
void CMy4_1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy4_1Doc* CMy4_1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy4_1Doc)));
return (CMy4_1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMy4_1View message handlers
void CMy4_1View::OnMenuStart()
{
// TODO: Add your command handler code here
if(view==1)
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,500,590,SWP_NOMOVE|SWP_NOZORDER );
if(view==2)
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,253,510,SWP_NOMOVE|SWP_NOZORDER );
player=1;
start=true;
russia.Start();
SetTimer(1,50*(11-russia.m_Speed ),NULL);
}
void CMy4_1View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//下移
if(player==1)
russia.Move(3);
if(player==2)
{
russia.Move(3);
russia2.Move(3);
}
if(player==3)
{
russia0.Move(3);
russia0.Move(7);
}
OnDraw(GetDC());
CView::OnTimer(nIDEvent);
}
void CMy4_1View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
//没有开始
if(!start)
{
CRect rect;
rect.left=170;
rect.top=330;
rect.right=340;
rect.bottom=450;
if(nChar==VK_DOWN)
{
if(ixuanze<3)
ixuanze++;
else
ixuanze=1;
InvalidateRect(&rect);
}
if(nChar==VK_UP)
{
if(ixuanze>1)
ixuanze--;
else
ixuanze=3;
InvalidateRect(&rect);
}
if(nChar==VK_SPACE)
{
if(ixuanze==1)
OnMenuStart();
if(ixuanze==2)
OnMenuDstart();
if(ixuanze==3)
OnMenuTstart();
}
return;
}
//暂停
if(m_bPause==TRUE)
return;
switch(nChar)
{
case VK_LEFT:
russia.Move(1);russia0.Move(5);
break;
case VK_RIGHT:
russia.Move(2);russia0.Move(6);
break;
case VK_UP:
russia.Move(4);russia0.Move(8);
break;
case VK_DOWN:
russia.Move(3); russia0.Move(7);
break;
case 65:
russia2.Move(1);russia0.Move(1);
break;
case 68:
russia2.Move(2);russia0.Move(2);
break;
case 87:
russia2.Move(4);russia0.Move(4);
break;
case 83:
russia2.Move(3);russia0.Move(3);
break;
}
//重画
OnDraw(GetDC());
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CMy4_1View::OnMenuPause()
{
// TODO: Add your command handler code here
m_bPause=!m_bPause;
if(m_bPause)
KillTimer(1);
else
SetTimer(1,50*(11-russia.m_Speed ),NULL);
}
void CMy4_1View::OnUpdateMenuPause(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bPause);
}
void CMy4_1View::OnView1()
{
// TODO: Add your command handler code here
if(player==3)return;
view=1;
//调整窗口大小
if(player==1)
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,500,590,SWP_NOMOVE|SWP_NOZORDER );
if(player==2)
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,1000,590,SWP_NOMOVE|SWP_NOZORDER );
}
void CMy4_1View::OnView2()
{
// TODO: Add your command handler code here
if(player==3)return;
view=2;
if(!start)
return;
//调整窗口大小
if(player==1)
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,253,510,SWP_NOMOVE|SWP_NOZORDER );
if(player==2)
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,510,510,SWP_NOMOVE|SWP_NOZORDER );
}
void CMy4_1View::OnUpdateView1(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(view==1);
}
void CMy4_1View::OnUpdateView2(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(view==2);
}
void CMy4_1View::OnMenuDstart()
{
// TODO: Add your command handler code here
if(view==1)
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,1000,590,SWP_NOMOVE|SWP_NOZORDER );
if(view==2)
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,510,510,SWP_NOMOVE|SWP_NOZORDER );
player=2;
start=true;
russia.Start();
Sleep(300);
russia2.Start();
SetTimer(1,50*(11-russia.m_Speed ),NULL);
}
void CMy4_1View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(point.x>200&&point.x<340&&point.y>350&&point.y<450)
{
if(ixuanze==1)
OnMenuStart();
if(ixuanze==2)
OnMenuDstart();
if(ixuanze==3)
OnMenuTstart();
}
CView::OnLButtonDown(nFlags, point);
}
void CMy4_1View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(start)
return;
CRect rect;
rect.left=170;
rect.top=330;
rect.right=340;
rect.bottom=450;
if(point.x>200&&point.x<350)
{
if(point.y>350&&point.y<380)
{
if(ixuanze!=1)
{
ixuanze=1;
InvalidateRect(&rect);
}
}
if(point.y>380&&point.y<410)
if(ixuanze!=2)
{
ixuanze=2;
InvalidateRect(&rect);
}
if(point.y>410&&point.y<440)
if(ixuanze!=3)
{
ixuanze=3;
InvalidateRect(&rect);
}
}
CView::OnMouseMove(nFlags, point);
}
void CMy4_1View::OnMenuTstart()
{
// TODO: Add your command handler code here
// AfxMessageBox("还没有完成!");
AfxGetMainWnd() ->SetWindowPos(NULL,0,0,513,650,SWP_NOMOVE|SWP_NOZORDER );
player=3;
start=true;
russia0.Start();
SetTimer(1,50*(11-russia0.m_Speed ),NULL);
}
void CMy4_1View::OnContextMenu(CWnd*, CPoint point)
{
if(!start)
return; // CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_MY4_1_VIEW)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -