【发布时间】:2014-03-27 15:06:17
【问题描述】:
我正在做我的面向对象编程作业,其中要求我为孩子们创建一个接数游戏,以便他们在玩的过程中也可以学习数数。
在这里,我应该创建一个 Point 类和一个 x-y 坐标。在这里,我必须创建一个以 P(点对象作为参数)为参数的移位函数。此功能在用户按下键即箭头键时移动第一个点。
问题是我对在 c++ 中用于箭头键的实际关键字(如向上、向下、向左、向右移动)感到困惑,就像我们在普通游戏中用来移动物体或人一样! ???
下面是我的代码! 类点.h
#ifndef POINT_H
#define POINT_H
class Point
{
public:
Point(); // Default Constructor
Point(double, double, int); // Three argument constructor
void initialize(double, double, int);
void shift(Point p); // Shift the first point when user press keys
void setValue(int value);
int getValue() const;
void setX();
double getX() const;
void setY();
double gety() const;
void AddPointValue(Point p2); /*This function add the TWO points value
void displayPoint(); //This will use to display value of point
bool checkCoordinates();
bool checkTime(); // Check time remaining
private:
double x;
double y;
int value;
};
#endif
实施文件
#include <iostream>
#include <windows.h>
#include "point.h"
using namespace std;
Point::Point() // Default Constructor
{
x = 0;
y = 0;
value = 0;
}
Point::Point(double x1, double y1, int value1){ // Three argument constructor
x = x1;
y = y1;
value = value1;
}
void Point::initialize(double init_x, double init_y, int init_value)
{
x = init_x;
y = init_y;
value = init_value;
}
void Point::shift(Point p){
if(p == VK_LEFT)
{
}else if(p == VK_RIGHT)
{
}else if(p == VK_UP)
{
}else if(p == VK_DOWN)
{
}
}
它现在给我一个错误,不匹配运算符==(操作数类型'point'和'int')
【问题讨论】:
-
这是什么操作系统?答案可能因操作系统而异。
-
你是操作系统吗?如果我做对了,可能是窗户
-
是的操作系统,非常好,我可以用 Windows 术语来表达我的答案:)
-
谢谢。我在等:)