水果机

懒得描述了,直接上链接。

https://www.codewars.com/kata/fruit-machine/csharp

MyCode:

public static int FruitMachine(List<string[]> reels, int[] spins)
        {
            int score = 0;
            int[] scoresArr = { 100, 90, 80, 70, 60, 50, 40, 30, 20, 10 };
            Dictionary<string, int> reeldic = new Dictionary<string, int> { 
                 {"Wild",0},
                 {"Star",1},
                 {"Bell",2},
                 {"Shell",3},
                 {"Seven",4},
                 {"Cherry",5},
                 {"Bar",6},
                 {"King",7},
                 {"Queen",8},
                 {"Jack",9},
            };

            string reel1 = reels[0][spins[0]];
            string reel2 = reels[1][spins[1]];
            string reel3 = reels[2][spins[2]];

            if (reel1 != reel2 && reel2 != reel3 & reel1 != reel3)
            {
                return score;
            }
            else if (reel1 == reel2 && reel2 == reel3)
            {
                score = scoresArr[reeldic[reel1]];
                return score;
            }
            else
            {
                string samereel = reel1 == reel2 ? reel1 : reel3;
                score = scoresArr[reeldic[samereel]] / 10;
                if (samereel != "Wild" && (reel1 == "Wild" || reel2 == "Wild" || reel3 == "Wild"))
                {
                    score = score * 2;
                }
                return score;
            }
        }

你可能感兴趣的:(CodeWar,-,C#,黄色六阶)