コード例 #1
0
        /// <summary>
        /// Constructor used for creating a new cube that looks the same as the given cube
        /// </summary>
        /// <param name="cube">The cube base the new cube off</param>
        public Cube(Cube cube)
        {
            int piecesInASide = Size * Size;

            top    = new Piece[piecesInASide];
            bottom = new Piece[piecesInASide];
            front  = new Piece[piecesInASide];
            back   = new Piece[piecesInASide];
            right  = new Piece[piecesInASide];
            left   = new Piece[piecesInASide];

            centres = new Centre[6];
            edges   = new Edge[12];
            corners = new Corner[8];

            // Get the pieces of the other cube
            Centre[] otherCentres = cube.GetCentres();
            Edge[]   otherEdges   = cube.GetEdges();
            Corner[] otherCorners = cube.GetCorners();

            // Create each piece with the same colour as the pieces of the sample cube
            // and set the position to be the same as the sample cube
            for (int i = 0; i < centres.Length; i++)
            {
                centres[i] = new Centre(otherCentres[i].colour);
                centres[i].SetPosition(otherCentres[i].Position());
            }

            for (int i = 0; i < edges.Length; i++)
            {
                edges[i] = new Edge(otherEdges[i].GetColours());
                edges[i].SetPosition(otherEdges[i].GetPosition());
            }

            for (int i = 0; i < corners.Length; i++)
            {
                corners[i] = new Corner(otherCorners[i].GetColours());
                corners[i].SetPosition(otherCorners[i].GetPosition());
            }

            UpdateSides();
        }
コード例 #2
0
        /// <summary>
        /// Get the string representing the requested side of the cube. Used for creating
        /// a printable cube
        /// </summary>
        /// <param name="Side">The side to get the string of</param>
        /// <returns>String representing the side</returns>
        private string GetSideString(Piece[] Side)
        {
            // String to represent the sides colours.
            string[] pieces = new string[9];

            Positions position;
            Positions first, second, third, fourth;

            // Get the sides around the selected face
            if (Side.Equals(top))
            {
                position = Positions.top;
                first    = Positions.back;
                second   = Positions.left;
                third    = Positions.right;
                fourth   = Positions.front;
            }
            else if (Side.Equals(bottom))
            {
                position = Positions.bottom;
                first    = Positions.front;
                second   = Positions.left;
                third    = Positions.right;
                fourth   = Positions.back;
            }
            else if (Side.Equals(right))
            {
                position = Positions.right;
                first    = Positions.top;
                second   = Positions.front;
                third    = Positions.back;
                fourth   = Positions.bottom;
            }
            else if (Side.Equals(left))
            {
                position = Positions.left;
                first    = Positions.top;
                second   = Positions.back;
                third    = Positions.front;
                fourth   = Positions.bottom;
            }
            else if (Side.Equals(front))
            {
                position = Positions.front;
                first    = Positions.top;
                second   = Positions.left;
                third    = Positions.right;
                fourth   = Positions.bottom;
            }
            else
            {
                position = Positions.back;
                first    = Positions.bottom;
                second   = Positions.left;
                third    = Positions.right;
                fourth   = Positions.top;
            }

            // Look through all the pieces within the side, find where they are in the cube,
            // then get their string code for that side and place it within the string array
            // depending where in the side they are located
            foreach (Piece piece in Side)
            {
                if (piece.GetPieceType().Equals(PieceTypes.centre))
                {
                    Centre centre = piece as Centre;

                    pieces[4] = centre.GetColourString();
                }
                else if (piece.GetPieceType().Equals(PieceTypes.corner))
                {
                    Corner corner = piece as Corner;

                    if (corner.InSide(first) && corner.InSide(second))
                    {
                        pieces[0] = corner.GetColourString(position);
                    }
                    else if (corner.InSide(first) && corner.InSide(third))
                    {
                        pieces[2] = corner.GetColourString(position);
                    }
                    else if (corner.InSide(fourth) && corner.InSide(second))
                    {
                        pieces[6] = corner.GetColourString(position);
                    }
                    else
                    {
                        pieces[8] = corner.GetColourString(position);
                    }
                }
                else if (piece.GetPieceType().Equals(PieceTypes.edge))
                {
                    Edge edge = piece as Edge;

                    if (edge.InSide(first))
                    {
                        pieces[1] = edge.GetColourString(position);
                    }
                    else if (edge.InSide(second))
                    {
                        pieces[3] = edge.GetColourString(position);
                    }
                    else if (edge.InSide(third))
                    {
                        pieces[5] = edge.GetColourString(position);
                    }
                    else
                    {
                        pieces[7] = edge.GetColourString(position);
                    }
                }
            }

            // Transform string array to string then return
            string sideString = "";

            foreach (string colour in pieces)
            {
                sideString += colour;
            }

            return(sideString);
        }
コード例 #3
0
        /// <summary>
        /// Standard constructor, used for created on Rubik's cube that is already solved
        /// </summary>
        public Cube()
        {
            int piecesInASide = Size * Size;

            top    = new Piece[piecesInASide];
            bottom = new Piece[piecesInASide];
            front  = new Piece[piecesInASide];
            back   = new Piece[piecesInASide];
            right  = new Piece[piecesInASide];
            left   = new Piece[piecesInASide];

            centres = new Centre[6];

            // Create all the centre pieces then add them as the first item in each side
            centres[0] = new Centre(Colours.blue);
            bottom[0]  = centres[0];
            centres[1] = new Centre(Colours.green);
            top[0]     = centres[1];
            centres[2] = new Centre(Colours.orange);
            left[0]    = centres[2];
            centres[3] = new Centre(Colours.red);
            right[0]   = centres[3];
            centres[4] = new Centre(Colours.white);
            back[0]    = centres[4];
            centres[5] = new Centre(Colours.yellow);
            front[0]   = centres[5];

            edges = new Edge[12];

            // Create all the edge pieces that the cube could contain
            edges[0] = new Edge(new Colours[2] {
                Colours.green, Colours.yellow
            });
            edges[1] = new Edge(new Colours[2] {
                Colours.green, Colours.white
            });
            edges[2] = new Edge(new Colours[2] {
                Colours.green, Colours.red
            });
            edges[3] = new Edge(new Colours[2] {
                Colours.green, Colours.orange
            });
            edges[4] = new Edge(new Colours[2] {
                Colours.blue, Colours.yellow
            });
            edges[5] = new Edge(new Colours[2] {
                Colours.blue, Colours.white
            });
            edges[6] = new Edge(new Colours[2] {
                Colours.blue, Colours.red
            });
            edges[7] = new Edge(new Colours[2] {
                Colours.blue, Colours.orange
            });
            edges[8] = new Edge(new Colours[2] {
                Colours.yellow, Colours.red
            });
            edges[9] = new Edge(new Colours[2] {
                Colours.yellow, Colours.orange
            });
            edges[10] = new Edge(new Colours[2] {
                Colours.white, Colours.red
            });
            edges[11] = new Edge(new Colours[2] {
                Colours.white, Colours.orange
            });

            corners = new Corner[8];

            // Create all the corner pieces that the cube could contain
            corners[0] = new Corner(new Colours[3] {
                Colours.green, Colours.yellow, Colours.orange
            });
            corners[1] = new Corner(new Colours[3] {
                Colours.green, Colours.yellow, Colours.red
            });
            corners[2] = new Corner(new Colours[3] {
                Colours.green, Colours.white, Colours.orange
            });
            corners[3] = new Corner(new Colours[3] {
                Colours.green, Colours.white, Colours.red
            });
            corners[4] = new Corner(new Colours[3] {
                Colours.blue, Colours.yellow, Colours.orange
            });
            corners[5] = new Corner(new Colours[3] {
                Colours.blue, Colours.yellow, Colours.red
            });
            corners[6] = new Corner(new Colours[3] {
                Colours.blue, Colours.white, Colours.orange
            });
            corners[7] = new Corner(new Colours[3] {
                Colours.blue, Colours.white, Colours.red
            });

            UpdateSides();
        }
コード例 #4
0
        /// <summary>
        /// Constructor to create a cube with pieces in given positions
        /// </summary>
        /// <param name="positions">The positions to set the cube to</param>
        public Cube(Positions[] positions)
        {
            // Create cube like normal constructor
            int piecesInASide = Size * Size;

            top    = new Piece[piecesInASide];
            bottom = new Piece[piecesInASide];
            front  = new Piece[piecesInASide];
            back   = new Piece[piecesInASide];
            right  = new Piece[piecesInASide];
            left   = new Piece[piecesInASide];

            centres = new Centre[6];

            centres[0] = new Centre(Colours.blue);
            bottom[0]  = centres[0];
            centres[1] = new Centre(Colours.green);
            top[0]     = centres[1];
            centres[2] = new Centre(Colours.orange);
            left[0]    = centres[2];
            centres[3] = new Centre(Colours.red);
            right[0]   = centres[3];
            centres[4] = new Centre(Colours.white);
            back[0]    = centres[4];
            centres[5] = new Centre(Colours.yellow);
            front[0]   = centres[5];

            edges = new Edge[12];

            edges[0] = new Edge(new Colours[2] {
                Colours.green, Colours.yellow
            });
            edges[1] = new Edge(new Colours[2] {
                Colours.green, Colours.white
            });
            edges[2] = new Edge(new Colours[2] {
                Colours.green, Colours.red
            });
            edges[3] = new Edge(new Colours[2] {
                Colours.green, Colours.orange
            });
            edges[4] = new Edge(new Colours[2] {
                Colours.blue, Colours.yellow
            });
            edges[5] = new Edge(new Colours[2] {
                Colours.blue, Colours.white
            });
            edges[6] = new Edge(new Colours[2] {
                Colours.blue, Colours.red
            });
            edges[7] = new Edge(new Colours[2] {
                Colours.blue, Colours.orange
            });
            edges[8] = new Edge(new Colours[2] {
                Colours.yellow, Colours.red
            });
            edges[9] = new Edge(new Colours[2] {
                Colours.yellow, Colours.orange
            });
            edges[10] = new Edge(new Colours[2] {
                Colours.white, Colours.red
            });
            edges[11] = new Edge(new Colours[2] {
                Colours.white, Colours.orange
            });

            corners = new Corner[8];

            corners[0] = new Corner(new Colours[3] {
                Colours.green, Colours.yellow, Colours.orange
            });
            corners[1] = new Corner(new Colours[3] {
                Colours.green, Colours.yellow, Colours.red
            });
            corners[2] = new Corner(new Colours[3] {
                Colours.green, Colours.white, Colours.orange
            });
            corners[3] = new Corner(new Colours[3] {
                Colours.green, Colours.white, Colours.red
            });
            corners[4] = new Corner(new Colours[3] {
                Colours.blue, Colours.yellow, Colours.orange
            });
            corners[5] = new Corner(new Colours[3] {
                Colours.blue, Colours.yellow, Colours.red
            });
            corners[6] = new Corner(new Colours[3] {
                Colours.blue, Colours.white, Colours.orange
            });
            corners[7] = new Corner(new Colours[3] {
                Colours.blue, Colours.white, Colours.red
            });

            // Instead of updating sides, set the positions of the cubes to match the given positions
            SetPositions(positions);
        }