windows MFC——汉罗塔可视化移动程序
来源:互联网 发布:rx1r2 知乎 编辑:程序博客网 时间:2024/05/16 18:48
汉诺塔可视化移动过程
班级:计科1203班 姓名:杜杨浩 学号:2012310200707
问题描述:假设有三个塔座:X,Y,Z,在塔座X上有N个直径大小各不相同,按圆盘大小从小到大编号为1,2,…,N的圆盘。要求将X塔座上N个圆盘移动到塔座Z上,并仍按同样顺序叠排。圆盘移动时必须遵守下列规则:
(1) 每次只能移动一个圆盘
(2) 圆盘可以加到塔座X、Y、Z中任意一个上
(3) 任何时刻都不能将一个较大的圆盘放在较小的圆盘之上
要求将圆盘移动的整个过程用可视化图形的方式表现出来。
汉诺塔可视化移动过程设计说明书
一、需求分析:
该实验的核心目标就是将圆盘移动的整个过程用可视化的方式表现出来,具体的还有如下功能实现:
1) 设置圆盘的颜色和塔座的颜色(圆盘的边缘颜色与塔座颜色一致)
2) 设置圆盘的数量和圆盘的最大尺寸
3) 设置开始按钮和退出按钮,分别控制程序的开始和退出
4) 在圆盘整个移动过程结束后会弹出一个对话框,提示用户圆盘移动过程已结束,当用户点击弹出对话框确定按钮时,弹出对话框和原对话框均消失
二、系统模型:
该程序采用二维模型,用平面图形来表示三维物体。
三、界面设计:
该程序设置了6个下拉列表框用于分别设置圆盘的颜色和塔座的颜色。另设置了2个下拉列表框用于设置圆盘的数量和最大圆盘的尺寸。另附设两个按钮,分别为开始按钮和退出按钮。将每个塔座用英文字母代表以静态文本框的形式表现出来。上述是控件的界面设计,下面是核心的圆盘动态移动过程的界面设计:
首先,圆盘的每一次移动过程如下:假设现在是X——>Y(圆盘从塔座X移动到塔座Y),那么界面的显示顺序是这样的:
1) X塔座上去掉最顶层的圆盘后所剩圆盘的全部显示,X塔座上原最顶层的圆盘在X塔座的顶端(即表现出要离开X塔座),Y、Z塔座显示原有的所有圆盘。
2) X塔座上原最顶层的圆盘由X顶端移动到Y顶端,其它不变
3) X塔座上原最顶层的圆盘由Y塔座顶端移动到Y塔座上所有圆盘的最顶层,其它不变
这样圆盘的一次移动过程结束,每一次的移动过程都由诸如上述步骤顺序组合显示,这样整个移动过程就是每一次移动过程的累加了。最后当整个圆盘移动过程结束,会弹出一个对话框,提示用户圆盘移动过程已经结束。但用户点击弹出式对话框确定按钮时,弹出式对话框会关闭,并且原对话框也关闭,整个界面显示过程结束。
四、系统中重要类及方法的说明:
该程序设计中除了MFC自带的对话框类,我还设计了两个一般类,和一个对话框类。其中一般类和MFC自带对话框类的设计是关键,自行设计的对话框类只是为了作为弹出式对话框提示用户相关结束信息。下面主要讲解一下两个一般类和MFC自带的对话框类。
首先是两个一般类。分别为disk类和tazuo类。disk类即为圆盘类。有颜色和尺寸两类属性。对应方法有五个,分别为:
int Get_color_red(); //获取圆盘颜色RGB中的红色信息
int Get_color_green();//获取圆盘颜色RGB中的绿色信息
int Get_color_blue();//获取圆盘颜色RGB中的蓝色信息
void Set_digits(int size); //设置圆盘的半径
int Get_digits(); //获取圆盘的半径
而tazuo类的属性和方法相对较少。其属性为int cr,cg,cb;分别代表塔座颜色RGB中的R、G、B信息。对应的方法有三个,分别为:
int Get_color_red(); //获取塔座颜色RGB中的红色信息
int Get_color_green();//获取塔座颜色RGB中的绿色信息
int Get_color_blue();//获取塔座颜色RGB中的蓝色信息
接着详细介绍一下MFC自带的对话框类。在该类中我附加了如下属性:
bool paintbegin; //用于标识是否可以开始绘图
int diskred;//用于记录下拉列表框中圆盘颜色RGB值中的R信息
int diskgreen;// 用于记录下拉列表框中圆盘颜色RGB值中的G信息
int diskblue;// 用于记录下拉列表框中圆盘颜色RGB值中的B信息
int tazuored;// 用于记录下拉列表框中塔座颜色RGB值中的R信息
int tazuogreen;// 用于记录下拉列表框中塔座颜色RGB值中的G信息
int tazuoblue;// 用于记录下拉列表框中塔座颜色RGB值中的B信息
int disksize;//用于记录下拉列表框中最大圆盘的尺寸信息
int disknum;//用于记录下拉列表框中圆盘的个数信息
另外我还增加了一个方法:void Hanoi(int n,tower x,tower y,tower z);用于计算并保存圆盘移动过程中的每一步移动信息。(存放于相关的全局变量中)
最后我详细介绍一下程序整体的框架:首先利用Hanoi()函数计算出圆盘移动过程中的每一步移动信息并存于record[Maxx][2]中,移动次数存于transver_num中,然后创建用户指定个数(在下拉列表框中选择)的圆盘对象存于堆栈stax中(按半径从大到小的顺序入栈)以及队列Quex中(按半径从大到小的顺序入队)。设置计时器,在OnTimer中写刷新,在OnPaint中画图(圆盘移动过程)。
五、编写程序过程中出现的问题和解决方案
该程序设计中出现的主要问题可以归纳为如下三个。
第一:如何按照合理的顺序画一个塔座上所有的圆盘,以及移动的圆盘。不发生遗漏、多余和覆盖。
这里分别详细说明一下什么是覆盖、多余、和遗漏问题及相应的解决办法。
覆盖是指先画半径小的圆盘,后画半径大的圆盘,半径大的圆盘会覆盖半径小的圆盘,从而表现出半径小的圆盘不存在假象。怎么样才能不产生覆盖现象?
多余是指每一次移动都必有一个塔座失去最顶层的圆盘。那么怎么样处理失去最顶层圆盘,而不产生冗余错误?
遗漏是指每一次移动都必有一个塔座得到一个圆盘,并且这个圆盘会成为该塔座最顶层的圆盘。那么怎么样处理得到的圆盘并作为该塔座的最顶层圆盘而不产生遗漏的错误?
这三个问题看似独立,实质却相互关联。如何整体上把握这三个问题,用统一的方法解决就成为该程序的难点和重点了。经过不断的修改,得出了一个较为合理的解决方案:
为每个塔座创建一个堆栈sta和两个队列Que1,Que2(和程序中的标识符不同,仅作分析使用)。堆栈sta和队列Que1中都存放相应塔座的所有圆盘信息。不同的是出栈时,是按照圆盘半径从小到大的顺序。而出队时,是按照圆盘半径从大到小的顺序。利用队列实现将圆盘以半径从大到小的顺序绘制处理,解决覆盖问题。利用堆栈解决最顶层圆盘问题。具体例子如下:假设现在X——>Y(即圆盘从塔座X移动到塔座Y)。那么过程如下,首先利用Quez将塔座Z的所有圆盘非覆盖形式绘制处理。并存于Quezz队列中(以便后续还原)。然后利用堆栈stax在X塔座顶端绘制出X塔座最顶层的圆盘,并出栈。相应的利用队列Quex将除掉最顶层的所有圆盘非覆盖形式绘制处理,并存于队列Quexx中(以便后续还原)。接着在塔座Y的顶端绘制X塔座原顶层的圆盘,并利用Quey将塔座Y的所有圆盘非覆盖形式绘制处理,并存于队列Queyy中(以便后续还原)。这里要注意几个问题:
1) 在利用队列Quex将除X塔座最顶层的圆盘非覆盖形式绘制处理时,Quex的判断条件应为while(Quex.size()>1),而不应该while(!Quex.empty()),同时绘制处理结束后,队列Quex还要进行出队处理。因为塔座X要失去最顶层的圆盘,而最顶层的圆盘在堆栈stax的栈顶和队列Quex的队尾,这样就解决了多余的问题了。
2) 在利用队列Quez将塔座Z的所有圆盘非覆盖形式绘制处理之后还要进行两步操作。第一:将移动过来的圆盘入队列Quez;第二,将移动过来的圆盘入堆栈staz。这两步处理就是解决遗漏问题的。
下面是部分核心代码:
if(record[index][0]=='X' && record[index][1]=='Y'){
while(!Quez.empty()){
temp=Quez.front();
Quez.pop();
dc.Ellipse(330-temp.Get_digits(),200-temp.Get_digits(),330+temp.Get_digits(),200+temp.Get_digits());
Quezz.push(temp);
}
temp=stax.top();
stax.pop();
rec=temp;
dc.Ellipse(70-temp.Get_digits(),100-temp.Get_digits(),70+temp.Get_digits(),100+temp.Get_digits());
while(Quex.size()>1){
temp=Quex.front();
Quex.pop();
dc.Ellipse(70-temp.Get_digits(),200-temp.Get_digits(),70+temp.Get_digits(),200+temp.Get_digits());
Quexx.push(temp);
}
Quex.pop();
while(!Quey.empty()){
temp=Quey.front();
Quey.pop();
dc.Ellipse(200-temp.Get_digits(),200-temp.Get_digits(),200+temp.Get_digits(),200+temp.Get_digits());
Queyy.push(temp);
}
Sleep(1000);
dc.Ellipse(200-rec.Get_digits(),100-rec.Get_digits(),200+rec.Get_digits(),100+rec.Get_digits());
Sleep(1000);
dc.Ellipse(200-rec.Get_digits(),200-rec.Get_digits(),200+rec.Get_digits(),200+rec.Get_digits());
while(!Quezz.empty()){
Quez.push(Quezz.front());
Quezz.pop();
}
while(!Quexx.empty()){
Quex.push(Quexx.front());
Quexx.pop();
}
while(!Queyy.empty()){
Quey.push(Queyy.front());
Queyy.pop();
}
Quey.push(rec);
stay.push(rec);
}
第二:如何计算并保存圆盘移动的每一过程
这个问题的难度没有上面大,只需要一个递归函数就可以解决。下面是计算圆盘每个移动过程的递归函数:
void Hanoi(int n,tower x,tower y,tower z){
if(n){
Hanoi(n-1,x,z,y);
record[transver_num][0]=char(x);
record[transver_num++][1]=char(z);
Hanoi(n-1,y,x,z);
}
}
第三:刷新的时候控件总消失
这个问题,我想了很久,虽然是个小问题,但也值得。
这个问题产生的原因是每次都刷新的是整个对话框,因此控件都消失了,所以只要将刷新区域固定在画图区域,控件就不会消失了,即将代码:Invalidate();
改为:
RECT rect;
rect=CRect(40,70,360,250);
InvalidateRect(&rect,true);
下面是MFC(Dlg cpp代码)
// 大作业Dlg.cpp : implementation file//#include "stdafx.h"#include "大作业.h"#include "大作业Dlg.h"#include "MyNewDlg.h"#include "disk.h"#include "tazuo.h"#include <queue>#include <stack>using namespace std;#define Maxx 100#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CAboutDlg dialog used for App Aboutchar record[Maxx][2];int transver_num=0;int index;enum tower{A='X',B='Y',C='Z'};queue<disk> Quex;queue<disk> Quexx;queue<disk> Quey;queue<disk> Queyy;queue<disk> Quez;queue<disk> Quezz;stack<disk> stax;stack<disk> stay;stack<disk> staz;tazuo color;//===================void Hanoi(int n,tower x,tower y,tower z){if(n){Hanoi(n-1,x,z,y);record[transver_num][0]=char(x);record[transver_num++][1]=char(z);Hanoi(n-1,y,x,z);}}//================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// Implementationprotected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_MESSAGE_MAP()};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_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CMyDlg dialogCMyDlg::CMyDlg(CWnd* pParent /*=NULL*/): CDialog(CMyDlg::IDD, pParent){//{{AFX_DATA_INIT(CMyDlg)// NOTE: the ClassWizard will add member initialization here//}}AFX_DATA_INIT// Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}void CMyDlg::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CMyDlg)DDX_Control(pDX, IDC_COMBO8, m_combo8);DDX_Control(pDX, IDC_COMBO7, m_combo7);DDX_Control(pDX, IDC_COMBO6, m_combo6);DDX_Control(pDX, IDC_COMBO5, m_combo5);DDX_Control(pDX, IDC_COMBO4, m_combo4);DDX_Control(pDX, IDC_COMBO3, m_combo3);DDX_Control(pDX, IDC_COMBO2, m_combo2);DDX_Control(pDX, IDC_COMBO1, m_combo1);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CMyDlg, CDialog)//{{AFX_MSG_MAP(CMyDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON2, OnButton2)ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)ON_CBN_SELCHANGE(IDC_COMBO3, OnSelchangeCombo3)ON_CBN_SELCHANGE(IDC_COMBO4, OnSelchangeCombo4)ON_CBN_SELCHANGE(IDC_COMBO5, OnSelchangeCombo5)ON_CBN_SELCHANGE(IDC_COMBO6, OnSelchangeCombo6)ON_CBN_SELCHANGE(IDC_COMBO7, OnSelchangeCombo7)ON_CBN_SELCHANGE(IDC_COMBO8, OnSelchangeCombo8)ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_WM_TIMER()//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CMyDlg message handlersBOOL CMyDlg::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 dialogSetIcon(m_hIcon, TRUE);// Set big iconSetIcon(m_hIcon, FALSE);// Set small icon// TODO: Add extra initialization herem_combo1.AddString("0");m_combo1.AddString("125");m_combo1.AddString("255");m_combo2.AddString("0");m_combo2.AddString("125");m_combo2.AddString("255");m_combo3.AddString("0");m_combo3.AddString("125");m_combo3.AddString("255");m_combo4.AddString("0");m_combo4.AddString("125");m_combo4.AddString("255");m_combo5.AddString("0");m_combo5.AddString("125");m_combo5.AddString("255");m_combo6.AddString("0");m_combo6.AddString("125");m_combo6.AddString("255");m_combo7.AddString("2");m_combo7.AddString("3");m_combo7.AddString("4");m_combo8.AddString("15");m_combo8.AddString("20");m_combo8.AddString("25");tazuored=255;tazuogreen=0;tazuoblue=0;diskred=255;diskgreen=255;diskblue=255;disknum=2;disksize=20;paintbegin=0;return TRUE; // return TRUE unless you set the focus to a control}void CMyDlg::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 CMyDlg::OnPaint() {CPaintDC dc(this);CPen pen;CBrush brush;if(paintbegin){ pen.CreatePen(PS_SOLID,1,RGB(color.Get_color_red(),color.Get_color_green(),color.Get_color_blue()));dc.SelectObject(pen); //这里将塔座颜色和圆盘边缘颜色设为同一颜色 dc.MoveTo(70,100);dc.LineTo(70,200);dc.MoveTo(200,100);dc.LineTo(200,200);dc.MoveTo(330,100);dc.LineTo(330,200);brush.CreateSolidBrush(RGB(diskred,diskgreen,diskblue));dc.SelectObject(brush);disk temp,rec;if(record[index][0]=='X' && record[index][1]=='Y'){while(!Quez.empty()){temp=Quez.front();Quez.pop();dc.Ellipse(330-temp.Get_digits(),200-temp.Get_digits(),330+temp.Get_digits(),200+temp.Get_digits());Quezz.push(temp);}temp=stax.top();stax.pop(); rec=temp;dc.Ellipse(70-temp.Get_digits(),100-temp.Get_digits(),70+temp.Get_digits(),100+temp.Get_digits());while(Quex.size()>1){temp=Quex.front();Quex.pop();dc.Ellipse(70-temp.Get_digits(),200-temp.Get_digits(),70+temp.Get_digits(),200+temp.Get_digits());Quexx.push(temp);}Quex.pop();while(!Quey.empty()){temp=Quey.front();Quey.pop();dc.Ellipse(200-temp.Get_digits(),200-temp.Get_digits(),200+temp.Get_digits(),200+temp.Get_digits());Queyy.push(temp);}Sleep(1000);dc.Ellipse(200-rec.Get_digits(),100-rec.Get_digits(),200+rec.Get_digits(),100+rec.Get_digits());Sleep(1000);dc.Ellipse(200-rec.Get_digits(),200-rec.Get_digits(),200+rec.Get_digits(),200+rec.Get_digits());while(!Quezz.empty()){Quez.push(Quezz.front());Quezz.pop();}while(!Quexx.empty()){Quex.push(Quexx.front());Quexx.pop();}while(!Queyy.empty()){Quey.push(Queyy.front());Queyy.pop();}Quey.push(rec);stay.push(rec);} else if(record[index][0]=='X' && record[index][1]=='Z'){while(!Quey.empty()){temp=Quey.front();Quey.pop();dc.Ellipse(200-temp.Get_digits(),200-temp.Get_digits(),200+temp.Get_digits(),200+temp.Get_digits());Queyy.push(temp);}temp=stax.top();stax.pop(); rec=temp;dc.Ellipse(70-temp.Get_digits(),100-temp.Get_digits(),70+temp.Get_digits(),100+temp.Get_digits());while(Quex.size()>1){temp=Quex.front();Quex.pop();dc.Ellipse(70-temp.Get_digits(),200-temp.Get_digits(),70+temp.Get_digits(),200+temp.Get_digits());Quexx.push(temp);}Quex.pop();while(!Quez.empty()){temp=Quez.front();Quez.pop();dc.Ellipse(330-temp.Get_digits(),200-temp.Get_digits(),330+temp.Get_digits(),200+temp.Get_digits());Quezz.push(temp);}Sleep(1000);dc.Ellipse(330-rec.Get_digits(),100-rec.Get_digits(),330+rec.Get_digits(),100+rec.Get_digits());Sleep(1000);dc.Ellipse(330-rec.Get_digits(),200-rec.Get_digits(),330+rec.Get_digits(),200+rec.Get_digits());while(!Queyy.empty()){Quey.push(Queyy.front());Queyy.pop();}while(!Quexx.empty()){Quex.push(Quexx.front());Quexx.pop();}while(!Quezz.empty()){Quez.push(Quezz.front());Quezz.pop();}Quez.push(rec);staz.push(rec);}else if(record[index][0]=='Y' && record[index][1]=='Z'){while(!Quex.empty()){temp=Quex.front();Quex.pop();dc.Ellipse(70-temp.Get_digits(),200-temp.Get_digits(),70+temp.Get_digits(),200+temp.Get_digits());Quexx.push(temp);}temp=stay.top();stay.pop(); rec=temp;dc.Ellipse(200-temp.Get_digits(),100-temp.Get_digits(),200+temp.Get_digits(),100+temp.Get_digits());while(Quey.size()>1){temp=Quey.front();Quey.pop();dc.Ellipse(200-temp.Get_digits(),200-temp.Get_digits(),200+temp.Get_digits(),200+temp.Get_digits());Queyy.push(temp);}Quey.pop();while(!Quez.empty()){temp=Quez.front();Quez.pop();dc.Ellipse(330-temp.Get_digits(),200-temp.Get_digits(),330+temp.Get_digits(),200+temp.Get_digits());Quezz.push(temp);}Sleep(1000);dc.Ellipse(330-rec.Get_digits(),100-rec.Get_digits(),330+rec.Get_digits(),100+rec.Get_digits());Sleep(1000);dc.Ellipse(330-rec.Get_digits(),200-rec.Get_digits(),330+rec.Get_digits(),200+rec.Get_digits());while(!Quexx.empty()){Quex.push(Quexx.front());Quexx.pop();}while(!Queyy.empty()){Quey.push(Queyy.front());Queyy.pop();}while(!Quezz.empty()){Quez.push(Quezz.front());Quezz.pop();}Quez.push(rec);staz.push(rec);}else if(record[index][0]=='Y' && record[index][1]=='X'){while(!Quez.empty()){temp=Quez.front();Quez.pop();dc.Ellipse(330-temp.Get_digits(),200-temp.Get_digits(),330+temp.Get_digits(),200+temp.Get_digits());Quezz.push(temp);}temp=stay.top();stay.pop(); rec=temp;dc.Ellipse(200-temp.Get_digits(),100-temp.Get_digits(),200+temp.Get_digits(),100+temp.Get_digits());while(Quey.size()>1){temp=Quey.front();Quey.pop();dc.Ellipse(200-temp.Get_digits(),200-temp.Get_digits(),200+temp.Get_digits(),200+temp.Get_digits());Queyy.push(temp);}Quey.pop();while(!Quex.empty()){temp=Quex.front();Quex.pop();dc.Ellipse(70-temp.Get_digits(),200-temp.Get_digits(),70+temp.Get_digits(),200+temp.Get_digits());Quexx.push(temp);}Sleep(1000);dc.Ellipse(70-rec.Get_digits(),100-rec.Get_digits(),70+rec.Get_digits(),100+rec.Get_digits());Sleep(1000);dc.Ellipse(70-rec.Get_digits(),200-rec.Get_digits(),70+rec.Get_digits(),200+rec.Get_digits());while(!Quezz.empty()){Quez.push(Quezz.front());Quezz.pop();}while(!Queyy.empty()){Quey.push(Queyy.front());Queyy.pop();}while(!Quexx.empty()){Quex.push(Quexx.front());Quexx.pop();}Quex.push(rec);stax.push(rec);}else if(record[index][0]=='Z' && record[index][1]=='X'){while(!Quey.empty()){temp=Quey.front();Quey.pop();dc.Ellipse(200-temp.Get_digits(),200-temp.Get_digits(),200+temp.Get_digits(),200+temp.Get_digits());Queyy.push(temp);}temp=staz.top();staz.pop(); rec=temp;dc.Ellipse(330-temp.Get_digits(),100-temp.Get_digits(),330+temp.Get_digits(),100+temp.Get_digits());while(Quez.size()>1){temp=Quez.front();Quez.pop();dc.Ellipse(330-temp.Get_digits(),200-temp.Get_digits(),330+temp.Get_digits(),200+temp.Get_digits());Quezz.push(temp);}Quez.pop();while(!Quex.empty()){temp=Quex.front();Quex.pop();dc.Ellipse(70-temp.Get_digits(),200-temp.Get_digits(),70+temp.Get_digits(),200+temp.Get_digits());Quexx.push(temp);}Sleep(1000);dc.Ellipse(70-rec.Get_digits(),100-rec.Get_digits(),70+rec.Get_digits(),100+rec.Get_digits());Sleep(1000);dc.Ellipse(70-rec.Get_digits(),200-rec.Get_digits(),70+rec.Get_digits(),200+rec.Get_digits());while(!Queyy.empty()){Quey.push(Queyy.front());Queyy.pop();}while(!Quezz.empty()){Quez.push(Quezz.front());Quezz.pop();}while(!Quexx.empty()){Quex.push(Quexx.front());Quexx.pop();}Quex.push(rec);stax.push(rec);}else if(record[index][0]=='Z' && record[index][1]=='Y'){while(!Quex.empty()){temp=Quex.front();Quex.pop();dc.Ellipse(70-temp.Get_digits(),200-temp.Get_digits(),70+temp.Get_digits(),200+temp.Get_digits());Quexx.push(temp);}temp=staz.top();staz.pop(); rec=temp;dc.Ellipse(330-temp.Get_digits(),100-temp.Get_digits(),330+temp.Get_digits(),100+temp.Get_digits());while(Quez.size()>1){temp=Quez.front();Quez.pop();dc.Ellipse(330-temp.Get_digits(),200-temp.Get_digits(),330+temp.Get_digits(),200+temp.Get_digits());Quezz.push(temp);}Quez.pop();while(!Quey.empty()){temp=Quey.front();Quey.pop();dc.Ellipse(200-temp.Get_digits(),200-temp.Get_digits(),200+temp.Get_digits(),200+temp.Get_digits());Queyy.push(temp);}Sleep(1000);dc.Ellipse(200-rec.Get_digits(),100-rec.Get_digits(),200+rec.Get_digits(),100+rec.Get_digits());Sleep(1000);dc.Ellipse(200-rec.Get_digits(),200-rec.Get_digits(),200+rec.Get_digits(),200+rec.Get_digits());while(!Quexx.empty()){Quex.push(Quexx.front());Quexx.pop();}while(!Quezz.empty()){Quez.push(Quezz.front());Quezz.pop();}while(!Queyy.empty()){Quey.push(Queyy.front());Queyy.pop();}Quey.push(rec);stay.push(rec);}Sleep(1000);if(index==transver_num){KillTimer(0);CMyNewDlg dlg; dlg.DoModal();OnOK();}}pen.DeleteObject();brush.DeleteObject();CDialog::OnPaint();}// The system calls this to obtain the cursor to display while the user drags// the minimized window.HCURSOR CMyDlg::OnQueryDragIcon(){return (HCURSOR) m_hIcon;}void CMyDlg::OnButton2() {// TODO: Add your control notification handler code hereOnOK();}void CMyDlg::OnSelchangeCombo1() {// TODO: Add your control notification handler code hereif(m_combo1.GetCurSel()==0)diskred=0;else if(m_combo1.GetCurSel()==1)diskred=125;else if(m_combo1.GetCurSel()==2)diskred=255;}void CMyDlg::OnSelchangeCombo2() {// TODO: Add your control notification handler code hereif(m_combo2.GetCurSel()==0)diskgreen=0;else if(m_combo2.GetCurSel()==1)diskgreen=125;else if(m_combo2.GetCurSel()==2)diskgreen=255;}void CMyDlg::OnSelchangeCombo3() {// TODO: Add your control notification handler code hereif(m_combo3.GetCurSel()==0)diskblue=0;else if(m_combo3.GetCurSel()==1)diskblue=125;else if(m_combo3.GetCurSel()==2) diskblue=255;}void CMyDlg::OnSelchangeCombo4() {// TODO: Add your control notification handler code hereif(m_combo4.GetCurSel()==0)tazuored=0;else if(m_combo4.GetCurSel()==1)tazuored=125;else if(m_combo4.GetCurSel()==2) tazuored=255;}void CMyDlg::OnSelchangeCombo5() {// TODO: Add your control notification handler code hereif(m_combo5.GetCurSel()==0)tazuogreen=0;else if(m_combo5.GetCurSel()==1)tazuogreen=125;else if(m_combo5.GetCurSel()==2) tazuogreen=255;}void CMyDlg::OnSelchangeCombo6() {// TODO: Add your control notification handler code hereif(m_combo6.GetCurSel()==0)tazuoblue=0;else if(m_combo6.GetCurSel()==1)tazuoblue=125;else if(m_combo6.GetCurSel()==2) tazuoblue=255;}void CMyDlg::OnSelchangeCombo7() {// TODO: Add your control notification handler code hereif(m_combo7.GetCurSel()==0)disknum=2;else if(m_combo7.GetCurSel()==1)disknum=3;else if(m_combo7.GetCurSel()==2) disknum=4;}void CMyDlg::OnSelchangeCombo8() {// TODO: Add your control notification handler code hereif(m_combo8.GetCurSel()==0)disksize=15;else if(m_combo8.GetCurSel()==1)disksize=20;else if(m_combo8.GetCurSel()==2) disksize=25;}void CMyDlg::OnButton1() {// TODO: Add your control notification handler code hereHanoi(disknum,A,B,C);color.Set_color(tazuored,tazuogreen,tazuoblue);int dec=2;int i;disk temp;for(i=0;i<disknum;i++){temp.Set_color(diskred,diskgreen,diskblue); temp.Set_digits(disksize-i*dec);Quex.push(temp);stax.push(temp);}paintbegin=true;index=-1;SetTimer(0,1000,NULL);}void CMyDlg::OnTimer(UINT nIDEvent) {//OnTimer(0);// TODO: Add your message handler code here and/or call defaultif(index<transver_num){index++;RECT rect; rect=CRect(40,70,360,250); InvalidateRect(&rect,true);}CDialog::OnTimer(nIDEvent);}
- windows MFC——汉罗塔可视化移动程序
- 学习MFC第二天——第一个Windows程序
- MFC——1.浅谈Windows程序内部运行机制
- 最简单的windows程序——MFC版本
- MFC(一)——Windows程序内部运行原理
- MFC学习笔记(1)——Windows程序基础
- MFC入门——简单的Windows图形界面小程序
- matplotlib 可视化 —— 移动坐标轴(中心位置)
- mfc笔记: 《MFC Windows程序设计》Shape程序
- 调试一个MFC的点云可视化(PCL)程序
- MFC应用SkinMagic皮肤可视化包更换程序外观皮肤
- windows程序及MFC简介
- Windows-MFC框架程序剖析
- 如何在非MFC程序中使用MFC类——解决#error : WINDOWS.H already included.
- winform程序—窗体移动
- vc++ win32程序中使用MFC——防止重复引用windows.h错误
- MFC学习笔记(2)——Windows程序的类封装 上
- MFC学习笔记(3)——Windows程序类的封装 中
- houoj2048神、上帝以及老天爷
- HDU1879
- 考虑一个线性地址转换物理地址的过程
- hdu2192 MagicBuilding
- HDU1150/POJ1325_Machine Schedule(二分图/最小点覆盖=最大匹配)
- windows MFC——汉罗塔可视化移动程序
- 创建前台Service
- wiki 1257 打砖块
- 仿函数(functors)
- sql截取特殊字符分隔开的字串
- The Suspects poj
- OCP 1Z0 053 210
- asp.net 分页
- 解决MyEclipse内存不足