Chinaunix首页 | 论坛 | 博客
  • 博客访问: 666928
  • 博文数量: 156
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1201
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-05 20:08
文章分类

全部博文(156)

文章存档

2010年(13)

2008年(39)

2007年(104)

我的朋友

分类: C/C++

2007-06-09 21:41:03

// gameView.h : interface of the CGameView class

//

/////////////////////////////////////////////////////////////////////////////


#if !defined(AFX_GAMEVIEW_H__56F34070_2024_4E08_87FC_D2F3E768D357__INCLUDED_)
#define AFX_GAMEVIEW_H__56F34070_2024_4E08_87FC_D2F3E768D357__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include "link.h"

/*
    define the macros to be used
    directory `Move`
*/

#define MOVE_LEFT        1
#define MOVE_RIGHT        2
#define MOVE_DOWN        3
#define CHANGE            4

/* russia's spec `row` and `col` */
#define SPEC_ROW        18
#define SPEC_COL        12
/* client view's `width` and `high` */
#define SPEC_WIDTH        500        //单位为像素

#define SPEC_HIGH        550
/* block size */
#define BLOCK_SIZE        30
/* windows high, not the same with SPEC_HIGH! */
#define WND_HIGH        590

/*
 下面,来定义方块数据结构 4 * 4
  GRAN -> granularity (粒度)
 */

#define GRAN_SIZE        4

/*
  图形的种类是有限的,宏的种类总数
 */

#define BLOCK_COUNT        7 /* 共有七种 */

/*
  方块的外形属性 :
 */

    /*
     1 : ####
     */

    /*
     2 : #
     ###
     */

    /*
     3 : #
         ###
     */

    /*
     4 : ##
         #
             ##
     */

    /*
     5 : ##
         #
             ##
     */

    /*
     6 : ##
         ##
     */

    /*
     7 : #
         ###
     */

#define SHAPE_LINE        1
#define SHAPE_GUN        2    /* the shape like a gun */
#define    SHAPE_TWO        3    /* like the number `2` */
#define    SHAPE_BLOCK        4    /* a big block */
#define    SHAPE_TRIANGLE    5    /* 像一个三角形,你觉得呢 -_- */


class CGameView : public CView
{
protected: // create from serialization only

    CGameView();
    DECLARE_DYNCREATE(CGameView)

// Attributes

public:
    CGameDoc* GetDocument();

// Operations

public:

// Overrides

    // ClassWizard generated virtual function overrides

    //{{AFX_VIRTUAL(CGameView)

    public:
    virtual void OnDraw(CDC* pDC); // overridden to draw this view

    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    protected:
    virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
    //}}AFX_VIRTUAL


// Implementation

public:
    virtual ~CGameView();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions

protected:
    //{{AFX_MSG(CGameView)

    afx_msg void OnTimer(UINT nIDEvent);
    afx_msg void OnRestart();
    afx_msg void OnPause();
    afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()

private:
/* 在这里声明我们要用到的一些成员变量 */
/* bitmap */
    CBitmap            m_background;    /* background graphic */
    CBitmap            m_block;        /* block of russia */
    CBitmap            m_bgblock;        /* background block */
    CBitmap            m_gamescore;    /* game score background */
    CBitmap            m_gamelevel;    /* game level background */
    CBitmap            m_gamenext;        /* game next background */

/* the planar array to stroe the datas */
    BOOL            m_data[SPEC_ROW][SPEC_COL];
/* 游戏的特性 */
    short            m_level;        /* 一共 1 - 9 层 */
                                    /* 还有一点要说明的是:方格下落的速度也是根据m_level */
    short            m_score;        /* 每100分可以进入下一层 */
    BOOL            m_current[GRAN_SIZE][GRAN_SIZE];    /* 当前图形的形状 */
    BOOL            m_next[GRAN_SIZE][GRAN_SIZE];        /* 下一图 */
    short            m_cur_pro;        /* 当前方块图的属性 */
    short            m_next_pro;        /* 下一块的属性 */
    short            m_x;            /* 当前方块所在地左上角的XY座标 */
    short            m_y;

    struct l_node*    m_graphic;        /* 方块库,是一个链表 */
/* 关于游戏的重新开始与暂停 */
    BOOL            m_restart;
    BOOL            m_pause;
    BOOL            m_gameover;

public:
/* 这里添加我们的成员方法 */
    /*     
 ------------------------------------------------------    |
 方块的移动 --> 方块移动的接口函数                        |
 @@return : 如果返回的是false,证明游戏已经结束了!        |
 否则表明,已经顺利移运.                                    |
 ##param : flag -> MOVE_LEFT or MOVE_RIGHT or MOVE_DOWN    |
 -------------------------------------------------------
 ***********--------> 注意!! <---------***************
 我们在VIEW类中,接收到键盘消息的时候,我们知道用户按的是哪一个键,然后,我们要
 做的只是把MOVE_LEFT...RIGHT DOWN 作为参数传给move函数就可以了,而不用管其它东西!
 包括这个方块是否可以移动,移动之后界面的刷新,等等,这些问题都不用管!

  ----> 也就是说,move是一个接口函数,他是"强大"的,所以,我们要写一些辅助函数
*/

    BOOL            move (int flag);

/*----------------------------------------------------------
 move的辅助函数
 can left
 can right
 can down
 我们不用传参给他,因为,我们可以利用类成员变量 :
 m_current m_x m_y m_data !

 ************注意!!*************
 当candown反回假的时候,意味着本方块已经尘埃落定了
-----------------------------------------------------------*/

    BOOL            canleft (void);
    BOOL            canright (void);
    BOOL            candown (void);
/*---------------------------------------------------------
 #move left right down#在判断之后,如果能够移动,那么,我们就可以
 调用这三个函数来移动了
 ----------------------------------------------------------*/

    void            moveleft (void);
    void            moveright (void);
    void            movedown (void);
/*----------------------------------------------------------
 形变 : 这是一个重要的问题
 @@return : 如果返回的是TRUE,表明change函数已经更新了m_current的数
 据,所以,我们要重画用户界面
 相反,如果返回的是FALSE,表明,不可形变,m_current还是原来的值,所以
 不用更新用户界面!
------------------------------------------------------------*/

    BOOL            change (void);
/*----------------------------------------------------------
 下面,是另一个重要问题 : 产生随机的方块图按.
 我的做法是 : 用一个BOOL形的二维数组来存储图按
 而图按的种类是有限的 总数为宏BLOCK_COUNT中指定
 ****************!!!************************
 关于随机生成,我的做法是 :
 在view类的构造函数中,我初始化一个关于所有方块图案的链表
 然后,在程序运行的过程中,如果需要要生成随机的方块,那么,我只需要
 生成一个随机数N,然后,我循环N次这个循环链表,就可以得
 到这个随机的方块图了``
------------------------------------------------------------*/

    void            getrand (void);

/*
    get next, copy next to current !
    */

    void            getnext (void);
/*
    重新开始时,重新设定数据
    */

    void            restart (void);

/* draw current */
    void            draw_cur (void);
/*
    join the m_current to m_data!
    */

    void            join (void);
/*
    clean
    */

    void            clean (void);

/*
    write level, speed
    */

    void            reflush_level (void);
/* write score */
    void            reflush_score (void);
/* write next */
    void            reflush_next (void);
};

#ifndef _DEBUG // debug version in gameView.cpp

inline CGameDoc* CGameView::GetDocument()
   { return (CGameDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////


//{{AFX_INSERT_LOCATION}}

// Microsoft Visual C++ will insert additional declarations immediately before the previous line.


#endif // !defined(AFX_GAMEVIEW_H__56F34070_2024_4E08_87FC_D2F3E768D357__INCLUDED_)

teris的头文件,^_^

本代码作者 偶像的黄昏 qq:63879757

来自 qq群 Freedom Fighters 号码33261729

阅读(1462) | 评论(0) | 转发(0) |
0

上一篇:ACM比赛介绍

下一篇:Tetris Game

给主人留下些什么吧!~~