. , , ,

,,,

. — ,

..

--------------------------------------------------------------

Parovoz

: 4221

..

: ..

____________________________

___________________________

"____"________________________2001.

2001.


1. ._____________________________________________ 3

1.1. ._____________________________________________ 3

1.2. ._________________________________________________ 3

2. ._____________________________________________ 4

2.1. .__________________________________________ 4

2.2. , .______________ 4

2.2.1. CApp - .______________________________________________ 4

2.2.2. CainWnd- .________________________________________ 4

2.2.3. ._____________________________________________________ 5

2.3. .______________________________________________ 6

________________________________________________________ 7

main.cpp_____________________________________________ 7

main.h______________________________________________ 12

menu1.h____________________________________________ 13

menu1.rc____________________________________________ 13


1. .

 

1.1. .

 

, Windows 95 : parovoz.exe .

 

1.2. .

, . , . : ( , , ), (), . , , () (, ). , . , , , , , . , , . , . , , . , , .


2. .

 

2.1. .

- , MFC. - Windows. : Elliplse, Rectangle. , , , WM_PAINT .

2.2. , .

 

2.2.1. CApp - .

 

CApp - , CWinApp MFC , Windows : , .

- CApp :

InitInstance , CApp

2.2.2. CainWnd- .

 

CMainWnd - , CFrameWnd MFC .)

- MainWnd :

CRect wnd; /* */

CRect kol1,kol2,korp,kr,temp; /**/

CRect svet,ball1,ball2,ball3;/**/

CBrush br1[3],br2; /**/

CBrush sv[4]; /* */

CRect noga; /* */

CRect balls[5]; /* */

CRect kr2; //

int numball; //

int live[5]; //

bool game; /* */

int color; /* */

int ns; /* */

int move; /* *

/ - MainWnd :

CmainWnd(); -

afx_msg void OnBegin();

afx_msg void OnRed(); - Red

afx_msg void OnGreen(); - Green

afx_msg void OnBlue(); - Blue

afx_msg void OnPaint(); - -

afx_msg void OnTimer( UINT nIDEvent ); - -

afx_msg void OnExit(); - Exit

afx_msg void OnChar( UINT nChar, UINT nRepCnt, UINT nFlags ); -

DECLARE_MESSAGE_MAP() -

2.2.3. .

 

BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd)

ON_COMMAND(IDM_EXIT,OnExit)

ON_COMMAND(IDM_BEGIN,OnBegin)

ON_COMMAND(IDM_RED,OnRed)

ON_COMMAND(IDM_GREEN,OnGreen)

ON_COMMAND(IDM_BLUE,OnBlue)

ON_WM_PAINT()

ON_WM_TIMER()

ON_WM_CHAR()

END_MESSAGE_MAP()


2.3. .


1, 2 .

. 1.

 



. 2.

 
 



 

main.cpp

 

/* */

 

#include <afxwin.h>

#include "main.h"

#include "menu1.h"

CMainWnd::CMainWnd() /* . */

{

wnd.SetRect(0,0,400,355);//-

Create(NULL,"parovoz",WS_DLGFRAME ,wnd,NULL,"MAINMENU");

game=false; /* */

color=0; /*. */

ns=0; /*. */

br1[0].CreateSolidBrush(RGB(255,0,0));//

br1[1].CreateSolidBrush(RGB(0,255,0));

br1[2].CreateSolidBrush(RGB(0,0,255));

sv[0].CreateSolidBrush(RGB(255,0,0));//

sv[1].CreateSolidBrush(RGB(0,255,0));//

sv[2].CreateSolidBrush(RGB(255,255,0));

sv[3].CreateSolidBrush(RGB(128,128,128));

br2.CreateSolidBrush(RGB(1,1,1));/* */

for(numball=0;numball<5;numball++)

{//

live[numball]=0;

}

}

BOOL CApp:: InitInstance()/*- */

{

m_pMainWnd=new CMainWnd; /* */

m_pMainWnd->ShowWindow(m_nCmdShow); /* */

return true; /* */

}

afx_msg void CMainWnd::OnPaint() /*- */

{

CPaintDC dc(this); /* */

dc.SelectObject(&br2); /* */

dc.Rectangle(svet); // .

dc.Rectangle(noga); //

for(numball=0;numball<5;numball++)

{//

if(live[numball]==1)//

{

dc.Ellipse(balls[numball]);

}

}

switch(ns) /* */

{

case 0: /* */

{

dc.SelectObject(sv[0]);

dc.Ellipse(ball1);

dc.SelectObject(sv[3]);

dc.Ellipse(ball2);

dc.Ellipse(ball3);

break;

}

case 1: /* */

{

dc.SelectObject(sv[2]);

dc.Ellipse(ball2);

dc.SelectObject(sv[3]);

dc.Ellipse(ball1);

dc.Ellipse(ball3);

break;

}

case 2:/* */

{

dc.SelectObject(sv[1]);

dc.Ellipse(ball3);

dc.SelectObject(sv[3]);

dc.Ellipse(ball1);

dc.Ellipse(ball2);

break;

}

}

dc.SelectObject(br1[color]); /* */

dc.Rectangle(korp); //

dc.SelectObject(&br2);

dc.Rectangle(kr); //

dc.Rectangle(kr2); //

dc.Ellipse(kol1); //

dc.Ellipse(kol2);

char *s=" .";//

if(game==0) dc.TextOut(50,100,s,strlen(s));

}

void CMainWnd::OnExit() /* */

{

SendMessage(WM_CLOSE); /* */

}

afx_msg void CMainWnd::OnTimer( UINT nIDEvent )

{/* */

if(game) /* */

{

if(nIDEvent==2)//

{

for(numball=0;numball<5;numball++)

{// ,

if(live[numball]==0)

{

live[numball]=1;

balls[numball].SetRect(korp.left+35,kr.top-10,kr.right-5,korp.top);

break;

}

}

}

for(numball=0;numball<5;numball++)

{// .

temp.CopyRect(balls[numball]);

if(live[numball]==1)//

{

balls[numball].OffsetRect(1,-6);//

balls[numball].top--; //

balls[numball].right++;

InvalidateRect(temp); //

InvalidateRect(balls[numball]);

if(balls[numball].top<=0) live[numball]=0;//

}

}

if( (korp.right<=svet.left)||(korp.left>=svet.left+3)||(move==1))

{ /* */

if(korp.left<400)/* */

{

temp.CopyRect(korp); /* */

//

korp.OffsetRect(3,0);

InvalidateRect(temp);

InvalidateRect(korp);

temp.CopyRect(kol1);

kol1.OffsetRect(3,0);

InvalidateRect(temp);

InvalidateRect(kol1);

temp.CopyRect(kol2);

kol2.OffsetRect(3,0);

InvalidateRect(temp);

InvalidateRect(kol2);

temp.CopyRect(kr);

kr.OffsetRect(3,0);

InvalidateRect(temp);

InvalidateRect(kr);

temp.CopyRect(kr2);

if(kr2.top==270)

{

kr2.top=275;

}

else kr2.top=270;

kr2.OffsetRect(3,0);

InvalidateRect(temp);

InvalidateRect(kr2);

}

else/* */

{

korp.SetRect(0,288,50,300);

kr.SetRect(30,280,40,288);

kr2.SetRect(10,270,25,288);

kol1.SetRect(5,295,15,305);

kol2.SetRect(35,295,45,305);

ns=1;

move=0;

InvalidateRect(ball1);

InvalidateRect(ball2);

InvalidateRect(ball3);

}

}

}

}

afx_msg void CMainWnd::OnRed()

{/* */

color=0;

}

afx_msg void CMainWnd::OnGreen()

{/* */

color=1;

}

afx_msg void CMainWnd::OnBlue()

{

color=2;

}

afx_msg void CMainWnd::OnBegin()

{

game=true;

color=0;

move=0;

svet.SetRect(200,100,240,230);

noga.SetRect(210,230,230,250);

ball1.SetRect(210,110,230,140);

ball2.SetRect(210,150,230,180);

ball3.SetRect(210,190,230,220);

korp.SetRect(0,288,50,300);

kr.SetRect(30,280,40,288);

kr2.SetRect(10,270,25,288);

kol1.SetRect(5,295,15,305);

kol2.SetRect(35,295,45,305);

SetTimer(1,100,NULL);

SetTimer(2,1000,NULL);

InvalidateRect(NULL);

}

BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd)

ON_COMMAND(IDM_EXIT,OnExit)

ON_COMMAND(IDM_BEGIN,OnBegin)

ON_COMMAND(IDM_RED,OnRed)

ON_COMMAND(IDM_GREEN,OnGreen)

ON_COMMAND(IDM_BLUE,OnBlue)

ON_WM_PAINT()

ON_WM_TIMER()

ON_WM_CHAR()

END_MESSAGE_MAP()

afx_msg void CMainWnd::OnChar( UINT nChar, UINT nRepCnt, UINT nFlags )

{

if(game)

{

switch(nChar)

{

case 234:

{

ns=0;

break;

}

case 231:

{ns=2;

move=1;

break;

}

case 230:

{ns=1;

}

}

InvalidateRect(ball1);

InvalidateRect(ball2);

InvalidateRect(ball3);

}

}

CApp app;

main.h

 

class CMainWnd: public CFrameWnd /* */

{

public:

CRect wnd; /* */

CRect kol1,kol2,korp,kr,temp; /**/

CRect svet,ball1,ball2,ball3;/**/

CBrush br1[3],br2; /**/

CBrush sv[4]; /* */

CRect noga; /* */

CRect balls[5]; /* */

CRect kr2; //

int numball; //

int live[5]; //

bool game; /* */

int color; /* */

int ns; /* */

int move; /* */

CMainWnd(); /* . */

afx_msg void OnRed(); /* */

afx_msg void OnGreen();

afx_msg void OnBlue();

afx_msg void OnPaint(); /*- */

afx_msg void OnTimer( UINT nIDEvent ); /*- */

afx_msg void OnExit();//

afx_msg void OnBegin();//

afx_msg void OnChar( UINT nChar, UINT nRepCnt, UINT nFlags );

DECLARE_MESSAGE_MAP()//

};

class CApp: public CWinApp

{

public:

BOOL InitInstance();

};

menu1.h

 

#define IDM_BEGIN 100

#define IDM_RED 101

#define IDM_GREEN 102

#define IDM_BLUE 103

#define IDM_EXIT 104


menu1.rc

#include <afxres.h>

#include "menu1.h"

MAINMENU MENU DISCARDABLE

BEGIN

POPUP "GAME"

BEGIN

POPUP "COLOR"

BEGIN

MENUITEM "RED", IDM_RED

MENUITEM "GREEN", IDM_GREEN

MENUITEM "BLUE", IDM_BLUE

END

MENUITEM SEPARATOR

MENUITEM "START", IDM_BEGIN

MENUITEM "EXIT", IDM_EXIT

END

END

.. --------------------------------------------------------------

 

 

 

! , , , .
. , :