开发者

swipe directions and loop text string

Help me... I'm stuck. I'm trying to make simple game something like angry bird swipe. I don't know how to code this. I have two labels and swipe move code (up, down,left or 开发者_JS百科right, any directions).

I want to transfer label1.text ("333333777777555555888888") on label2.text with shorter number ("3758"). So I can make Artificial Intelligence game better. How do I do this?

Here's the code.

      for (NSValue *point_value in TouchRecord) {
             CGPoint current_point = [point_value CGPointValue];
             NSUInteger idx = [self subregionIndexContainingPoint:current_point];

             //collect string on label2
             NSString *numValue = [[NSString alloc] initWithFormat:@"%d", idx];
             label1.text = [label1.text  stringByAppendingString:numValue];


       }

Thanks.


I'm not entirely sure this is what you want but I think it is.

To shorten the string so that there are only one of each number use this function.

+(NSString*) removeDuplicateNumbersFromString:(NSString*)first{
    //if first is "1112222334445" the return value of this function would be "12345"

    NSString *end = [NSString stringWithString:@""]; //the return string
    char last; //will track changes in numbers

    for (int i = 0; i < [first length]; i++) {
        char charAtIndex = [first characterAtIndex:i]; 
        if (last != charAtIndex) {
            //if the last character is different than the current character
            //set the current character as last, and add that character to the return string
            last = charAtIndex;
            end = [end stringByAppendingFormat:@"%c",last];
        }
     }
     NSLog(@"First:%@, End:%@",first,end); //prints out the start/end strings
     return end;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜