⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gameboard.cpp

📁 C++高级编程这本书所附的源代码
💻 CPP
字号:
// GameBoard.cpp#include "GameBoard.h"// Microsoft Visual Studio requires you to omit the following two lines.// However, some compilers require them.//const int GameBoard::kDefaultWidth;//const int GameBoard::kDefaultHeight;GameBoard::GameBoard(int inWidth, int inHeight) :  mWidth(inWidth), mHeight(inHeight){  mCells = new GamePiece* [mWidth];  for (int i = 0; i < mWidth; i++) {    mCells[i] = new GamePiece[mHeight];  }}GameBoard::GameBoard(const GameBoard& src){  copyFrom(src);}GameBoard::~GameBoard(){  // free the old memory  for (int i = 0; i < mWidth; i++) {    delete [] mCells[i];  }  delete [] mCells;}void GameBoard::copyFrom(const GameBoard& src){  int i, j;  mWidth = src.mWidth;  mHeight = src.mHeight;  mCells = new GamePiece* [mWidth];  for (i = 0; i < mWidth; i++) {    mCells[i] = new GamePiece[mHeight];  }  for (i = 0; i < mWidth; i++) {    for (j = 0; j < mHeight; j++) {      mCells[i][j] = src.mCells[i][j];    }  }}GameBoard& GameBoard::operator=(const GameBoard& rhs){  // check for self-assignment  if (this == &rhs) {    return (*this);  }  // free the old memory  for (int i = 0; i < mWidth; i++) {    delete [] mCells[i];  }  delete [] mCells;  // copy the new memory  copyFrom(rhs);  return (*this);}void GameBoard::setPieceAt(int x, int y, const GamePiece& inElem){  mCells[x][y] = inElem;}GamePiece& GameBoard::getPieceAt(int x, int y){  return (mCells[x][y]);}const GamePiece& GameBoard::getPieceAt(int x, int y) const{  return (mCells[x][y]);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -