📄 board.h
字号:
// ************************************************************
// The main board to display the game, it is a dynamic method
// to create the board by the Create(),
//
// Author: Flowstar
// Date: 2002.12.09
//
// ************************************************************
// Board.h : header file
#if !defined(AFX_BOARD_H__2C134862_4DB6_4687_B50F_3BE7A3E772E5__INCLUDED_)
#define AFX_BOARD_H__2C134862_4DB6_4687_B50F_3BE7A3E772E5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxtempl.h> // for the CList class
#include "Picture.h"
#include "DigitalPlayer.h"
#include "BtnST.h"
#include "FsMidi.h"
// Define the const
const int ROWS = 18; // Game cell area
const int COL_CTL = 6; // Control area
const int COLS = 10;
const int WIDTH = 20;
const int SPAN = 4; // Splitter line's width
const int TIME_SPAN = 50; // The game speed span
//CRITICAL_SECTION gCritical;
/////////////////////////////////////////////////////////////////////////////
// CBoard window
class CBoard : public CStatic
{
// Construction
public:
CBoard();
// Attributes
public:
typedef enum { // move types
MOVE_UP,
MOVE_DOWN,
MOVE_LEFT,
MOVE_RIGHT
}MOVETYPE;
typedef enum{ // Game state
GAME_READY,
GAME_PAUSE,
GAME_PLAYING
}GAMESTATE;
typedef enum{ // Timer type
TIMER_SNAKE = 1,
TIMER_CELL,
TIMER_READY,
TIMER_OVER,
TIMER_WIN
};
// Operations
public:
void StartGame(void);
void EndGame(bool bWinGame = false, bool bGameOver = false);
void PauseGame(void);
void ResumeGame(void);
void Move(MOVETYPE movetype);
bool EnableSound(bool bSound = true);
void SetSpeed(int nSpeed = 1, bool bRestart = true);
static UINT PlayBkMusic(LPVOID pParam);
inline int GetGameState(void) const{ return m_nState; };
protected:
// Draw the board's cell, if (bEarse == false), draw the background picture
void DrawCell(CDC *pDC, CPoint ptCell, bool bErase = true);
void DrawCellF(CDC *pDC, CPoint ptCell, UINT nID = -1, bool bErase = true);
// Draw the snake shape, if false, draw the background
void DrawSnake(CDC *pDC, bool bErase = true, bool bAll = false);
void DrawPlayers(int nPlayer, bool bErase = true);
// the egg of the snake want to eat, flash
void FlashCell(CDC *pDC, CPoint pt);
// Random select the egg
CPoint RandomSelCell(void);
void SetScores(int nScore);
// Validate the moving is or not exceed the border, or itself
bool ValidateMoving(CPoint pt);
void InitSnake(void);
bool EatAgg(CPoint pt);
void SwapSnakeCell(CPoint pt);
// reverse the snake data, and head become tail,and moving
void MoveBackword();
void SpeedUp(bool bRestart = true);
void DrawMyText(CDC *pDC, CString sText, CRect rtClient, int nSize = 7, COLORREF cr = RGB(255, 0, 253));
void WinGame();
// 1 is round over, 2 is game over
void LostGame(int nEvent = 1);
void ReadyGame(bool bOver = false);
protected:
// Class Members
public:
protected:
int m_nSpeed; // the timer elapse
int m_nSpeedLevel; // speed level
int m_nSnakeCount; // the snake length
int m_nScores;
int m_nDeadSum; // the player deads count
int m_nFlag; // is 0 or 1, flash egg
CPoint m_ptFlashCell; // the flash point
byte m_bData[ROWS][COLS];
GAMESTATE m_nState; // the game state
bool m_bSound;
bool m_bBootGame;
bool m_bWinGame;
bool m_bReadyGame;
CDC m_dcBk;
CDC m_dcFr; // CDC for foreground
CRect m_rtClient; // game display area(all)
CRect m_rtClientLeft; // game area(left)
CPicture *m_picBackground; // background picture
CPicture *m_picForeground; // foreground picture
CBitmap *m_pbmpPlayer; // the players icon
CList<CPoint, CPoint> m_Snake; // the snake
CPoint m_ptHead; // Snake head
MOVETYPE m_mtCurrent; // the current movetype
MOVETYPE m_mtPrevious; // the previous movetype
CDigitalPlayer m_dpScore;
CDigitalPlayer m_dpSpeed;
CButtonST m_btnSound;
CButtonST m_btnStart;
CButtonST m_btnPause;
CButtonST m_btnRestart;
CButtonST m_btnEnd;
public:
CFsMidi m_MidBk;
// HANDLE m_hMusic;
static int m_nMidState;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBoard)
public:
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CBoard();
// Generated message map functions
protected:
//{{AFX_MSG(CBoard)
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
afx_msg void OnBtnSound();
afx_msg void OnBtnStart();
afx_msg void OnBtnPause();
afx_msg void OnBtnRestart();
afx_msg void OnBtnEnd();
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_BOARD_H__2C134862_4DB6_4687_B50F_3BE7A3E772E5__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -