例のやつ

//ch1gam.cpp
#include <iostream>
#include <cstdio>
#include "Object.h"

using namespace std;
/*
0000
.po#	の順に
*/


int main() {
	Stage stage1(5,8);
	char s1map[5][8] = { 
		{1,1,1,1,1,1,1,1},
		{1,0,8,8,0,4,0,1},
		{1,0,2,2,0,0,0,1},
		{1,0,0,0,0,0,0,1},
		{1,1,1,1,1,1,1,1},
	};
	stage1.SetMap(s1map);
	stage1.Create();
	
	int key;
	while((key = getchar()) != EOF) {
		if(key !='\n') {
		stage1.Move(key);
		stage1.Create();
		}
		if(stage1.IsClear()) {
			printf("OKOK\n");
			break;
		}
	}
//	for(int i=0;i<stage1.GetRow();i++) {
//		delete[] s1map[i];
//	}

	return 0;
}

//Object.h
/*
class Object {
protected:
	int x,y;	//位置
	char** stage;
	int row, col;
	bool Rule(int x, int y);
public:
	virtual void Init() {;}
	void Show();
	void Move(char key);
	
};
*/

class Stage {
private:
	char map[5][8];
	int pos_x,pos_y;
	int dotcount;
	int row;
	int col;
public:
	int GetRow();
	int GetCol();
	void SetMap(char map[5][8]);
	void Create();
	void Move(int key);
	bool IsClear();

	Stage(int row, int col);
//	virtual ~Stage();

};



//Object.cpp
#include "Object.h"
#include <stdlib.h>
#include <cstdio>

/*ビットの扱い方*
0000
.po#	とする

bool b;
int ans;
int qt;	//要素の属性

b = qt&4	//qtにp(player)が含まれていればb=true;

ans = qt|4 //qtにp(player)の属性を加える
ans = qt&(~4)	//qtにp(player)の属性を除く
*/

Stage::Stage(int row, int col) {
	this->row = row;	//左側のrow:クラス内のrow
	this->col = col;	//右側のcol:クラス内のcol
	//thisをつけたほうが無難。なぜなら、複数で開発する際にrowが使われているかわからないので、仮に引数を変えたとしても、
	//クラス内のメンバと一致する可能性があるから。
}
/*
Stage::~Stage() {
	for(int i=0;i<row;i++) {
		delete[] map[i];
	}
}
*/

int Stage::GetRow() {
	return this->row;
}
int Stage::GetCol() {
	return this->col;
}

void Stage::SetMap(char m[5][8]) {
	this->dotcount = 0;
	for(int i=0;i<row;i++) {
		for(int j=0;j<col;j++) {
			map[i][j] = m[i][j];
			if(map[i][j]&4) {
				this->pos_x = i;
				this->pos_y = j;
			}
			if(map[i][j]&8) {
				this->dotcount++;
			}
		}
	}
}


void Stage::Create() {
	//system("cls");
	for(int i=0;i<5;i++) {
		for(int j=0;j<8;j++) {
			switch (map[i][j]) {
			case (1):
				putchar('#');
				break;
			case (2|8):
				putchar('O');
				break;
			case (2):
				putchar('o');
				break;
			case (4|8):
				putchar('P');
				break;
			case (4):
				putchar('p');
				break;
			case (8):
				putchar('.');
				break;
			default:
				putchar(' ');
				break;
			}
		}
		putchar('\n');
	}
	printf("%d\n", dotcount);

}

void Stage::Move(int key) {
	int dir[5][2] = {
		{0,-1},
		{1,0},
		{0,1},
		{-1,0},
		{0,0}
	};
	int m;
	int x,y,nx,ny, f_nx, f_ny;
	switch (key) {
	case 'a':
		m = 0;
		break;
	case 's':
		m = 1;
		break;
	case 'd':
		m =2;
		break;
	case 'w':
		m = 3;
		break;
	default:
		m=4;
		break;
	}
	x = this->pos_x; y = this->pos_y;
	nx = x+dir[m][0]; ny = y+dir[m][1];
	if(nx >= 0 && nx < 5 && ny >= 0 && ny < 8) {
		
		if(!(map[nx][ny]&3) ) {
			map[x][y] = map[x][y]&(~4);
			map[nx][ny] = map[nx][ny]|4;
			pos_x = nx; pos_y = ny;

		} else if(map[nx][ny]&2) {
			f_nx = x+2*dir[m][0]; f_ny=y+2*dir[m][1];

			if(map[f_nx][f_ny]&3) {
				;//移動できない
			} else {
				if(map[f_nx][f_ny]==8) {
					this->dotcount--;
				}
				if(map[nx][ny]==(2|8)) {
					this->dotcount++;
				}
				map[f_nx][f_ny] = map[f_nx][f_ny]|2;
				map[nx][ny] = (map[nx][ny]|4)&~2;
				map[x][y] = map[x][y]&(~4);
				pos_x = nx; pos_y = ny;
			}
		}
	}
}

bool Stage::IsClear() {
	if(dotcount==0) {
		return true;
	}
	return false;
}