Skip to main content
added 2 characters in body
Source Link
Eric
  • 4k
  • 1
  • 20
  • 29

Two observations:

  1. Your condition system seems to have two orthogonal axes: temperature and poison. Represent them as such.
  2. When thinking about this you should separate transitionstransitions from statesstates. COLDCOLD and HOTHOT are state transitions in the way you mention them, not states.

Combining those observations would result in something like this:

// These is the representation of the two axes.
int temperature; // can be between -2 and +2, 0 is normal, 1 is hot, 2 is burning, -1 is cold, -2 is frozen
bool poisoned;

// These methods represent state transitions.
void applyHeat() {
    if ( temperature <= 32 ) {
        ++temperature;
    }
}

void applyCold() {
    if ( temperature >= -32 ) {
        --temperature;
    }
}

void applyPoison() {
    poisoned = true;
}

void removePoison() {
    poisoned = false;
}
  1. Your condition system seems to have two orthogonal axes: temperature and poison. Represent them as such.
  2. When thinking about this you should separate transitions from states. COLD and HOT are state transitions in the way you mention them, not states.

Combining those observations would result in something like this:

// These is the representation of the two axes.
int temperature; // can be between -2 and +2, 0 is normal, 1 is hot, 2 is burning, -1 is cold, -2 is frozen
bool poisoned;

// These methods represent state transitions.
void applyHeat() {
    if ( temperature <= 3 ) {
        ++temperature;
    }
}

void applyCold() {
    if ( temperature >= -3 ) {
        --temperature;
    }
}

void applyPoison() {
    poisoned = true;
}

void removePoison() {
    poisoned = false;
}

Two observations:

  1. Your condition system seems to have two orthogonal axes: temperature and poison. Represent them as such.
  2. When thinking about this you should separate transitions from states. COLD and HOT are transitions in the way you mention them, not states.

Combining those observations would result in something like this:

// These is the representation of the two axes.
int temperature; // can be between -2 and +2, 0 is normal, 1 is hot, 2 is burning, -1 is cold, -2 is frozen
bool poisoned;

// These methods represent state transitions.
void applyHeat() {
    if ( temperature <= 2 ) {
        ++temperature;
    }
}

void applyCold() {
    if ( temperature >= -2 ) {
        --temperature;
    }
}

void applyPoison() {
    poisoned = true;
}

void removePoison() {
    poisoned = false;
}
Source Link
Eric
  • 4k
  • 1
  • 20
  • 29

  1. Your condition system seems to have two orthogonal axes: temperature and poison. Represent them as such.
  2. When thinking about this you should separate transitions from states. COLD and HOT are state transitions in the way you mention them, not states.

Combining those observations would result in something like this:

// These is the representation of the two axes.
int temperature; // can be between -2 and +2, 0 is normal, 1 is hot, 2 is burning, -1 is cold, -2 is frozen
bool poisoned;

// These methods represent state transitions.
void applyHeat() {
    if ( temperature <= 3 ) {
        ++temperature;
    }
}

void applyCold() {
    if ( temperature >= -3 ) {
        --temperature;
    }
}

void applyPoison() {
    poisoned = true;
}

void removePoison() {
    poisoned = false;
}