模拟智能交通信号灯系统
设计一个智能信号灯系统,在十字路口控制东西南北四个方向交通信号,当然是红灯停绿灯行了,一般情况是四个方向每次绿灯亮30秒,只不过在绿灯熄灭后亮3秒黄灯再转红灯。现要求系统能够根据各个方向路口来的车流情况动态分配信号灯在来车多的方向绿灯可以綖长30秒时间,为此在各个路口设有车流信号统计器,可以向系统动态发送车流信息。
#include<iostream>
#include "stdafx.h"
#include "33.h"
#include "33Dlg.h"
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
CMy33Dlg::CMy33Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy33Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy33Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDOK, m_a);
}
BEGIN_MESSAGE_MAP(CMy33Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()
BOOL CMy33Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
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);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
return TRUE;
}
void CMy33Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CMy33Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
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;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this);
static int t;
t++;
CPen pGrayPen(PS_SOLID, 0, RGB(0,0,0));
CPen pPen(PS_DASH, 0, RGB(0,0,0));
CBrush brush(RGB(0,0,0));
CBrush greenbrush(RGB(0,255,0));
CBrush redbrush(RGB(255,0,0));
CBrush yellowbrush(RGB(255,255,0));
dc.SelectObject(pGrayPen);
dc.MoveTo(200,30);
dc.LineTo(200,150);
dc.MoveTo(30,150);
dc.LineTo(200,150);
dc.MoveTo(30,350);
dc.LineTo(200,350);
dc.MoveTo(200,350);
dc.LineTo(200,470);
dc.MoveTo(400,30);
dc.LineTo(400,150);
dc.MoveTo(570,150);
dc.LineTo(400,150);
dc.MoveTo(570,350);
dc.LineTo(400,350);
dc.MoveTo(400,470);
dc.LineTo(400,350);
dc.SelectObject(pPen);
dc.MoveTo(300,470);
dc.LineTo(300,350);
dc.MoveTo(30,250);
dc.LineTo(200,250);
dc.MoveTo(300,30);
dc.LineTo(300,150);
dc.MoveTo(400,250);
dc.LineTo(570,250);
dc.TextOut(50,50,"N");
dc.SelectObject(pGrayPen);
int time;
time=(t/100)%18; int z;
static int x[20];
if(18-time>=10)
{
char str[8];
sprintf(str,"倒计时%0d",18-time);
dc.TextOut(224,40,str,8);
}
if(18-time<10)
{
char str[8];
sprintf(str,"倒计时%0d",18-time);
dc.TextOut(224,40,str,7);
}
if(t==1)
{
x[0]=200-(rand()%(75-50)+50);
for( z=0;z<9;z++)
{
x[z+1]=x[z]-(rand()%(250-100)+100);
}
};
if(time<6)
{
dc.SelectObject (&greenbrush);
dc.Ellipse(170,350,200,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z=0;z<10;z++)
{
dc.Rectangle(x[z],315,x[z]+60,275);
x[z]=x[z]+3;
if(x[z]>600)
{
if(z==0)
x[z]=x[9]-(rand()%(250-100)+100);
else
x[z]=x[z-1]-(rand()%(250-100)+100);
}
}
}
else
if(time>=6&&time<12)
{
dc.SelectObject(&yellowbrush);
dc.Ellipse(170,350,200,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z=0;z<10;z++)
{
if(x[z]+60>200)
{
dc.Rectangle(x[z],315,x[z]+60,275);
x[z]=x[z]+3;
if(x[z]>600)
{
if(z==0)
x[z]=x[9]-(rand()%(250-100)+100);
else
x[z]=x[z-1]-(rand()%(250-100)+100);
}
}
else
dc.Rectangle(x[z],315,x[z]+60,275);
}
}
else
{
dc.SelectObject(&redbrush);
dc.Ellipse(170,350,200,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z=0;z<10;z++)
{
if(x[z]+60>200)
{
dc.Rectangle(x[z],315,x[z]+60,275);
x[z]=x[z]+3;
if(x[z]>600)
{
if(z==0)
x[z]=x[9]-(rand()%(250-100)+100);
else
x[z]=x[z-1]-(rand()%(250-100)+100);
}
}
dc.Rectangle(x[z],315,x[z]+60,275);
}
}
static int x1[20];
int z1;
if(t==1)
{
x1[0]=400+(rand()%(75-50)+50);
for( z1=0;z1<9;z1++)
{
x1[z1+1]=x1[z1]+(rand()%(250-100)+100);
}
};
if(time<6)
{
dc.SelectObject (&greenbrush);
dc.Ellipse(400,120,430,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z1=0;z1<10;z1++)
{
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
x1[z1]=x1[z1]-3;
if(x1[z1]<0)
{
if(z1==0)
x1[z1]=x1[9]+(rand()%(250-100)+100);
else
x1[z1]=x1[z1-1]+(rand()%(250-100)+100);
}
}
}
else
if(time>=6&&time<12)
{
dc.SelectObject(&yellowbrush);
dc.Ellipse(400,120,430,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z1=0;z1<10;z1++)
{
if(x1[z1]<400)
{
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
x1[z1]=x1[z1]-3;
if(x1[z1]<0)
{
if(z1==0)
x1[z1]=x1[9]+(rand()%(250-100)+100);
else
x1[z1]=x1[z1-1]+(rand()%(250-100)+100);
}
}
else
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
}
}
else
{
dc.SelectObject(&redbrush);
dc.Ellipse(400,120,430,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z1=0;z1<10;z1++)
{
if(x1[z1]<400)
{
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
x1[z1]=x1[z1]-3;
if(x1[z1]<0)
{
if(z1==0)
x1[z1]=x1[9]+(rand()%(250-100)+100);
else
x1[z1]=x1[z1-1]+(rand()%(250-100)+100);
}
}
else
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
}
}
static int x2[20];
int z2;
if(t==1)
{
x2[0]=150-(rand()%(75-50)+50);
for( z2=0;z2<9;z2++)
{
x2[z2+1]=x2[z2]-(rand()%(250-100)+100);
}
};
if(time<6)
{
dc.SelectObject(&redbrush);
dc.Ellipse(170,120,200,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z2=0;z2<10;z2++)
{
if(x2[z2]>150)
{
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
x2[z2]=x2[z2]+3;
if(x2[z2]>500)
{
if(z2==0)
x2[z2]=x2[9]-(rand()%(250-100)+100);
else
x2[z2]=x2[z2-1]-(rand()%(250-100)+100);
}
}
else
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
}
}
else
if(time>=6&&time<12)
{
dc.SelectObject (&greenbrush);
dc.Ellipse(170,120,200,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z2=0;z2<10;z2++)
{
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
x2[z2]=x2[z2]+3;
if(x2[z2]>500)
{
if(z2==0)
x2[z2]=x2[9]-(rand()%(250-100)+100);
else
x2[z2]=x2[z2-1]-(rand()%(250-100)+100);
}
}
}
else
{
dc.SelectObject(&yellowbrush);
dc.Ellipse(170,120,200,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z2=0;z2<10;z2++)
{
if(x2[z2]>150)
{
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
x2[z2]=x2[z2]+3;
if(x2[z2]>500)
{
if(z2==0)
x2[z2]=x2[9]-(rand()%(250-100)+100);
else
x2[z2]=x2[z2-1]-(rand()%(250-100)+100);
}
//x[z]=x[(z+9)%9]+(rand()%(250-100)+100);
}
else
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
}
}
static int x3[20];
int z3;
if(t==1)
{
x3[0]=350+(rand()%(75-50)+50);
for( z3=0;z3<9;z3++)
{
x3[z3+1]=x3[z3]+(rand()%(250-100)+100);
}
};
if(time<6)
{
dc.SelectObject(&redbrush);
dc.Ellipse(400,350,430,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z3=0;z3<10;z3++)
{
if(x3[z3]-60<350)
{
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
x3[z3]=x3[z3]-3;
if(x3[z3]-60<0)
{
if(z3==0)
x3[z3]=x3[9]+(rand()%(250-100)+100);
else
x3[z3]=x3[z3-1]+(rand()%(250-100)+100);
}
}
else
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
}
}
else
if(time>=6&&time<12)
{
dc.SelectObject (&greenbrush);
dc.Ellipse(400,350,430,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z3=0;z3<10;z3++)
{
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
x3[z3]=x3[z3]-3;
if(x3[z3]-60<0)
{
if(z3==0)
x3[z3]=x3[9]+(rand()%(250-100)+100);
else
x3[z3]=x3[z3-1]+(rand()%(250-100)+100);
}
}
}
else
{
dc.SelectObject(&yellowbrush);
dc.Ellipse(400,350,430,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z3=0;z3<10;z3++)
{
if(x3[z3]-60<350)
{
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
x3[z3]=x3[z3]-3;
if(x3[z3]-60<0)
{
if(z3==0)
x3[z3]=x3[9]+(rand()%(250-100)+100);
else
x3[z3]=x3[z3-1]+(rand()%(250-100)+100);
}
}
else
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
}
}
CRect rect;
GetClientRect(&rect);
CRect rect1(0,120,rect.Width(),380);
CRect rect2(200,0,400,rect.Height());
Sleep(10);
if(m%2==0)
{
InvalidateRect(rect1,1);
InvalidateRect(rect2,1);
}
}
}
HCURSOR CMy33Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy33Dlg::OnCancel()
{
CDialog::OnCancel();
}
#include<iostream>
#include "stdafx.h"
#include "33.h"
#include "33Dlg.h"
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
CMy33Dlg::CMy33Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy33Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy33Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDOK, m_a);
}
BEGIN_MESSAGE_MAP(CMy33Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()
BOOL CMy33Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
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);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
return TRUE;
}
void CMy33Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CMy33Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
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;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this);
static int t;
t++;
CPen pGrayPen(PS_SOLID, 0, RGB(0,0,0));
CPen pPen(PS_DASH, 0, RGB(0,0,0));
CBrush brush(RGB(0,0,0));
CBrush greenbrush(RGB(0,255,0));
CBrush redbrush(RGB(255,0,0));
CBrush yellowbrush(RGB(255,255,0));
dc.SelectObject(pGrayPen);
dc.MoveTo(200,30);
dc.LineTo(200,150);
dc.MoveTo(30,150);
dc.LineTo(200,150);
dc.MoveTo(30,350);
dc.LineTo(200,350);
dc.MoveTo(200,350);
dc.LineTo(200,470);
dc.MoveTo(400,30);
dc.LineTo(400,150);
dc.MoveTo(570,150);
dc.LineTo(400,150);
dc.MoveTo(570,350);
dc.LineTo(400,350);
dc.MoveTo(400,470);
dc.LineTo(400,350);
dc.SelectObject(pPen);
dc.MoveTo(300,470);
dc.LineTo(300,350);
dc.MoveTo(30,250);
dc.LineTo(200,250);
dc.MoveTo(300,30);
dc.LineTo(300,150);
dc.MoveTo(400,250);
dc.LineTo(570,250);
dc.TextOut(50,50,"N");
dc.SelectObject(pGrayPen);
int time;
time=(t/100)%18; int z;
static int x[20];
if(18-time>=10)
{
char str[8];
sprintf(str,"倒计时%0d",18-time);
dc.TextOut(224,40,str,8);
}
if(18-time<10)
{
char str[8];
sprintf(str,"倒计时%0d",18-time);
dc.TextOut(224,40,str,7);
}
if(t==1)
{
x[0]=200-(rand()%(75-50)+50);
for( z=0;z<9;z++)
{
x[z+1]=x[z]-(rand()%(250-100)+100);
}
};
if(time<6)
{
dc.SelectObject (&greenbrush);
dc.Ellipse(170,350,200,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z=0;z<10;z++)
{
dc.Rectangle(x[z],315,x[z]+60,275);
x[z]=x[z]+3;
if(x[z]>600)
{
if(z==0)
x[z]=x[9]-(rand()%(250-100)+100);
else
x[z]=x[z-1]-(rand()%(250-100)+100);
}
}
}
else
if(time>=6&&time<12)
{
dc.SelectObject(&yellowbrush);
dc.Ellipse(170,350,200,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z=0;z<10;z++)
{
if(x[z]+60>200)
{
dc.Rectangle(x[z],315,x[z]+60,275);
x[z]=x[z]+3;
if(x[z]>600)
{
if(z==0)
x[z]=x[9]-(rand()%(250-100)+100);
else
x[z]=x[z-1]-(rand()%(250-100)+100);
}
}
else
dc.Rectangle(x[z],315,x[z]+60,275);
}
}
else
{
dc.SelectObject(&redbrush);
dc.Ellipse(170,350,200,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z=0;z<10;z++)
{
if(x[z]+60>200)
{
dc.Rectangle(x[z],315,x[z]+60,275);
x[z]=x[z]+3;
if(x[z]>600)
{
if(z==0)
x[z]=x[9]-(rand()%(250-100)+100);
else
x[z]=x[z-1]-(rand()%(250-100)+100);
}
}
dc.Rectangle(x[z],315,x[z]+60,275);
}
}
static int x1[20];
int z1;
if(t==1)
{
x1[0]=400+(rand()%(75-50)+50);
for( z1=0;z1<9;z1++)
{
x1[z1+1]=x1[z1]+(rand()%(250-100)+100);
}
};
if(time<6)
{
dc.SelectObject (&greenbrush);
dc.Ellipse(400,120,430,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z1=0;z1<10;z1++)
{
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
x1[z1]=x1[z1]-3;
if(x1[z1]<0)
{
if(z1==0)
x1[z1]=x1[9]+(rand()%(250-100)+100);
else
x1[z1]=x1[z1-1]+(rand()%(250-100)+100);
}
}
}
else
if(time>=6&&time<12)
{
dc.SelectObject(&yellowbrush);
dc.Ellipse(400,120,430,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z1=0;z1<10;z1++)
{
if(x1[z1]<400)
{
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
x1[z1]=x1[z1]-3;
if(x1[z1]<0)
{
if(z1==0)
x1[z1]=x1[9]+(rand()%(250-100)+100);
else
x1[z1]=x1[z1-1]+(rand()%(250-100)+100);
}
}
else
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
}
}
else
{
dc.SelectObject(&redbrush);
dc.Ellipse(400,120,430,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z1=0;z1<10;z1++)
{
if(x1[z1]<400)
{
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
x1[z1]=x1[z1]-3;
if(x1[z1]<0)
{
if(z1==0)
x1[z1]=x1[9]+(rand()%(250-100)+100);
else
x1[z1]=x1[z1-1]+(rand()%(250-100)+100);
}
}
else
dc.Rectangle(x1[z1],225,x1[z1]+60,185);
}
}
static int x2[20];
int z2;
if(t==1)
{
x2[0]=150-(rand()%(75-50)+50);
for( z2=0;z2<9;z2++)
{
x2[z2+1]=x2[z2]-(rand()%(250-100)+100);
}
};
if(time<6)
{
dc.SelectObject(&redbrush);
dc.Ellipse(170,120,200,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z2=0;z2<10;z2++)
{
if(x2[z2]>150)
{
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
x2[z2]=x2[z2]+3;
if(x2[z2]>500)
{
if(z2==0)
x2[z2]=x2[9]-(rand()%(250-100)+100);
else
x2[z2]=x2[z2-1]-(rand()%(250-100)+100);
}
}
else
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
}
}
else
if(time>=6&&time<12)
{
dc.SelectObject (&greenbrush);
dc.Ellipse(170,120,200,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z2=0;z2<10;z2++)
{
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
x2[z2]=x2[z2]+3;
if(x2[z2]>500)
{
if(z2==0)
x2[z2]=x2[9]-(rand()%(250-100)+100);
else
x2[z2]=x2[z2-1]-(rand()%(250-100)+100);
}
}
}
else
{
dc.SelectObject(&yellowbrush);
dc.Ellipse(170,120,200,150);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z2=0;z2<10;z2++)
{
if(x2[z2]>150)
{
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
x2[z2]=x2[z2]+3;
if(x2[z2]>500)
{
if(z2==0)
x2[z2]=x2[9]-(rand()%(250-100)+100);
else
x2[z2]=x2[z2-1]-(rand()%(250-100)+100);
}
//x[z]=x[(z+9)%9]+(rand()%(250-100)+100);
}
else
dc.Rectangle(225,x2[z2],265,x2[z2]-60);
}
}
static int x3[20];
int z3;
if(t==1)
{
x3[0]=350+(rand()%(75-50)+50);
for( z3=0;z3<9;z3++)
{
x3[z3+1]=x3[z3]+(rand()%(250-100)+100);
}
};
if(time<6)
{
dc.SelectObject(&redbrush);
dc.Ellipse(400,350,430,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z3=0;z3<10;z3++)
{
if(x3[z3]-60<350)
{
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
x3[z3]=x3[z3]-3;
if(x3[z3]-60<0)
{
if(z3==0)
x3[z3]=x3[9]+(rand()%(250-100)+100);
else
x3[z3]=x3[z3-1]+(rand()%(250-100)+100);
}
}
else
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
}
}
else
if(time>=6&&time<12)
{
dc.SelectObject (&greenbrush);
dc.Ellipse(400,350,430,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z3=0;z3<10;z3++)
{
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
x3[z3]=x3[z3]-3;
if(x3[z3]-60<0)
{
if(z3==0)
x3[z3]=x3[9]+(rand()%(250-100)+100);
else
x3[z3]=x3[z3-1]+(rand()%(250-100)+100);
}
}
}
else
{
dc.SelectObject(&yellowbrush);
dc.Ellipse(400,350,430,380);
dc.SelectObject(pGrayPen);
dc.SelectObject (&brush);
for( z3=0;z3<10;z3++)
{
if(x3[z3]-60<350)
{
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
x3[z3]=x3[z3]-3;
if(x3[z3]-60<0)
{
if(z3==0)
x3[z3]=x3[9]+(rand()%(250-100)+100);
else
x3[z3]=x3[z3-1]+(rand()%(250-100)+100);
}
}
else
dc.Rectangle(335,x3[z3],375,x3[z3]-60);
}
}
CRect rect;
GetClientRect(&rect);
CRect rect1(0,120,rect.Width(),380);
CRect rect2(200,0,400,rect.Height());
Sleep(10);
if(m%2==0)
{
InvalidateRect(rect1,1);
InvalidateRect(rect2,1);
}
}
}
HCURSOR CMy33Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy33Dlg::OnCancel()
{
CDialog::OnCancel();
}
void CMy33Dlg::OnOK()
{
m++;
CRect rect;
GetClientRect(&rect);
CRect rect1(0,120,rect.Width(),380);
CRect rect2(170,0,430,rect.Height());
InvalidateRect(rect1,1);
InvalidateRect(rect2,1);
if(m%2==0)
m_a.SetWindowText("暂停");
else
m_a.SetWindowText("开始");
}
void CMy33Dlg::OnOK()
{
m++;
CRect rect;
GetClientRect(&rect);
CRect rect1(0,120,rect.Width(),380);
CRect rect2(170,0,430,rect.Height());
InvalidateRect(rect1,1);
InvalidateRect(rect2,1);
if(m%2==0)
m_a.SetWindowText("暂停");
else
m_a.SetWindowText("开始");
}