C++ 编程请教问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 16:10:43
两个object(A和B吧),扮演警察和小偷的游戏,假设A-警察,B-小偷,
在一个固定尺寸的点阵范围内,A受ASDW控制上下左右,B随机出现在点阵范围内(不是完全随机,跳动方向是随机,移动步数还是一格一格),当A与B重合,即打印出胜利信息。

面向对象编程,请教达人能提供一些参考实现方法,谢谢!!!高分

//图已发到:http://hi.baidu.com/%BD%F0%C3%AB%CA%A8%CD%F52007

//完全面向对象
//VC2008编译通过,已测试。
//vc6下编译如出错,请在using namespace std;后加上
extern "C" WINBASEAPI HWND WINAPI GetConsoleWindow ();

#include<iostream>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
using namespace std;
#define BOUNDRY_TOP 20
#define BOUNDRY_BOTTOM 200
#define BOUNDRY_LEFT 20
#define BOUNDRY_RIGHT 100

class object{
int x,y,width,height;
int last_x,last_y;//上次的位置
COLORREF color;
public:
void move(int direction);
void draw();
friend bool caught(object police,object thief);
object(int _x,int _y,int _w,int _h,COLORREF _c):x(_x),y(_y),width(_w),height(_h),color(_c){}
};
void object::draw(){
HWND hwnd;
HDC hdc;
hwnd =