Advertisement
Guest User

Untitled

a guest
May 4th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.02 KB | None | 0 0
  1. -(void) randomCharBotton: (NSInteger) totalButton{
  2.    
  3.     NSInteger posRandom;
  4.     int pos = 0;
  5.     long lengthWord = self.stPalabraAAdivinar.length;
  6.     UIButton *boton;
  7.     char *tituloBoton;
  8.     NSString *caracter;
  9.     char *caracter2;
  10.    
  11.    
  12.     while(pos < lengthWord){
  13.      
  14.         posRandom = [self getRandomNumberBetween:0 to:(int)totalButton-1];
  15.    
  16.         boton = [self.arregloBotones objectAtIndex:posRandom];
  17.      
  18.         tituloBoton = (char*) [boton.titleLabel.text UTF8String];
  19.        
  20.  
  21.         if((*tituloBoton >= '0' ) && (*tituloBoton <= '9')){
  22.            
  23.             caracter = [self.stPalabraAAdivinar substringWithRange:NSMakeRange(pos,1)] ;
  24.             NSLog(@"%@",caracter);
  25.             NSLog(@"%i",pos);
  26.             [boton setTitle: caracter  forState:UIControlStateNormal];
  27.             pos++;
  28.         }
  29.         else{
  30.      
  31.             while(*tituloBoton <= '0'  && *tituloBoton >= '9'){
  32.                 posRandom = [self getRandomNumberBetween:0 to:(int)totalButton-1];
  33.                 boton = [self.arregloBotones objectAtIndex:posRandom];
  34.                 tituloBoton = (char*)[boton.titleLabel.text UTF8String];
  35.             }
  36.             if((*tituloBoton >= '0' ) && (*tituloBoton <= '9')){
  37.                
  38.                 caracter = [self.stPalabraAAdivinar substringWithRange:NSMakeRange(pos,1)] ;
  39.                 NSLog(@"%@",caracter);
  40.                 NSLog(@"%i",pos);
  41.                 [boton setTitle: caracter  forState:UIControlStateNormal];
  42.                 pos++;
  43.             }
  44.         }
  45.        
  46.    
  47.     }
  48.    
  49.     for(int j = 0; j < totalButton; j++){
  50.        
  51.         boton = [self.arregloBotones objectAtIndex:j];
  52.         tituloBoton =(char*)[boton.titleLabel.text UTF8String];
  53.        
  54.         if((*tituloBoton >= '0' ) && (*tituloBoton <= '9')){
  55.             caracter2 = [self generateRandomChar];
  56.             [[self.arregloBotones objectAtIndex:j] setTitle: [NSString stringWithFormat:@"%c",*caracter2]  forState:UIControlStateNormal];
  57.         }
  58.     }
  59.    
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement