[ create a new paste ] login | about

Link: http://codepad.org/jf1PC5LW    [ raw code | fork ]

totoPon - C++, pasted on May 22:
/*------------------------------------------------
 * TetrisBase.hpp - テトリスの基盤となるプログラム
 *------------------------------------------------*/

#ifndef TETRISBASE_HPP_
#define TETRISBASE_HPP_

#include <stdint.h>
#include <vector>

#include "TetrisDefines.hpp"

namespace TetrisBase
{

  // 操作中のテトリミノ
  class CurrentTetro
  {
  private:
    enum{ MAX_TETRO=gMaxTetro }; // テトリミノの種類(+null)
    enum{ MAX_BLOCK=gMaxBlock }; // 1テトリミノあたりのブロック最大数
    static const Tetro *tetro; // テトリミノのブロック情報

  private:
    Position pos; // 座標
    int8_t rot; // 回転回数
    int8_t type; // テトリミノの種類
    Position blocks[MAX_BLOCK]; // ブロック位置

  public:
    void fall(); // 下に移動(1ライン)
    void moveY(int8_t addY); // 上下移動(addYの分だけ)
    int rotate(int8_t r); // 回転する
    void moveX(int8_t addX); // 左右移動(addXの分だけ)
    void moveTo(const Position &pos); // 座標を移動する
    void moveTo(int8_t x, int8_t y); // 座標を移動する
    void changeTetro(int8_t type); // テトリミノを変更する
    void getBlockPos(int id, Position &dst) const; // ブロックの位置(絶対座標)を返す
    void getMaxPos(Position &dst) const; // ブロックの相対座標の最大値を返す
    void getMinPos(Position &dst) const; // ブロックの相対座標の最小値を返す
    int8_t getType() const; // テトリミノの種類を返す
    void getPos(Position &dst) const; // テトリミノの座標を返す

    int getBlockNum() const; // 全テトリミノ中でのブロック使用最大数を返す
    int getBlockNum(int id) const; // 指定したテトリミノのブロック数を返す

    int8_t getMaxTetro() const; // テトリミノの種類数を返す

  public:
    CurrentTetro();
    ~CurrentTetro();

  public:
    CurrentTetro(const CurrentTetro&);
    CurrentTetro &operator=(const CurrentTetro&);

  private:
    void copy(const CurrentTetro&);

  public:
    bool operator==(const CurrentTetro&) const;
    bool operator!=(const CurrentTetro&) const;
  };

  // フィールド
  class TetrisField
  {
  private:
    enum{ FIELD_X=gFieldX, FIELD_Y=gFieldY };
    int8_t field[FIELD_X+2][FIELD_Y+1]; // フィールド(左右と下に番兵)

  private:
    bool isInField(int x, int y) const; // フィールド範囲内を指定出来ているか
    int fillClearable(int8_t line); // 指定ラインのブロックに、消去可能フラグを立てる

  public:
    void clearField(); // フィールドを初期化する

    // canPut() - テトリミノの配置可否を確認する。
    //            置けない場合は負の値、壁蹴りして配置できるなら1が返される
    int canPut(const CurrentTetro &tetro); // 通常モード
    int canPut(const CurrentTetro &tetro, CurrentTetro &refference); // 壁蹴り後を返す

    int putBlock(const Position &pos, int8_t type); // 指定位置にブロックを配置
    int rmBlock(const Position &pos); // 指定位置のブロックを消去

    // putTetro() - フィールド上にテトリミノを配置する
    int putTetro(const CurrentTetro &tetro); // 通常
    int putTetro(const CurrentTetro &tetro, int8_t type); // 配置番号を指定

    int rmTetro(const CurrentTetro &tetro); // フィールドからテトリミノを消去

    // getBlock() - 指定位置のブロックを取得
    int getBlock(const Position &pos) const;
    int getBlock(int x, int y) const;

    int clearClearable(); // 消去可能フラグが立っているラインを消去

    // 消去可能なライン数を返す(任意で消去可能フラグを立てる)
    int getClearable(bool setFlag);

    void getFieldSize(int &x, int &y) const; // フィールドサイズの取得
    void getField(std::vector<std::vector<int8_t> > &dst) const; // フィールドを取得

  public:
    TetrisField();
    ~TetrisField();

  private:
    TetrisField(const TetrisField&);
    TetrisField &operator=(const TetrisField&);
  };

} // namespace

#endif // TETRISBASE_HPP_


Create a new paste based on this one


Comments: