24 game/CSharp: Difference between revisions
m
Fixed syntax highlighting.
m (→{{header|C_sharp|C#}}: "header" template isn't necessary on this page) |
m (Fixed syntax highlighting.) |
||
Line 4:
Or, while not necessarily a good coding practice, but certainly a short and simple route, you could use System.Xml.XPath.XPathNavigator.Evaluate(string xpath) as shown here:
<
public class XPathEval : I24MathParser {
public float Evaluate(string expression) {
Line 18:
return answer;
}
}</syntaxhighlight>
The XPathEval class is implementing this interface to facilitate swapping out Evaluate providers:
<
interface I24MathParser {
float Evaluate(string expression);
}
</syntaxhighlight>
Here is a more verbose, native solution - a lightweight math expression parser for evaluating 24 Game user input:
<
/// <summary>
/// Lightweight math parser - C# does not have an Evaluate function
Line 163 ⟶ 162:
}
}
</syntaxhighlight>
This is the main class that handles puzzle generation and user interaction
<
/// <summary>
/// The Game. Handles user interaction and puzzle generation.
Line 339 ⟶ 338:
}
}
</syntaxhighlight>
|