我正在学习waaaayyy的课程,比我通常在这个学期做的要多,而且没有时间玩弄客观的c,让它成为我自己的,这一切依然让人感觉非常对我来说是陌生的,我遇到很多麻烦,我知道我应该很简单。如何交换NSMutableArray中的值(不是索引)
但基本上我所拥有的是一块6块拼图拼图,当拼图重新启动时,棋子会返回到同一个地方。每次拼图重新开始时,我都试图用随机的方式将每件作品的原点与另一块作品的原点互换。所以我想以随机的数组分配给NSValue对象的CGRect值,宣布为:
@synthesize topLeft;
@synthesize topMiddle;
@synthesize topRight;
@synthesize bottomLeft;
@synthesize bottomMiddle;
@synthesize bottomRight;
@synthesize scoreLabel;
topLeftRectOrigin=[NSValue valueWithCGRect: topLeft.frame];
topMiddleRectOrigin=[NSValue valueWithCGRect: topMiddle.frame];
topRightRectOrigin=[NSValue valueWithCGRect: topRight.frame];
bottomLeftRectOrigin=[NSValue valueWithCGRect: bottomLeft.frame];
bottomMiddleRectOrigin=[NSValue valueWithCGRect: bottomMiddle.frame];
bottomRightRectOrigin=[NSValue valueWithCGRect: bottomRight.frame];
puzzlePieces=[[NSMutableArray alloc]initWithObjects:topLeft, topMiddle, topRight, bottomLeft, bottomMiddle, bottomRight, nil];
puzzleOrigins=[[NSMutableArray alloc]initWithObjects:topLeftRectOrigin, topMiddleRectOrigin, topRightRectOrigin, bottomLeftRectOrigin, bottomMiddleRectOrigin, bottomRightRectOrigin, nil];
topLeftRectGrid=CGRectMake(145, 95, 30, 30);
topMiddleRectGrid=CGRectMake(235, 95, 30, 30);
topRightRectGrid=CGRectMake(325, 95, 30, 30);
bottomLeftRectGrid=CGRectMake(145, 185, 30, 30);
bottomMiddleRectGrid=CGRectMake(235, 185, 30, 30);
bottomRightRectGrid=CGRectMake(325, 185, 30, 30);
我真的遇到了麻烦我解决这个脑子,你们可以建议我应该怎么去这样做?非常感谢您的帮助。
感谢所有帮助人员,每个人都贡献了一点点,向我展示了解决此问题的最佳方法。事实证明,很多问题都是教授让我们跟随的教程中糟糕的算法,这使得很难在没有重写的情况下改变任何东西。但是之后重写一切都会奏效:-D我基本上只需要改变对数组的所有引用,而不是数组中的对象,这将不允许数组混排。 – jamzsabb 2012-02-29 03:30:16