滑动方向并循环文本字符串

发布于 2024-12-02 23:04:53 字数 659 浏览 0 评论 0原文

帮助我...我被困住了。我正在尝试制作简单的游戏,例如愤怒的小鸟滑动。我不知道如何编写这个代码。我有两个标签和滑动移动代码(向上、向下、向左或向右,任何方向)。

我想将 label1.text ("3333337777775555558888888") 传输到带有较短数字 ("3758") 的 label2.text 上。所以我可以让人工智能游戏变得更好。 我该怎么做?

这是代码。

      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];


       }

谢谢。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-12-09 23:04:53

我不完全确定这就是你想要的,但我认为它是。

要缩短字符串以使每个数字只有一个,请使用此函数。

+(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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文