public Cube() { this.Upper = new Side(Colors.White); this.Back = new Side(Colors.Yellow); this.Right = new Side(Colors.Red); this.Left = new Side(Colors.Orange); this.Front = new Side(Colors.Green); this.Down = new Side(Colors.Blue); // Wires up the proper Side object vectors touching the face of // the 'back' Side object. AdjacentVector upperBackConnection = new AdjacentVector(this.Back, 0, true); AdjacentVector upperFrontConnection = new AdjacentVector(this.Front, 0, true); AdjacentVector upperLeftConnection = new AdjacentVector(this.Left, 0, true); AdjacentVector upperRightConnection = new AdjacentVector(this.Right, 0, true); // The initial order of this array is critical, as it represents // the actual physical cube and must be consistent across Side objects. this.Upper.AdjacentRows = new AdjacentVector[] { upperBackConnection, upperRightConnection, upperFrontConnection, upperLeftConnection }; AdjacentVector backUpperConnection = new AdjacentVector(this.Upper, 0, true); AdjacentVector backLeftConnection = new AdjacentVector(this.Left, 0, false); AdjacentVector backDownConnection = new AdjacentVector(this.Down, 2, true); AdjacentVector backRightConnection = new AdjacentVector(this.Right, 2, false); this.Back.AdjacentRows = new AdjacentVector[] { backUpperConnection, backLeftConnection, backDownConnection, backRightConnection }; AdjacentVector rightTopConnection = new AdjacentVector(this.Upper, 2, false); AdjacentVector rightBackConnection = new AdjacentVector(this.Back, 0, false); AdjacentVector rightDownConnection = new AdjacentVector(this.Down, 2, false); AdjacentVector rightFrontConnection = new AdjacentVector(this.Front, 2, false); this.Right.AdjacentRows = new AdjacentVector[] { rightTopConnection, rightBackConnection, rightDownConnection, rightFrontConnection }; AdjacentVector downFrontConnection = new AdjacentVector(this.Front, 2, true); AdjacentVector downRightConnection = new AdjacentVector(this.Right, 2, true); AdjacentVector downBackConnection = new AdjacentVector(this.Back, 2, true); AdjacentVector downLeftConnection = new AdjacentVector(this.Left, 2, true); this.Down.AdjacentRows = new AdjacentVector[] { downFrontConnection, downRightConnection, downBackConnection, downLeftConnection }; AdjacentVector frontUpperConnection = new AdjacentVector(this.Upper, 2, true); AdjacentVector frontRightConnection = new AdjacentVector(this.Right, 0, false); AdjacentVector frontDownConnection = new AdjacentVector(this.Down, 0, true); AdjacentVector frontLeftConnection = new AdjacentVector(this.Left, 2, false); Front.AdjacentRows = new AdjacentVector[] { frontUpperConnection, frontRightConnection, frontDownConnection, frontLeftConnection }; AdjacentVector leftUpperConnection = new AdjacentVector(this.Upper, 0, false); AdjacentVector leftFrontConnection = new AdjacentVector(this.Front, 0, false); AdjacentVector leftDownConnection = new AdjacentVector(this.Down, 0, false); AdjacentVector leftBackConnection = new AdjacentVector(this.Back, 2, false); this.Left.AdjacentRows = new AdjacentVector[] { leftUpperConnection, leftFrontConnection, leftDownConnection, leftBackConnection }; }
// Updates the adjacent rows in the Side objects "touching" the // Side object that was rotated. public void RotateAdjacentVectors() { int length = this.AdjacentRows.Length; Colors[] temp = new Colors[3]; Array.Copy(this.AdjacentRows[length - 1].GetAdjacentVector(), temp, 3); for (int i = length - 1; i > 0; i--) { AdjacentVector current = this.AdjacentRows[i]; AdjacentVector previous = this.AdjacentRows[i - 1]; current.SetVector(previous.GetAdjacentVector()); } this.AdjacentRows[0].SetVector(temp); }