Пример #1
0
 /// <summary>
 /// Gets the correpondent face position.
 /// </summary>
 /// <param name="color">The face</param>
 /// <returns>Returns the face position.</returns>
 /// <exception cref="IndexOutOfRangeException"></exception>
 public CubeFaceType this[CubeFace face]
 {
     get
     {
         foreach (KeyValuePair<CubeFace, CubeFaceType> entry in CubeMap)
         {
             if (entry.Key.Equals(face))
                 return entry.Value;
         }
         throw new IndexOutOfRangeException();
     }
 }
        // Este método foi apenas criado para usarmos para a interface traduzir um string para uma estrutura de cubo
        // Não será necessário depois, na implementação final
        public Cube TranslateInputStringToCube(String input)
        {
            Dictionary<CubeFace, CubeFaceType> faces = new Dictionary<RubikCube.CubeFace,RubikCube.CubeFaceType>();

            for (int pos = 0; pos < input.Length; pos++)
            {
                // pega a posicao da face
                CubeFaceType positionFace = (CubeFaceType) Enum.Parse(typeof(CubeFaceType), input[pos++].ToString());
                pos++;

                Dictionary<CubeFaceletType, CubeFaceColor> facelets = new Dictionary<CubeFaceletType, CubeFaceColor>();
                facelets.Add(CubeFaceletType.UpLeft, (CubeFaceColor) Enum.Parse(typeof(CubeFaceColor), input[pos++].ToString()));
                facelets.Add(CubeFaceletType.UpMid, (CubeFaceColor)Enum.Parse(typeof(CubeFaceColor), input[pos++].ToString()));
                facelets.Add(CubeFaceletType.UpRight, (CubeFaceColor)Enum.Parse(typeof(CubeFaceColor), input[pos++].ToString()));
                facelets.Add(CubeFaceletType.MidLeft, (CubeFaceColor)Enum.Parse(typeof(CubeFaceColor), input[pos++].ToString()));
                facelets.Add(CubeFaceletType.Center, (CubeFaceColor)Enum.Parse(typeof(CubeFaceColor), input[pos++].ToString()));
                facelets.Add(CubeFaceletType.MidRight, (CubeFaceColor)Enum.Parse(typeof(CubeFaceColor), input[pos++].ToString()));
                facelets.Add(CubeFaceletType.DownLeft, (CubeFaceColor)Enum.Parse(typeof(CubeFaceColor), input[pos++].ToString()));
                facelets.Add(CubeFaceletType.DownMid, (CubeFaceColor)Enum.Parse(typeof(CubeFaceColor), input[pos++].ToString()));
                facelets.Add(CubeFaceletType.DownRight, (CubeFaceColor)Enum.Parse(typeof(CubeFaceColor), input[pos++].ToString()));

                CubeFace face = new CubeFace(facelets);
                faces.Add(face, positionFace);
            }

            return new Cube(faces);
        }