Source Code (Use browser search to find items of interest.)

Class Index

ksokoban'LevelMap (./kdegames/ksokoban/LevelMap.H:31)

class LevelMap : public Map {
public:
  LevelMap();
  ~LevelMap();

  LevelCollection *collection() { return collection_; }
  const QString &collectionName();
  void changeCollection(LevelCollection *_collection);
  int totalMoves() { return totalMoves_; }
  int totalPushes() { return totalPushes_; }
  void level(int _level);
  int level();
  int noOfLevels();
  int completedLevels();
  bool goodLevel() { return goodLevel_; }

  bool step(int _x, int _y);
  bool push(int _x, int _y);
  bool unstep(int _x, int _y);
  bool unpush(int _x, int _y);

  //void random();

protected:
  LevelCollection *collection_;


private:
  int    totalMoves_;
  int    totalPushes_;
  bool   goodLevel_;

  static int distance(int x1, int y1, int x2, int y2);
};

ksokoban'LevelMap::collectionName() (./kdegames/ksokoban/LevelMap.C:42)

LevelMap::collectionName() {
  return collection_->name();
}


ksokoban'LevelMap::LevelMap() (./kdegames/ksokoban/LevelMap.C:46)

LevelMap::LevelMap () : collection_(0), totalMoves_(0), totalPushes_(0),
			goodLevel_(false) {
}


ksokoban'LevelMap::~LevelMap() (./kdegames/ksokoban/LevelMap.C:50)

LevelMap::~LevelMap () {
}

void

ksokoban'LevelMap::changeCollection() (./kdegames/ksokoban/LevelMap.C:54)

LevelMap::changeCollection (LevelCollection *_collection)
{
  collection_ = _collection;
  goodLevel_ = collection_->loadLevel(this);
  totalMoves_ = totalPushes_ = 0;
}

int

ksokoban'LevelMap::level() (./kdegames/ksokoban/LevelMap.C:62)

LevelMap::level () {
  if (collection_ == 0) return 0;
  return collection_->level();
}

void

ksokoban'LevelMap::level() (./kdegames/ksokoban/LevelMap.C:68)

LevelMap::level (int _level) {
  assert(collection_ != 0);

  collection_->level(_level);
  goodLevel_ = collection_->loadLevel(this);

  totalMoves_ = totalPushes_ = 0;
}

int

ksokoban'LevelMap::noOfLevels() (./kdegames/ksokoban/LevelMap.C:78)

LevelMap::noOfLevels () {
  assert(collection_ != 0);
  return collection_->noOfLevels();
}

int

ksokoban'LevelMap::completedLevels() (./kdegames/ksokoban/LevelMap.C:84)

LevelMap::completedLevels () {
  assert(collection_ != 0);
  return collection_->completedLevels();
}

int

ksokoban'LevelMap::distance() (./kdegames/ksokoban/LevelMap.C:90)

LevelMap::distance (int x1, int y1, int x2, int y2) {
  int d;

  if (x2 > x1) d = x2-x1;
  else d = x1-x2;

  if (y2 > y1) d += y2-y1;
  else d += y1-y2;

  return d;
}

bool

ksokoban'LevelMap::step() (./kdegames/ksokoban/LevelMap.C:103)

LevelMap::step (int _x, int _y) {
  int oldX=xpos_, oldY=ypos_;

  bool success = Map::step (_x, _y);

  totalMoves_ += distance (oldX, oldY, xpos_, ypos_);

  return success;
}

bool

ksokoban'LevelMap::push() (./kdegames/ksokoban/LevelMap.C:114)

LevelMap::push (int _x, int _y) {
  int oldX=xpos_, oldY=ypos_;

  bool success = Map::push (_x, _y);

  int d = distance (oldX, oldY, xpos_, ypos_);
  totalMoves_ += d;
  totalPushes_ += d;

  if (completed ()) collection_->levelCompleted();

  return success;
}

bool

ksokoban'LevelMap::unstep() (./kdegames/ksokoban/LevelMap.C:129)

LevelMap::unstep (int _x, int _y) {
  int oldX=xpos_, oldY=ypos_;

  bool success = Map::unstep (_x, _y);

  totalMoves_ -= distance (oldX, oldY, xpos_, ypos_);

  return success;
}

bool

ksokoban'LevelMap::unpush() (./kdegames/ksokoban/LevelMap.C:140)

LevelMap::unpush (int _x, int _y) {
  int oldX=xpos_, oldY=ypos_;

  bool success = Map::unpush (_x, _y);

  int d = distance (oldX, oldY, xpos_, ypos_);
  totalMoves_ -= d;
  totalPushes_ -= d;

  return success;
}

#if 0
void
LevelMap::random (void) {
  printf ("start!\n");

  minX_ = 0;
  minY_ = 0;
  maxX_ = MAX_X;
  maxY_ = MAX_Y;
  totalMoves_ = totalPushes_ = 0;
  clearMap ();
  
  xpos_ = 13;
  ypos_ = 9;

  KRandomSequence random(0);

  for (int i=0; i<200; i++) {
    map (xpos_, ypos_, FLOOR);

    switch (random.getLong(4)) {
    case 0:
      if (ypos_ > 1) ypos_--; else i--;
      break;

    case 1:
      if (ypos_ < MAX_Y-1) ypos_++; else i--;
      break;

    case 2:
      if (xpos_ > 1) xpos_--; else i--;
      break;

    case 3:
      if (xpos_ < MAX_X-1) xpos_++; else i--;
      break;
    }
  }

  for (int y=1; y<MAX_Y; y++) {
    for (int x=1; x<MAX_X; x++) {
      if (map (x, y) & FLOOR) {
	if (!(map (x, y-1) & FLOOR)) map (x, y-1, WALL);
	if (!(map (x, y+1) & FLOOR)) map (x, y+1, WALL);
	if (!(map (x-1, y) & FLOOR)) map (x-1, y, WALL);
	if (!(map (x+1, y) & FLOOR)) map (x+1, y, WALL);
      }
    }
  }

  printf ("klar!\n");
  printMap ();
}