Bitwise logic should work with flag enums like this.
if((Flow & (GameFlow.Normal | GameFlow.NormalNoMove)) > 0)
You can also create enum values โโthat combine other values, as I mention here .
So in your case:
[Flags] public enum GameFlow { Normal = 1, NormalNoMove = 2, Paused = 4, Battle = 8, AnyNormal = Normal | NormalNoMove } bool IsNormal(GameFlow flow) { return (flow & GameFlow.AnyNormal) > 0; }
And the LINQPad test:
void Main() { IsNormal(GameFlow.Normal).Dump();// True IsNormal(GameFlow.NormalNoMove).Dump();// True IsNormal(GameFlow.Paused).Dump();// False IsNormal(GameFlow.Battle).Dump();// False IsNormal(GameFlow.Normal | GameFlow.Paused).Dump();// True IsNormal(GameFlow.NormalNoMove | GameFlow.Battle).Dump();// True IsNormal(GameFlow.Paused | GameFlow.Battle).Dump();// False IsNormal(GameFlow.Battle | GameFlow.Normal).Dump();// True }
Based on your comment, I wonder if bit-wise flags need to be reviewed here. It appears that โNormalโ is the state you want to check, and โNormalNoMoveโ is based on that. Perhaps your listing should look like this:
[Flags] public enum GameFlow { Normal = 1, NormalNoMove = Normal | 2, Paused = 4, Battle = 8 }
This way you can check if flow & GameFlow.Normal > 0 is there if you are in a normal state: NormalNoMove just "extends" Normal , so to speak.
source share