Changes

Jump to: navigation, search

State

3,652 bytes added, 23:31, 12 April 2007
no edit summary
_pState->Operate();
}
</pre>
 
=== Game programming: Character Status ===
'''Abstract Class'''
<pre>
 
 
using System;
using System.Drawing;
 
namespace StatePatternApp
{
/// <summary>
/// Summary description for State.
/// </summary>
public abstract class State
{
public State()
{
}
public State(State state)
{
this.CurrentLevel = state.CurrentLevel;
this.Deviation = state.Deviation;
this.MaxLevel = state.MaxLevel;
this.MinLevel = state.MinLevel;
this.Machine = state.Machine;
this.SetParams();
}
public State(Machine machine, int iCurrentLevel,
int iDeviation, int iMaxLevel, int iMinLevel)
{
this.CurrentLevel = iCurrentLevel;
this.Deviation = iDeviation;
this.MaxLevel = iMaxLevel;
this.MinLevel = iMinLevel;
this.Machine = machine;
this.SetParams();
}
private Machine machine;
private int minLevel = 0;
private int maxLevel = 0;
private int currentLevel = 0;
private int deviation = 0;
private Color messageColor = Color.Green;
private string messageText = "";
public virtual void SetParams(){}
public virtual void CheckEfficiency()
{
Transition t = Transition.GetInstance();
t.Transform(this);
}
 
protected virtual void ChangeState(Machine m, State s)
{
m.ChangeState(s);
}
 
public Machine Machine
{
get
{
return this.machine;
}
set
{
this.machine = value;
}
}
public int MinLevel
{
get
{
return this.minLevel;
}
set
{
this.minLevel = value;
}
}
 
public int MaxLevel
{
get
{
return this.maxLevel;
}
set
{
this.maxLevel = value;
}
}
 
public int CurrentLevel
{
get
{
return this.currentLevel;
}
set
{
this.currentLevel = value;
// Is the machine value set?
if(this.Machine != null)
{
this.CheckEfficiency();
}
}
}
 
public int Deviation
{
get
{
return this.deviation;
}
set
{
this.deviation = value;
}
}
 
public int MaxDeviaton
{
get
{
return this.MaxLevel - this.Deviation;
}
}
 
public int MinDeviaton
{
get
{
return this.MinLevel + this.Deviation;
}
}
 
public Color MessageColor
{
get
{
return this.messageColor;
}
set
{
this.messageColor = value;
}
}
 
public string MessageText
{
get
{
return this.messageText;
}
set
{
this.messageText = value;
}
}
}
}
</pre>
1
edit

Navigation menu