You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# pragma once
# include "map.h"
# define DIR_NONE 0
# define DIR_UP 1
# define DIR_DOWN -1
# define DIR_RIGHT 2
# define DIR_LEFT -2
class Mover
{
private :
int new_x ;
int new_y ;
int old_x ;
int old_y ;
int new_dir ;
int old_dir ;
int speed ;
int width ;
int height ;
// 尝试按dir方向移动, 并给出new_xy值
bool TryMove ( int dir , int & nx , int & ny , const Map * map )
{
/* 等待完善 */
// 判断是否脱轨
// 判断是否撞墙
// 判断是否穿越边界
return true ;
}
public :
void SetDir ( int dir ) { new_dir = dir ; }
void SetXY ( int x , int y ) { new_x = x ; new_y = y ; }
void SetOldXY ( int x , int y ) { old_x = x ; old_y = y ; }
void SetSpeed ( int s ) { speed = s ; }
void SetWH ( int w , int h ) { width = w ; height = h ; }
int GetX ( ) const { return new_x ; }
int GetY ( ) const { return new_y ; }
int GetOldX ( ) const { return old_x ; }
int GetOldY ( ) const { return old_y ; }
int GetW ( ) const { return width ; }
int GetH ( ) const { return height ; }
bool Move ( const Map * map )
{
int nx , ny ;
bool s = TryMove ( new_dir , nx , ny , map ) ;
// 如果新dir移动失败, 将尝试使用旧dir移动
if ( s = = false & & old_dir ! = new_dir )
{
s = TryMove ( old_dir , nx , ny , map ) ;
}
// 两种移动策略中,有一种成功,则
if ( s )
{
old_x = new_x ;
old_y = new_y ;
old_dir = new_dir ;
new_x = nx ;
new_y = ny ;
}
return s ;
}
// 初始化
void Init ( int x , int y , int s , int w , int h )
{
old_x = x ;
old_y = y ;
new_x = x ;
new_y = y ;
speed = s ;
old_dir = DIR_NONE ;
new_dir = DIR_NONE ;
width = w ;
height = h ;
}
} ;