Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #import "room.h"
  3. // Note, stdio and printstring are only here for debugging purposes.
  4. #import <stdio.h>
  5. void printstring(NSString *input);
  6.  
  7. void makeexits(NSString* list, Room* storage, BOOL hidden) {
  8.     BOOL pipe = NO; // When we hit a pipe, this turns to yes
  9.  
  10.     NSUInteger character_counter = 0;
  11.     NSUInteger current_index = 0; // Array index of current door we're working on
  12.     NSMutableString* buffer = [NSMutableString string];
  13.     if (hidden == YES) {
  14.         [storage Add_Hidden_Exit: [[door alloc] Init]];
  15.         while (pipe == NO) {
  16.             unichar* bar = malloc(1);          
  17.             *bar = [list characterAtIndex: character_counter];         
  18.                 switch (*bar) {
  19.                     case '|':
  20.                         pipe = YES;
  21.                         break;
  22.                     case '=':
  23.                         // Dump string into room's door
  24.                         [[[storage Hidden_Exits] objectAtIndex: current_index] setDirection: [NSString stringWithString: buffer]];
  25.                         // Reset buffer                    
  26.                         [buffer release]; buffer = [NSMutableString string];
  27.                         break;
  28.                     case ',':
  29.                         // Dump integer into room's door
  30.                         [[[storage Hidden_Exits] objectAtIndex: current_index] setAddress: [[NSString stringWithString: buffer] integerValue]];
  31.                         // Create new door
  32.                         [storage Add_Hidden_Exit: [[door alloc] Init]];
  33.                         // Reset buffer                    
  34.                         [buffer release]; buffer = [NSMutableString string];
  35.                         // Increment index to accomodate new door in array
  36.                         current_index = current_index + 1;
  37.                         break;
  38.                     default:
  39.                         [buffer appendString: [NSString stringWithCharacters: bar length: 1]];
  40.                         break;
  41.                 }
  42.             // Last line in function. Do not write below this
  43.             character_counter += 1;
  44.             free(bar);
  45.         }
  46.     } else {
  47.         [storage Add_Direction: [[door alloc] Init]];
  48.         while (pipe == NO) {
  49.             unichar* bar = malloc(1);
  50.             *bar = [list characterAtIndex: character_counter];
  51.                 switch (*bar) {
  52.                     case '|':
  53.                         pipe = YES;
  54.                         break;
  55.                     case '=':
  56.                         // Dump string into room's door
  57.                         [[[storage Directions] objectAtIndex: current_index] setDirection: [NSString stringWithString: buffer]];
  58.                         // Reset buffer
  59.                         [buffer release]; buffer = [NSMutableString string];
  60.                        
  61.                         break;
  62.                     case ',':
  63.                         // Dump integer into room's door
  64.                         [[[storage Directions] objectAtIndex: current_index] setAddress: [[NSString stringWithString: buffer] integerValue]];
  65.                         // Create new door
  66.                         [storage Add_Direction: [[door alloc] Init]];
  67.                         // Reset buffer
  68.                         [buffer release]; buffer = [NSMutableString string];
  69.                         // Increment index to accomodate new door in array
  70.                         current_index = current_index + 1;
  71.                         break;
  72.                     default:
  73.                         [buffer appendString: [NSString stringWithCharacters: bar length: 1]];
  74.                         break;
  75.                 }
  76.             // Last line in function. Do not write below this
  77.             character_counter += 1;
  78.             free(bar);
  79.         }
  80.     }
  81.     [buffer release];
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement