79 lines
1.3 KiB
C#
79 lines
1.3 KiB
C#
using System;
|
|
namespace PingPong.GameEngine
|
|
{
|
|
|
|
public class GameCondition
|
|
{
|
|
#region Members
|
|
|
|
/// <summary>
|
|
/// The expression.
|
|
/// </summary>
|
|
private Lazy<string> expression;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Gets the expression.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The expression.
|
|
/// </value>
|
|
public string Expression
|
|
{
|
|
get
|
|
{
|
|
return this.expression.Value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PingPong.GameEngine.GameCondition"/> class.
|
|
/// </summary>
|
|
public GameCondition()
|
|
{
|
|
this.expression = new Lazy<string>(() => string.Empty);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Evaluate this instance.
|
|
/// </summary>
|
|
public bool Evaluate()
|
|
{
|
|
Engine.ExpressionParser.Interpret(this.Expression);
|
|
return Engine.ExpressionParser.Output.Equals(
|
|
bool.TrueString,
|
|
StringComparison.OrdinalIgnoreCase
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the expression.
|
|
/// </summary>
|
|
/// <returns>
|
|
/// The expression.
|
|
/// </returns>
|
|
/// <param name='expression'>
|
|
/// Expression.
|
|
/// </param>
|
|
public GameCondition SetExpression(string expression)
|
|
{
|
|
this.expression = new Lazy<string>(() => expression);
|
|
return this;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|