RussianGameDlg.cpp
上传用户:clj987822
上传日期:2022-04-25
资源大小:13296k
文件大小:70k
- // RussianGameDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "RussianGame.h"
- #include "RussianGameDlg.h"
- #include "HeroDlg.h"
- #include "NameDlg.h"
- #include "mmsystem.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define LeftMargin 20
- #define TopMargin 20
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- 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
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_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_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRussianGameDlg dialog
- CRussianGameDlg::CRussianGameDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CRussianGameDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CRussianGameDlg)
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_iScore=0;
- m_iSp=1;
- m_iLine=0;
- pause=FALSE;
- gameover=TRUE;
- FlagSound=FALSE;
- board.game =FALSE;
- board.level =1;
- board.scroe =0;
- board.pic[0].LoadBitmap(IDB_BITMAP0);
- board.pic[1].LoadBitmap(IDB_BITMAP1);
- rect.left =LeftMargin;
- rect.top =TopMargin;
- rect.right =LeftMargin+202;
- rect.bottom =TopMargin+362;
- picnext[1].LoadBitmap(IDB_PIC1);
- picnext[2].LoadBitmap(IDB_PIC2);
- picnext[3].LoadBitmap(IDB_PIC3);
- picnext[4].LoadBitmap(IDB_PIC4);
- picnext[5].LoadBitmap(IDB_PIC5);
- picnext[6].LoadBitmap(IDB_PIC6);
- picnext[7].LoadBitmap(IDB_PIC7);
- int i,j;
- for(i=0;i<11;i++)
- for(j=0;j<19;j++)
- board.square[i][j]=0;
- scorenum[0]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum1"),500);
- scorenum[1]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum2"),500);
- scorenum[2]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum3"),500);
- scorenum[3]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum4"),500);
- scorenum[4]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum5"),500);
- scorename[0]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename1"),_T("无名英雄"));
- scorename[1]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename2"),_T("无名英雄"));
- scorename[2]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename3"),_T("无名英雄"));
- scorename[3]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename4"),_T("无名英雄"));
- scorename[4]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename5"),_T("无名英雄"));
-
- }
- void CRussianGameDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CRussianGameDlg)
- DDX_Control(pDX, IDC_SOUND, m_Sound);
- DDX_Control(pDX, IDC_EXIT, m_Exit);
- DDX_Control(pDX, IDC_START, m_Start);
- DDX_Control(pDX, IDC_SPADD, m_SpAdd);
- DDX_Control(pDX, IDC_PAUSE, m_Pause);
- DDX_Control(pDX, IDC_LINEADD, m_LineAdd);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CRussianGameDlg, CDialog)
- //{{AFX_MSG_MAP(CRussianGameDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_SPADD, OnSpadd)
- ON_BN_CLICKED(IDC_EXIT, OnExit)
- ON_BN_CLICKED(IDC_START, OnStart)
- ON_WM_TIMER()
- ON_WM_KEYDOWN()
- ON_BN_CLICKED(IDC_PAUSE, OnPause)
- ON_BN_CLICKED(IDC_LINEADD, OnLineadd)
- ON_BN_CLICKED(IDC_SOUND, OnSound)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRussianGameDlg message handlers
- BOOL CRussianGameDlg::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 dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- RECT rect;
- GetWindowRect(&rect);
- int cx=rect.right -rect.left ;
- int cy=rect.bottom -rect.top ;
- POINT pos[9];
- pos[0].x =0;
- pos[0].y = 0;
- pos[1].x = cx;
- pos[1].y = 0;
- pos[2].x = cx;
- pos[2].y = cy - 20;
- pos[3].x = cx - 25;
- pos[3].y = cy - 20;
- pos[4].x = cx - 50;
- pos[4].y = cy;
- pos[5].x = 50;
- pos[5].y = cy;
- pos[6].x = 25;
- pos[6].y = cy - 20;
- pos[7].x = 0;
- pos[7].y = cy - 20;
- pos[8] = pos[0];
- HRGN hrgn;//,hrgn1;
- hrgn=CreatePolygonRgn(pos,9,2);
- CDC *pDC=GetDC();
- // SetBkMode(pDC->m_hDC,TRANSPARENT);
- // pDC->BeginPath();
- // pDC->TextOut(cx/2-20,cy-10,"英雄无敌",8);
- // pDC->EndPath();
- // hrgn1=PathToRegion(pDC->m_hDC);
- //CombineRgn(hrgn,hrgn,hrgn1,RGN_DIFF);
- // SetWindowRgn(hrgn,TRUE);
- m_SpAdd.SetIcon(IDI_ICONADD);
- m_SpAdd.AddToolTip(_T("水平"));
- m_SpAdd.SetBtnCursor(IDC_HAND);
- m_SpAdd.SetActiveFgColor(RGB(0,0,255));
- m_Start.SetIcon(IDI_ICONSTART);
- m_Start.AddToolTip(_T("开始"));
- m_Start.SetBtnCursor(IDC_HAND);
- m_Start.SetActiveFgColor(RGB(0,0,255));
- m_Pause.SetIcon(IDI_ICONPAUSE);
- m_Pause.AddToolTip(_T("暂停"));
- m_Pause.SetBtnCursor(IDC_HAND);
- m_Pause.SetActiveFgColor(RGB(0,0,255));
- m_Exit.SetIcon(IDI_ICONEXIT);
- m_Exit.AddToolTip(_T("退出"));
- m_Exit.SetBtnCursor(IDC_HAND);
- m_Exit.SetActiveFgColor(RGB(0,0,255));
- m_LineAdd.SetIcon(IDI_ICONADD);
- m_LineAdd.AddToolTip(_T("行数"));
- m_LineAdd.SetBtnCursor(IDC_HAND);
- m_LineAdd.SetActiveFgColor(RGB(0,0,255));
- m_Sound.SetIcon(IDI_ICONSOUND);
- m_Sound.AddToolTip(_T("声音"));
- m_Sound.SetBtnCursor(IDC_HAND);
- m_Sound.SetActiveFgColor(RGB(0,0,255));
- Score_num.Create(this,285,105,0,5);
- Sp_num.Create(this,305,157,0,2);
- Line_num.Create(this,305,243,0,2);
-
- //TODO: Add extra initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CRussianGameDlg::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 CRussianGameDlg::OnPaint()
- {
- CPaintDC dc(this);
- if (IsIconic())
- {
- // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- 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;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- /*CDC memdc;
- CDC *pDC=GetDC();
- RECT rect;
- memdc.CreateCompatibleDC(pDC);
- GetClientRect(&rect);
- CBitmap bitmap;
- bitmap.LoadBitmap(IDB_BACKPIC);
- int cx=rect.right -rect.left ;
- int cy=rect.bottom -rect.top ;
- memdc.SelectObject(bitmap);
- pDC->BitBlt(0,0,cx,cy,&memdc,0,0,SRCCOPY);
- ReleaseDC(pDC);*/
- CBrush br(RGB(0,0,255));
- CRect rc=rect;
- dc.FrameRect(&rc,&br);
- rc.InflateRect(2,2);
- CBrush br1(RGB(0,255,0));
- dc.FrameRect(&rc,&br1);
- CBrush br2(RGB(255,0,0));
- rc.InflateRect(2,2);
- dc.FrameRect(&rc,&br2);
- br.DeleteObject();
- br1.DeleteObject();
- br2.DeleteObject();
- rc.SetRectEmpty();
- paintpic(&dc);
- Score_num.SetNumber(board.scroe);
- Sp_num.SetNumber(board.level);
- Line_num.SetNumber(m_iLine);
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CRussianGameDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CRussianGameDlg::checkforhighscore()
- {
- getscore();
- int n,j;
- for (n=0;n<5;n++)
- if(board.scroe >= scorenum[n])
- {
- if(n<4)
- {
- for(j=4;j>=n+1;j--)
- {
- scorenum[j] = scorenum[j - 1];
- scorename[j] = scorename[j - 1];
- }
- }
- CNameDlg name;
- name.DoModal();
- heroname=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("heroname"),_T("无名英雄"));
- scorename[n] =heroname;
- scorenum[n] = board.scroe;
- writescore();
- break;
- }
- return;
- }
- void CRussianGameDlg::getscore()
- {
- scorenum[0]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum1"),500);
- scorenum[1]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum2"),500);
- scorenum[2]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum3"),500);
- scorenum[3]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum4"),500);
- scorenum[4]=AfxGetApp()->GetProfileInt(_T("英雄榜"),_T("scorenum5"),500);
- scorename[0]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename1"),_T("无名英雄"));
- scorename[1]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename2"),_T("无名英雄"));
- scorename[2]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename3"),_T("无名英雄"));
- scorename[3]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename4"),_T("无名英雄"));
- scorename[4]=AfxGetApp()->GetProfileString(_T("英雄榜"),_T("scorename5"),_T("无名英雄"));
- }
- void CRussianGameDlg::drawpiece()
- {
- int i,curpiece;
- curpiece=board.curpiece ;
- switch (curpiece)
- {
- case 1:
- {
- for (i=4;i<=7;i++)
- {
- if (board.square[i][1]!=0) gameover = TRUE;
- board.square[i][1]=1;
- }
- }
- break;
- case 2:
- {
- if (board.square[4][1] != 0) gameover = TRUE;
- board.square[4][1] = 1;
- for(i = 4;i<=6;i++)
- {
- if (board.square[i][2] != 0)gameover = TRUE;
- board.square[i][2] = 1;
- }
- }
- break;
- case 3:
- {
- if (board.square[6][1] != 0) gameover = TRUE;
- board.square[6][1] = 1;
- for(i = 4;i<=6;i++)
- {
- if (board.square[i][2] != 0) gameover = TRUE;
- board.square[i][2] = 1;
- }
- }
- break;
- case 4:
- {
- for(i = 4;i<=5;i++)
- {
- if (board.square[i][1] != 0) gameover = TRUE;
- board.square[i][1] = 1;
- }
- for(i = 5;i<=6;i++)
- {
- if (board.square[i][2] != 0) gameover = TRUE;
- board.square[i][2] = 1;
- }
- }
- break;
- case 5:
- {
- for(i = 5;i<=6;i++)
- {
- if (board.square[i][1] != 0) gameover = TRUE;
- board.square[i][1] = 1;
- }
- for(i = 4;i<=5;i++)
- {
- if (board.square[i][2] != 0) gameover = TRUE;
- board.square[i][2] = 1;
- }
- }
- break;
- case 6:
- {
- if (board.square[5][1] != 0) gameover = TRUE;
- board.square[5][1] = 1;
- for(i = 4;i<=6;i++)
- {
- if (board.square[i][2] != 0) gameover = TRUE;
- board.square[i][2] = 1;
- }
- }
- break;
- case 7:
- {
- for(i = 5;i<=6;i++)
- {
- if (board.square[i][1] != 0) gameover = TRUE;
- board.square[i][1] = 1;
- }
- for(i = 5;i<=6;i++)
- {
- if (board.square[i][2] != 0) gameover = TRUE;
- board.square[i][2] = 1;
- }
- }
- break;
- }
- return;
- }
- void CRussianGameDlg::movepiecedown()
- {
- int i,curpiece;
- curpiece=board.curpiece ;
- switch (curpiece)
- {
- case 1:
- {
- if (board.piecepos == 1)
- {
- if(board.piecey <= 17)
- {
- if(board.square[board.piecex - 1][board.piecey + 1]== 0 && board.square[board.piecex][board.piecey + 1]== 0 && board.square[board.piecex + 1][board.piecey + 1]== 0 && board.square[board.piecex +2][board.piecey + 1]== 0)
- {
- for(i = board.piecex - 1;i<=board.piecex + 2;i++)
- {
- board.square[i][board.piecey] = 0;
- board.square[i][board.piecey + 1] = 1;
- }
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if (board.piecepos== 2)
- {
- if (board.piecey <= 15)
- {
- if(board.square[board.piecex][board.piecey + 3]== 0)
- {
- board.square[board.piecex][board.piecey + 3] = 1;
- board.square[board.piecex][board.piecey -1] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- }
- break;
- case 2:
- {
- if(board.piecepos == 1)
- {
- if(board.piecey <= 17)
- {
- if(board.square[board.piecex-1][board.piecey + 1]== 0 && board.square[board.piecex][board.piecey + 1]== 0 && board.square[board.piecex+1][board.piecey + 1]== 0)
- {
- board.square[board.piecex-1][board.piecey + 1]= 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex+1][board.piecey + 1] = 1;
- board.square[board.piecex-1][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex+1][board.piecey] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos== 2)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex][board.piecey + 2]== 0 && board.square[board.piecex + 1][board.piecey]== 0)
- {
- board.square[board.piecex][board.piecey + 2] = 1;
- board.square[board.piecex+1][board.piecey] = 1;
- board.square[board.piecex][board.piecey -1] = 0;
- board.square[board.piecex+1][board.piecey-1] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos == 3)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex-1][board.piecey + 1]== 0 && board.square[board.piecex][board.piecey+1]== 0 && board.square[board.piecex+1][board.piecey+2]== 0)
- {
- board.square[board.piecex-1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey+1] = 1;
- board.square[board.piecex+1][board.piecey + 2] = 1;
- board.square[board.piecex-1][board.piecey] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex+1][board.piecey] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos== 4)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex-1][board.piecey + 2]== 0 && board.square[board.piecex][board.piecey+2]== 0)
- {
- board.square[board.piecex-1][board.piecey + 2] = 1;
- board.square[board.piecex][board.piecey+2] = 1;
- board.square[board.piecex][board.piecey -1] = 0;
- board.square[board.piecex-1][board.piecey+1] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- }
- break;
- case 3:
- {
- if(board.piecepos == 1)
- {
- if(board.piecey <= 17)
- {
- if(board.square[board.piecex-1][board.piecey + 1]== 0 && board.square[board.piecex][board.piecey + 1]== 0 && board.square[board.piecex+1][board.piecey + 1]== 0)
- {
- board.square[board.piecex-1][board.piecey + 1]= 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex+1][board.piecey + 1] = 1;
- board.square[board.piecex-1][board.piecey] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex+1][board.piecey-1] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos== 2)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex][board.piecey + 2]== 0 && board.square[board.piecex + 1][board.piecey+2]== 0)
- {
- board.square[board.piecex][board.piecey + 2] = 1;
- board.square[board.piecex+1][board.piecey+2] = 1;
- board.square[board.piecex][board.piecey -1] = 0;
- board.square[board.piecex+1][board.piecey+1] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos == 3)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex-1][board.piecey + 2]== 0 && board.square[board.piecex][board.piecey+1]== 0 && board.square[board.piecex+1][board.piecey+1]== 0)
- {
- board.square[board.piecex-1][board.piecey + 2] = 1;
- board.square[board.piecex][board.piecey+1] = 1;
- board.square[board.piecex+1][board.piecey + 1] = 1;
- board.square[board.piecex-1][board.piecey] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex+1][board.piecey] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos== 4)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex-1][board.piecey]== 0 && board.square[board.piecex][board.piecey+2]== 0)
- {
- board.square[board.piecex-1][board.piecey] = 1;
- board.square[board.piecex][board.piecey+2] = 1;
- board.square[board.piecex][board.piecey -1] = 0;
- board.square[board.piecex-1][board.piecey-1] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- }
- break;
- case 4:
- {
- if(board.piecepos == 1)
- {
- if(board.piecey <= 17)
- {
- if(board.square[board.piecex-1][board.piecey]== 0 && board.square[board.piecex][board.piecey + 1]== 0 && board.square[board.piecex+1][board.piecey + 1]== 0)
- {
- board.square[board.piecex-1][board.piecey]= 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex+1][board.piecey + 1] = 1;
- board.square[board.piecex-1][board.piecey-1] = 0;
- board.square[board.piecex][board.piecey-1] = 0;
- board.square[board.piecex+1][board.piecey] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos== 2)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex][board.piecey + 2]== 0 && board.square[board.piecex + 1][board.piecey+1]== 0)
- {
- board.square[board.piecex][board.piecey + 2] = 1;
- board.square[board.piecex+1][board.piecey+1] = 1;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex+1][board.piecey-1] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- }
- break;
- case 5:
- {
- if(board.piecepos == 1)
- {
- if(board.piecey <= 17)
- {
- if(board.square[board.piecex-1][board.piecey+1]== 0 && board.square[board.piecex][board.piecey + 1]== 0 && board.square[board.piecex+1][board.piecey]== 0)
- {
- board.square[board.piecex-1][board.piecey+1]= 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex+1][board.piecey] = 1;
- board.square[board.piecex-1][board.piecey] = 0;
- board.square[board.piecex][board.piecey-1] = 0;
- board.square[board.piecex+1][board.piecey-1] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos== 2)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex][board.piecey + 1]== 0 && board.square[board.piecex + 1][board.piecey+2]== 0)
- {
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex+1][board.piecey+2] = 1;
- board.square[board.piecex][board.piecey-1] = 0;
- board.square[board.piecex+1][board.piecey] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- }
- break;
- case 6:
- {
- if(board.piecepos == 1)
- {
- if(board.piecey <= 17)
- {
- if(board.square[board.piecex-1][board.piecey + 1]== 0 && board.square[board.piecex][board.piecey + 1]== 0 && board.square[board.piecex+1][board.piecey + 1]== 0)
- {
- board.square[board.piecex-1][board.piecey + 1]= 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex+1][board.piecey + 1] = 1;
- board.square[board.piecex-1][board.piecey] = 0;
- board.square[board.piecex][board.piecey-1] = 0;
- board.square[board.piecex+1][board.piecey] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos== 2)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex][board.piecey + 2]== 0 && board.square[board.piecex + 1][board.piecey+1]== 0)
- {
- board.square[board.piecex][board.piecey + 2] = 1;
- board.square[board.piecex+1][board.piecey+1] = 1;
- board.square[board.piecex][board.piecey -1] = 0;
- board.square[board.piecex+1][board.piecey] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos == 3)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex-1][board.piecey + 1]== 0 && board.square[board.piecex][board.piecey+2]== 0 && board.square[board.piecex+1][board.piecey+1]== 0)
- {
- board.square[board.piecex-1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey+2] = 1;
- board.square[board.piecex+1][board.piecey + 1] = 1;
- board.square[board.piecex-1][board.piecey] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex+1][board.piecey] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- else if(board.piecepos== 4)
- {
- if(board.piecey <= 16)
- {
- if( board.square[board.piecex-1][board.piecey+1]== 0 && board.square[board.piecex][board.piecey+2]== 0)
- {
- board.square[board.piecex-1][board.piecey+1] = 1;
- board.square[board.piecex][board.piecey+2] = 1;
- board.square[board.piecex][board.piecey -1] = 0;
- board.square[board.piecex-1][board.piecey] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- }
- break;
- case 7:
- {
- if(board.piecey <= 17)
- {
- if(board.square[board.piecex][board.piecey + 1]== 0 && board.square[board.piecex+1][board.piecey + 1]== 0)
- {
- board.square[board.piecex][board.piecey + 1]= 1;
- board.square[board.piecex+1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey-1] = 0;
- board.square[board.piecex+1][board.piecey-1] = 0;
- board.piecey = board.piecey + 1;
- }
- else
- newpiece = TRUE;
- }
- else
- newpiece = TRUE;
- }
- break;
- }
- return;
- }
- void CRussianGameDlg::movepieceleft()
- {
- int i,curpiece;
- curpiece=board.curpiece;
- switch (curpiece)
- {
- case 1:
- if(board.piecepos== 1)
- {
- if(board.piecex >= 3)
- if(board.square[board.piecex - 2][board.piecey]== 0)
- {
- board.square[board.piecex - 2][board.piecey]= 1;
- board.square[board.piecex + 2][board.piecey] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex >= 2)
- if(board.square[board.piecex - 1][board.piecey - 1]== 0 && board.square[board.piecex - 1][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey + 1]== 0 && board.square[board.piecex - 1][board.piecey + 2] == 0)
- {
- for(i = board.piecey - 1;i<=board.piecey + 2;i++)
- {
- board.square[board.piecex - 1][i] = 1;
- board.square[board.piecex][i] = 0;
- }
- board.piecex = board.piecex - 1;
- }
- }
- break;
- case 2:
- if(board.piecepos == 1)
- {
- if(board.piecex >= 3)
- if(board.square[board.piecex - 2][board.piecey] == 0 && board.square[board.piecex - 2][board.piecey - 1]== 0)
- {
- board.square[board.piecex - 2][board.piecey]=1;
- board.square[board.piecex - 2][board.piecey-1] = 1;
- board.square[board.piecex - 1][board.piecey-1] = 0;
- board.square[board.piecex +1][board.piecey] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex >= 2)
- if(board.square[board.piecex - 1][board.piecey - 1]== 0 && board.square[board.piecex - 1][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey + 1]== 0)
- {
- for(i = board.piecey - 1;i<=board.piecey + 1;i++)
- {
- board.square[board.piecex - 1][i] = 1;
- board.square[board.piecex][i] = 0;
- }
- board.square[board.piecex][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey - 1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos== 3)
- {
- if(board.piecex >= 3)
- if(board.square[board.piecex - 2][board.piecey]== 0 && board.square[board.piecex][board.piecey + 1]== 0)
- {
- board.square[board.piecex - 2][board.piecey] = 1;
- board.square[board.piecex][board.piecey + 1]= 1;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey + 1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos == 4)
- {
- if(board.piecex >= 3)
- if( board.square[board.piecex - 1][board.piecey - 1] == 0 && board.square[board.piecex - 1][board.piecey]== 0 && board.square[board.piecex - 2][board.piecey + 1]== 0)
- {
- board.square[board.piecex - 1][board.piecey - 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex - 2][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- break;
- case 3:
- if(board.piecepos == 1)
- {
- if(board.piecex >= 3)
- if(board.square[board.piecex - 2][board.piecey] == 0 && board.square[board.piecex][board.piecey - 1]== 0)
- {
- board.square[board.piecex - 2][board.piecey]=1;
- board.square[board.piecex][board.piecey-1] = 1;
- board.square[board.piecex +1][board.piecey-1] = 0;
- board.square[board.piecex +1][board.piecey] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex >= 2)
- if(board.square[board.piecex - 1][board.piecey - 1]== 0 && board.square[board.piecex - 1][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey + 1]== 0)
- {
- for(i = board.piecey - 1;i<=board.piecey + 1;i++)
- {
- board.square[board.piecex - 1][i] = 1;
- board.square[board.piecex][i] = 0;
- }
- board.square[board.piecex][board.piecey +1] = 1;
- board.square[board.piecex + 1][board.piecey +1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos== 3)
- {
- if(board.piecex >= 3)
- if(board.square[board.piecex - 2][board.piecey]== 0 && board.square[board.piecex-2][board.piecey + 1] == 0)
- {
- board.square[board.piecex - 2][board.piecey] = 1;
- board.square[board.piecex-2][board.piecey + 1]= 1;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.square[board.piecex - 1][board.piecey + 1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos == 4)
- {
- if(board.piecex >= 3)
- if( board.square[board.piecex - 2][board.piecey - 1] == 0 && board.square[board.piecex - 1][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey + 1]== 0)
- {
- board.square[board.piecex - 2][board.piecey - 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex - 1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- break;
- case 4:
- if(board.piecepos == 1)
- {
- if(board.piecex >= 3)
- if(board.square[board.piecex - 2][board.piecey - 1]== 0 && board.square[board.piecex - 1][board.piecey]== 0)
- {
- board.square[board.piecex - 2][board.piecey - 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex >= 2)
- if(board.square[board.piecex - 1][board.piecey] == 0 && board.square[board.piecex - 1][board.piecey + 1]== 0 && board.square[board.piecex][board.piecey - 1] == 0)
- {
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex - 1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey - 1] = 0;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- break;
- case 5:
- if(board.piecepos == 1)
- {
- if(board.piecex >= 3)
- if(board.square[board.piecex - 2][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey-1]== 0)
- {
- board.square[board.piecex - 2][board.piecey] = 1;
- board.square[board.piecex - 1][board.piecey-1] = 1;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey-1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex >= 2)
- if(board.square[board.piecex - 1][board.piecey] == 0 && board.square[board.piecex - 1][board.piecey - 1]== 0 && board.square[board.piecex][board.piecey + 1] == 0)
- {
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex - 1][board.piecey - 1] = 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex + 1][board.piecey + 1] = 0;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- break;
- case 6:
- if(board.piecepos == 1)
- {
- if(board.piecex >= 3)
- if(board.square[board.piecex - 2][board.piecey] == 0 && board.square[board.piecex - 1][board.piecey - 1]== 0)
- {
- board.square[board.piecex - 2][board.piecey]=1;
- board.square[board.piecex - 1][board.piecey-1] = 1;
- board.square[board.piecex][board.piecey-1] = 0;
- board.square[board.piecex +1][board.piecey] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex >= 2)
- if(board.square[board.piecex - 1][board.piecey - 1]== 0 && board.square[board.piecex - 1][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey + 1]== 0)
- {
- for(i = board.piecey - 1;i<=board.piecey + 1;i++)
- {
- board.square[board.piecex - 1][i] = 1;
- board.square[board.piecex][i] = 0;
- }
- board.square[board.piecex][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos== 3)
- {
- if(board.piecex >= 3)
- if(board.square[board.piecex - 2][board.piecey]== 0 && board.square[board.piecex-1][board.piecey + 1]== 0)
- {
- board.square[board.piecex - 2][board.piecey] = 1;
- board.square[board.piecex-1][board.piecey + 1]= 1;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- else if(board.piecepos == 4)
- {
- if(board.piecex >= 3)
- if( board.square[board.piecex - 1][board.piecey - 1] == 0 && board.square[board.piecex - 2][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey + 1]== 0)
- {
- board.square[board.piecex - 1][board.piecey - 1] = 1;
- board.square[board.piecex - 2][board.piecey] = 1;
- board.square[board.piecex - 1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- break;
- case 7:
- if(board.piecex >= 2)
- {
- if( board.square[board.piecex - 1][board.piecey - 1]== 0 && board.square[board.piecex - 1][board.piecey]== 0)
- {
- board.square[board.piecex - 1][board.piecey - 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey - 1] = 0;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.piecex = board.piecex - 1;
- }
- }
- break;
- }
- InvalidateRect(&rect,FALSE);
- return;
- }
- void CRussianGameDlg::movepieceright()
- {
- int i,curpiece;
- curpiece=board.curpiece;
- switch (curpiece)
- {
- case 1:
- if(board.piecepos== 1)
- {
- if(board.piecex <= 7)
- if(board.square[board.piecex +3][board.piecey]== 0)
- {
- board.square[board.piecex +3][board.piecey]= 1;
- board.square[board.piecex -1][board.piecey] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex <= 9)
- if(board.square[board.piecex + 1][board.piecey - 1]== 0 && board.square[board.piecex + 1][board.piecey]== 0 && board.square[board.piecex + 1][board.piecey + 1]== 0 && board.square[board.piecex + 1][board.piecey + 2] == 0)
- {
- for(i = board.piecey - 1;i<=board.piecey + 2;i++)
- {
- board.square[board.piecex + 1][i] = 1;
- board.square[board.piecex][i] = 0;
- }
- board.piecex = board.piecex + 1;
- }
- }
- break;
- case 2:
- if(board.piecepos == 1)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 2][board.piecey] == 0 && board.square[board.piecex ][board.piecey - 1]== 0)
- {
- board.square[board.piecex + 2][board.piecey]=1;
- board.square[board.piecex ][board.piecey-1] = 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex -1][board.piecey-1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex +2][board.piecey - 1]== 0 && board.square[board.piecex +1][board.piecey]== 0 && board.square[board.piecex + 1][board.piecey + 1]== 0)
- {
- for(i = board.piecey - 1;i<=board.piecey + 1;i++)
- {
- board.square[board.piecex + 1][i] = 1;
- board.square[board.piecex][i] = 0;
- }
- board.square[board.piecex+2][board.piecey - 1] = 1;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos== 3)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 2][board.piecey]== 0 && board.square[board.piecex+2][board.piecey + 1]== 0)
- {
- board.square[board.piecex + 2][board.piecey] = 1;
- board.square[board.piecex+2][board.piecey + 1]= 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey + 1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos == 4)
- {
- if(board.piecex <= 9)
- if( board.square[board.piecex + 1][board.piecey - 1] == 0 && board.square[board.piecex + 1][board.piecey]== 0 && board.square[board.piecex +1][board.piecey + 1]== 0)
- {
- board.square[board.piecex + 1][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex +1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex-1][board.piecey + 1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- break;
- case 3:
- if(board.piecepos == 1)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 2][board.piecey] == 0 && board.square[board.piecex+2][board.piecey - 1]== 0)
- {
- board.square[board.piecex + 2][board.piecey]=1;
- board.square[board.piecex+2][board.piecey-1] = 1;
- board.square[board.piecex -1][board.piecey] = 0;
- board.square[board.piecex +1][board.piecey-1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex +2][board.piecey + 1]== 0 && board.square[board.piecex + 1][board.piecey]== 0 && board.square[board.piecex + 1][board.piecey - 1]== 0)
- {
- for(i = board.piecey - 1;i<=board.piecey + 1;i++)
- {
- board.square[board.piecex + 1][i] = 1;
- board.square[board.piecex][i] = 0;
- }
- board.square[board.piecex+2][board.piecey +1] = 1;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos== 3)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 2][board.piecey]== 0 && board.square[board.piecex][board.piecey + 1] == 0)
- {
- board.square[board.piecex + 2][board.piecey] = 1;
- board.square[board.piecex][board.piecey + 1]= 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex - 1][board.piecey + 1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos == 4)
- {
- if(board.piecex <= 9)
- if( board.square[board.piecex +1][board.piecey - 1] == 0 && board.square[board.piecex + 1][board.piecey]== 0 && board.square[board.piecex + 1][board.piecey + 1]== 0)
- {
- board.square[board.piecex+ 1][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex-1][board.piecey - 1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- break;
- case 4:
- if(board.piecepos == 1)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 2][board.piecey]== 0 && board.square[board.piecex + 1][board.piecey-1]== 0)
- {
- board.square[board.piecex + 2][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey-1] = 1;
- board.square[board.piecex][board.piecey] = 0;
- board.square[board.piecex - 1][board.piecey-1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex +2][board.piecey] == 0 && board.square[board.piecex +2][board.piecey - 1]== 0 && board.square[board.piecex+1][board.piecey + 1] == 0)
- {
- board.square[board.piecex +2][board.piecey] = 1;
- board.square[board.piecex + 2][board.piecey - 1] = 1;
- board.square[board.piecex+1][board.piecey + 1] = 1;
- board.square[board.piecex + 1][board.piecey - 1] = 0;
- board.square[board.piecex ][board.piecey+1] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- break;
- case 5:
- if(board.piecepos == 1)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 2][board.piecey-1]== 0 && board.square[board.piecex + 1][board.piecey]== 0)
- {
- board.square[board.piecex + 2][board.piecey-1] = 1;
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex-1][board.piecey] = 0;
- board.square[board.piecex ][board.piecey-1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 2][board.piecey] == 0 && board.square[board.piecex +2][board.piecey + 1]== 0 && board.square[board.piecex+1][board.piecey - 1] == 0)
- {
- board.square[board.piecex +2][board.piecey] = 1;
- board.square[board.piecex +2][board.piecey +1] = 1;
- board.square[board.piecex+1][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey + 1] = 0;
- board.square[board.piecex][board.piecey-1] = 0;
- board.square[board.piecex][board.piecey] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- break;
- case 6:
- if(board.piecepos == 1)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 2][board.piecey] == 0 && board.square[board.piecex + 1][board.piecey - 1]== 0)
- {
- board.square[board.piecex + 2][board.piecey]=1;
- board.square[board.piecex + 1][board.piecey-1] = 1;
- board.square[board.piecex][board.piecey-1] = 0;
- board.square[board.piecex -1][board.piecey] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 1][board.piecey - 1]== 0 && board.square[board.piecex +2][board.piecey]== 0 && board.square[board.piecex + 1][board.piecey + 1]== 0)
- {
- for(i = board.piecey - 1;i<=board.piecey + 1;i++)
- {
- board.square[board.piecex + 1][i] = 1;
- board.square[board.piecex][i] = 0;
- }
- board.square[board.piecex+2][board.piecey] = 1;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos== 3)
- {
- if(board.piecex <= 8)
- if(board.square[board.piecex + 2][board.piecey]== 0 && board.square[board.piecex+1][board.piecey + 1]== 0)
- {
- board.square[board.piecex + 2][board.piecey] = 1;
- board.square[board.piecex+1][board.piecey + 1]= 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- else if(board.piecepos == 4)
- {
- if(board.piecex <= 9)
- if( board.square[board.piecex + 1][board.piecey - 1] == 0 && board.square[board.piecex +1][board.piecey]== 0 && board.square[board.piecex + 1][board.piecey + 1]== 0)
- {
- board.square[board.piecex + 1][board.piecey - 1] = 1;
- board.square[board.piecex +1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex-1][board.piecey] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.piecex = board.piecex + 1;
- }
- }
- break;
- case 7:
- if(board.piecex <= 8)
- if( board.square[board.piecex +2][board.piecey - 1]== 0 && board.square[board.piecex +2][board.piecey]== 0)
- {
- board.square[board.piecex +2][board.piecey - 1] = 1;
- board.square[board.piecex +2][board.piecey] = 1;
- board.square[board.piecex ][board.piecey - 1] = 0;
- board.square[board.piecex ][board.piecey] = 0;
- board.piecex = board.piecex + 1;
- }
- break;
- }
- InvalidateRect(&rect,FALSE);
- return;
- }
- void CRussianGameDlg::roatepiece()
- {
- int curpiece;
- curpiece=board.curpiece;
- switch (curpiece)
- {
- case 1:
- if(board.piecepos== 1)
- {
- if(board.piecey > 1 && board.piecey <= 16)
- if (board.square[board.piecex][board.piecey - 1]== 0 && board.square[board.piecex][board.piecey + 1]== 0 && board.square[board.piecex][board.piecey + 2]== 0)
- {
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.square[board.piecex + 2][board.piecey] = 0;
- board.square[board.piecex][board.piecey - 1] = 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey + 2] = 1;
- board.piecepos = 2;
- }
- }
- else if(board.piecepos ==2)
- {
- if (board.piecex > 1 && board.piecex <= 8 )
- if(board.square[board.piecex - 1][board.piecey]== 0 && board.square[board.piecex + 1][board.piecey] == 0 && board.square[board.piecex + 2][board.piecey]== 0)
- {
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex + 2][board.piecey] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.square[board.piecex][board.piecey + 2] = 0;
- board.piecepos = 1;
- }
- }
- break;
- case 2:
- if(board.piecepos == 1)
- {
- if(board.piecey <= 17)
- if (board.square[board.piecex][board.piecey - 1] == 0 && board.square[board.piecex + 1][board.piecey - 1] == 0 && board.square[board.piecex][board.piecey + 1]== 0)
- {
- board.square[board.piecex][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey - 1] = 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex - 1][board.piecey - 1] = 0;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.piecepos = 2;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex > 1)
- if(board.square[board.piecex - 1][board.piecey]== 0 && board.square[board.piecex + 1][board.piecey] == 0 && board.square[board.piecex + 1][board.piecey + 1]== 0)
- {
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.square[board.piecex + 1][board.piecey - 1] = 0;
- board.piecepos = 3;
- }
- }
- else if(board.piecepos == 3)
- {
- if(board.piecey > 1)
- if(board.square[board.piecex][board.piecey - 1] == 0 && board.square[board.piecex][board.piecey + 1] == 0 && board.square[board.piecex - 1][board.piecey + 1] == 0)
- {
- board.square[board.piecex][board.piecey - 1] = 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex - 1][board.piecey + 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey + 1] = 0;
- board.piecepos = 4;
- }
- }
- else if(board.piecepos == 4)
- {
- if(board.piecex < 10)
- if(board.square[board.piecex + 1][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey - 1] == 0)
- {
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex - 1][board.piecey - 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.square[board.piecex - 1][board.piecey + 1] = 0;
- board.piecepos = 1;
- }
- }
- break;
- case 3:
- if(board.piecepos == 1)
- {
- if(board.piecey <=17)
- if(board.square[board.piecex][board.piecey - 1]== 0 && board.square[board.piecex + 1][board.piecey + 1] == 0 && board.square[board.piecex][board.piecey + 1] == 0)
- {
- board.square[board.piecex][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey - 1] = 0;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.piecepos = 2;
- }
- }
- else if(board.piecepos==2)
- {
- if(board.piecex > 1)
- if(board.square[board.piecex - 1][board.piecey] == 0 && board.square[board.piecex + 1][board.piecey]== 0 && board.square[board.piecex - 1][board.piecey + 1] == 0)
- {
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex - 1][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.square[board.piecex + 1][board.piecey + 1] = 0;
- board.piecepos = 3;
- }
- }
- else if(board.piecepos == 3)
- {
- if(board.piecey > 1)
- if(board.square[board.piecex][board.piecey - 1]== 0 && board.square[board.piecex][board.piecey + 1] == 0 && board.square[board.piecex - 1][board.piecey - 1] ==0)
- {
- board.square[board.piecex][board.piecey - 1] = 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex - 1][board.piecey - 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.square[board.piecex - 1][board.piecey + 1] = 0;
- board.piecepos = 4;
- }
- }
- else if(board.piecepos == 4)
- {
- if(board.piecex < 10)
- if(board.square[board.piecex + 1][board.piecey] == 0 && board.square[board.piecex - 1][board.piecey] == 0 && board.square[board.piecex + 1][board.piecey - 1] ==0)
- {
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey - 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.square[board.piecex - 1][board.piecey - 1] = 0;
- board.piecepos = 1;
- }
- }
- break;
- case 4:
- if(board.piecepos == 1)
- {
- if(board.piecey < 18)
- if(board.square[board.piecex + 1][board.piecey - 1]== 0 && board.square[board.piecex][board.piecey + 1] == 0 )
- {
- board.square[board.piecex + 1][board.piecey - 1] = 1;
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.square[board.piecex - 1][board.piecey - 1] = 0;
- board.piecepos = 2;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex > 1)
- if(board.square[board.piecex][board.piecey - 1]== 0 && board.square[board.piecex - 1][board.piecey - 1] == 0 )
- {
- board.square[board.piecex][board.piecey - 1] = 1;
- board.square[board.piecex - 1][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey - 1] = 0;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.piecepos = 1;
- }
- }
- break;
- case 5:
- if(board.piecepos == 1)
- {
- if(board.piecey < 18 )
- if(board.square[board.piecex + 1][board.piecey] == 0 && board.square[board.piecex + 1][board.piecey + 1] == 0 )
- {
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey + 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey - 1] = 0;
- board.piecepos = 2;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex > 1 )
- if(board.square[board.piecex - 1][board.piecey] == 0 && board.square[board.piecex + 1][board.piecey - 1] == 0)
- {
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex + 1][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.square[board.piecex + 1][board.piecey + 1] = 0;
- board.piecepos = 1;
- }
- }
- break;
- case 6:
- if(board.piecepos == 1)
- {
- if(board.piecey <= 17)
- if(board.square[board.piecex][board.piecey + 1] == 0 )
- {
- board.square[board.piecex][board.piecey + 1] = 1;
- board.square[board.piecex - 1][board.piecey] = 0;
- board.piecepos = 2;
- }
- }
- else if(board.piecepos == 2)
- {
- if(board.piecex > 1)
- if(board.square[board.piecex - 1][board.piecey] == 0)
- {
- board.square[board.piecex - 1][board.piecey] = 1;
- board.square[board.piecex][board.piecey - 1] = 0;
- board.piecepos = 3;
- }
- }
- else if(board.piecepos == 3)
- {
- if(board.piecey > 1)
- if(board.square[board.piecex][board.piecey - 1] == 0)
- {
- board.square[board.piecex][board.piecey - 1] = 1;
- board.square[board.piecex + 1][board.piecey] = 0;
- board.piecepos = 4;
- }
- }
- else if(board.piecepos == 4)
- {
- if(board.piecex < 10)
- if(board.square[board.piecex + 1][board.piecey] == 0)
- {
- board.square[board.piecex + 1][board.piecey] = 1;
- board.square[board.piecex][board.piecey + 1] = 0;
- board.piecepos = 1;
- }
- }
- break;
- }
- InvalidateRect(&rect,FALSE);
- return;
- }
- void CRussianGameDlg::OnSpadd()
- {
- m_iSp++;
- if(m_iSp==10)m_iSp=1;
- board.level =m_iSp;
- Sp_num.SetNumber(m_iSp);
- // TODO: Add your control notification handler code here
-
- }
- void CRussianGameDlg::paintpic(CDC *dc)
- {
- int i,j;
- CDC memdc0,memdc1;
- //CDC *pDC=GetDC();
- memdc0.CreateCompatibleDC(dc);
- memdc1.CreateCompatibleDC(dc);
- memdc0.SelectObject(board.pic[0]);
- memdc1.SelectObject(board.pic[1]);
- for(i = 1;i<=10;i++)
- for(j = 1;j<=18;j++)
- dc->BitBlt((i-1)*20+1+LeftMargin,(j-1)*20+1+TopMargin,20,20,board.square[i][j]==0?&memdc0:&memdc1,1,1,SRCCOPY);
- ReleaseDC(dc);
- return;
- }
- void CRussianGameDlg::OnExit()
- {
- //PostQuitMessage(0);
- KillTimer(1);
- CDialog::EndDialog(0);
- // TODO: Add your control notification handler code here
-
- }
- void CRussianGameDlg::OnStart()
- {
- if(pause==FALSE)
- {
- int i,j;
- for(i=0;i<11;i++)
- for(j=0;j<19;j++)
- board.square[i][j]=0;
- board.level =m_iSp;
- board.scroe =0;
- board.rows =(board.level -1)*10;
- board.game =TRUE;
- board.nextpiece =Random(8);
- if(board.nextpiece ==0)board.nextpiece =5;
- gameover=FALSE;
- newpiece=TRUE;
- if(m_iLine>0)
- {
- int snum;
- for(i = 18;i>=18 - m_iLine + 1;i--)
- {
- srand(i);
- for(j = 1;j<11;j++)
- {
- snum = rand()%5;
- if(snum== 2 )board.square[j][i] = 1;
- }
- }
- }
- }
- else
- pause=FALSE;
- SetTimer(1,1000-m_iSp*105,NULL);
- // TODO: Add your control notification handler code here
-
- }
- void CRussianGameDlg::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- if(newpiece==TRUE)
- {
- board.curpiece =board.nextpiece ;
- board.nextpiece =Random(8);
- if(board.nextpiece ==0)board.nextpiece=3;
- PaintNextPic();
- if(board.curpiece ==1)
- board.piecey =1;
- else
- board.piecey =2;
- board.piecex =5;
- board.piecepos =1;
- drawpiece();
- newpiece=FALSE;
- }
- else
- movepiecedown();
- InvalidateRect(&rect,FALSE);
- if(newpiece==TRUE)
- {
- checkforrows();
- }
- if(gameover==TRUE)
- {
- KillTimer(1);
- pause=FALSE;
- board.game =FALSE;
- checkforhighscore();
- MessageBox("游戏已结束,请重新开始!","俄罗斯方块游戏",MB_OK | MB_ICONINFORMATION);
- }
- CDialog::OnTimer(nIDEvent);
- }
- void CRussianGameDlg::checkforrows()
- {
- int i,j,rcount,k;
- rcount=0;
- bool r,row[19], goback;
- goback=TRUE;
- for(i= 18;i>0;i--)
- {
- r = TRUE;
- for(j = 1;j<11;j++)
- {
- if(board.square[j][i] == 0)
- {
- r = FALSE;
- break;
- }
- }
- row[i] = r;
- if(r == TRUE)
- {
- for(j = 1;j<11;j++)
- board.square[j][i] = 0;
- rcount = rcount + 1;
- }
- }
- if (FlagSound == TRUE && rcount>0) PlaySounds();
- for(i = 18;i>1;i--)
- {
- if(goback == TRUE)
- {
- i = i + 1;
- goback = FALSE;
- }
- if(row[i] == TRUE)
- {
- for(k = i;k>1;k--)
- {
- for(j = 1;j<11;j++)
- board.square[j][k] = board.square[j][k - 1];
- row[k] = row[k - 1];
- }
- goback = TRUE;
- }
- }
- InvalidateRect(&rect,FALSE);
- board.scroe = board.scroe + rcount * 100;
- board.rows = board.rows + rcount;
- board.level = board.rows/10 + 1;
- SetTimer(1,1000-board.level*105,NULL);
- return;
- }
- void CRussianGameDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- if(board.game ==TRUE)
- {
- switch(nChar)
- {
- case VK_LEFT:
- movepieceleft();
- break;
- case VK_RIGHT:
- movepieceright();
- break;
- case VK_UP:
- roatepiece();
- break;
- case VK_DOWN:
- while(newpiece==FALSE)
- {
- movepiecedown();
- }
- checkforrows();
- break;
- }
- }
-
- CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CRussianGameDlg::OnPause()
- {
- // TODO: Add your control notification handler code here
- pause=TRUE;
- KillTimer(1);
- }
- int CRussianGameDlg::Random(int MaxNumber)
- {
- unsigned int currentClock = (unsigned)time(NULL);
- srand(currentClock);
- return (rand() % MaxNumber);
- }
- void CRussianGameDlg::OnLineadd()
- {
- m_iLine++;
- if(m_iLine==16)m_iLine=0;
- Line_num.SetNumber(m_iLine);
- // TODO: Add your control notification handler code here
-
- }
- void CRussianGameDlg::PaintNextPic()
- {
- CDC *pDC=GetDC();
- CDC memdc;
- memdc.CreateCompatibleDC(pDC);
- memdc.SelectObject(picnext[board.nextpiece]);
- pDC->BitBlt(280,42,80,40,&memdc,1,1,SRCCOPY);
- ReleaseDC(pDC);
- }
- void CRussianGameDlg::OnSound()
- {
- // TODO: Add your control notification handler code here
- if(FlagSound==FALSE)
- {
- FlagSound=TRUE;
- GetDlgItem(IDC_SOUND)->SetWindowText("无声");
- }
- else
- {
- FlagSound=FALSE;
- GetDlgItem(IDC_SOUND)->SetWindowText("有声");
- }
- }
- BOOL CRussianGameDlg::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
- if(pMsg->message==WM_KEYDOWN)
- {
- OnKeyDown((UINT)pMsg->wParam,(UINT)pMsg->lParam,(UINT)pMsg->lParam);
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- void CRussianGameDlg::writescore()
- {
- AfxGetApp()->WriteProfileInt(_T("英雄榜"),_T("scorenum1"),scorenum[0]);
- AfxGetApp()->WriteProfileInt(_T("英雄榜"),_T("scorenum2"),scorenum[1]);
- AfxGetApp()->WriteProfileInt(_T("英雄榜"),_T("scorenum3"),scorenum[2]);
- AfxGetApp()->WriteProfileInt(_T("英雄榜"),_T("scorenum4"),scorenum[3]);
- AfxGetApp()->WriteProfileInt(_T("英雄榜"),_T("scorenum5"),scorenum[4]);
- AfxGetApp()->WriteProfileString(_T("英雄榜"),_T("scorename1"),scorename[0]);
- AfxGetApp()->WriteProfileString(_T("英雄榜"),_T("scorename2"),scorename[1]);
- AfxGetApp()->WriteProfileString(_T("英雄榜"),_T("scorename3"),scorename[2]);
- AfxGetApp()->WriteProfileString(_T("英雄榜"),_T("scorename4"),scorename[3]);
- AfxGetApp()->WriteProfileString(_T("英雄榜"),_T("scorename5"),scorename[4]);
- }
- BOOL CRussianGameDlg::PlaySounds()
- {
- if(PlaySound(MAKEINTRESOURCE(IDR_WAVESOUND),AfxGetInstanceHandle(),SND_ASYNC|SND_RESOURCE|SND_NODEFAULT))
- return TRUE;
- return FALSE;
- }