我有零件的枚舉列表中的特定位置的內容:試圖告訴枚舉字符是在一個字符串
public enum Parts
{
Wall = (int)'#',
Empty = (int)'-',
Player = (int)'@',
Goal = (int)'.',
Block = (int)'$',
BlockOnGoal = (int)'*',
PlayerOnGoal = (int)'+'
};
而且我有一個字符串
string Level = "####\n# #\n#@ #\n####";
所以所有的項目中字符串是在枚舉列表 如果我再調用函數
public Parts WhatsAt(int row, int column)
{
return Parts.Wall;// Teachers comment but idk what he means "WRONG - but now no exception! should look up Level or some better data structure"
}
所以當調用該函數將將字符串拆分爲\ n,然後將輸入用作地圖上的座標來精確定位其中的特定字符。
左上方行:0,列:0
右下側排:4,列:4
####
# #
#@ #
####
我如何再使函數返回什麼部件名稱是在指定給座標。
例如
Parts actual = WhatsAt(0, 2);
實際然後會成爲華爾街的那是什麼#中的枚舉意味着
感謝所有幫助提前
那麼,一旦你有一個字符(採用分體式,[]和子),你*會*投你的性格爲int,並然後將其轉換爲您的枚舉類型,但這將是一個黑客(因爲您假設枚舉值等於字符值)。一個更好的數據結構將是一個'Dictionary'將字符映射到零件。 –