Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. #import "PBWIZasob.h"
  2. #import "PBWIZasobyWydzialu.h"
  3. #import "PBWIPokoj.h"
  4. #import "PBWIBiurko.h"
  5. #import "PBWIKrzeslo.h"
  6. @implementation PBWIZasobyWydzialu
  7.  
  8. -(id) init {
  9. self = [super init];
  10. if (self) {
  11. _mutableDictionary=[[NSMutableDictionary alloc] init];
  12. _zasoby=[[NSMutableArray alloc] init];
  13. _nrPokoju=0;
  14. }
  15. return self;
  16. }
  17.  
  18.  
  19.  
  20. -(int) dodajPokoj: (PBWIPokoj *) pokoj iParametr2:(int)nrPokoju1 {
  21. //int i=0;
  22. //NSNumber * nr= [NSNumber numberWithInt:nrPokoju1];
  23. [_mutableDictionary setObject: pokoj forKey:[@(nrPokoju1) stringValue]];
  24. nrPokoju1++;
  25. NSLog(@"Dodano pokoj");
  26. return nrPokoju1;
  27. //i++;
  28. }
  29. -(void) dodajZasob: (PBWIZasob *) zasob iParametr2:(int) nr_Pokoju1 {
  30. if([_mutableDictionary objectForKey:[@(nr_Pokoju1) stringValue]]){
  31. PBWIPokoj *pokoj=[_mutableDictionary objectForKey:[@(nr_Pokoju1) stringValue]] ;
  32. [pokoj dodajZasob:zasob];
  33. [_zasoby addObject:zasob];
  34. NSLog(@"Dodano zasob do pokoju");
  35. }
  36. else{
  37. NSLog(@"Nie ma takiego pokoju");
  38. }
  39.  
  40.  
  41. }
  42.  
  43. -(void) przeniesZasob: (PBWIZasob *) zasob iParametr2:(int) nr_Pokoju {
  44. if([_mutableDictionary objectForKey:[@(nr_Pokoju) stringValue]])
  45. {
  46. if([_zasoby containsObject:zasob])
  47. {
  48. for(NSString *key in _mutableDictionary)
  49. {
  50. PBWIPokoj *pokoj=[_mutableDictionary objectForKey:key];
  51. if([[pokoj wszystkieZasoby] containsObject:zasob] )
  52. {
  53. [pokoj usunZasob:zasob];
  54. PBWIPokoj *pokoj2=[_mutableDictionary objectForKey:[@(nr_Pokoju) stringValue]];
  55. [pokoj2 dodajZasob:zasob];
  56.  
  57. }
  58. }
  59. NSLog(@"Zasob przeniesiono");
  60. }
  61. else
  62. {
  63. NSLog(@"Nie ma takiego zasobu");
  64. }
  65.  
  66. }
  67. else{
  68. NSLog(@"Nie ma takiego pokoju");
  69. }
  70. //PBWIPokoj* pokoj=[_mutableDictionary objectForKey:[@(nr_Pokoju) stringValue]];
  71. //[pokoj usunZasob:zasob];
  72. //[_zasobyWszystkie removeObject:zasob];
  73. //PBWIPokoj *pokoj2=[_mutableDictionary objectForKey:@"nr_Pokoju2"];
  74. //[pokoj2 dodajZasob:zasob];
  75. //[_zasobyWszystkie addObject:zasob];
  76.  
  77. }
  78.  
  79.  
  80.  
  81. -(void) usunZasob: (PBWIZasob *) zasob iParametr2:(int) nr_Pokoju{
  82. if([_mutableDictionary objectForKey:[@(nr_Pokoju) stringValue]])
  83. {
  84. if([_zasoby containsObject:zasob])
  85. {
  86. for(NSString *key in _mutableDictionary)
  87. {
  88. PBWIPokoj *pokoj=[_mutableDictionary objectForKey:key];
  89. if([[pokoj wszystkieZasoby] containsObject:zasob] )
  90. {
  91. [pokoj usunZasob:zasob];
  92. [_zasoby removeObject:zasob];
  93.  
  94. }
  95. }
  96. NSLog(@"Zasob usunieto");
  97. }
  98. else
  99. {
  100. NSLog(@"Nie ma takiego zasobu");
  101. }
  102.  
  103. }
  104. else{
  105. NSLog(@"Nie ma takiego pokoju");
  106. }
  107. //PBWIPokoj *pokoj=[_mutableDictionary objectForKey:@"nr_Pokoju"];
  108. //[pokoj usunZasob:zasob];
  109. //[_zasobyWszystkie removeObject:zasob];
  110. }
  111. -(NSArray *) wszystkieZasoby {
  112. return [_zasoby copy];
  113. }
  114. -(void) zwrocZasoby{
  115. NSLog(@"%@",_zasoby);
  116. }
  117.  
  118.  
  119. -(NSMutableArray*) zwrocNrPokoi{
  120. NSMutableArray* result= [NSMutableArray array];
  121. for(NSString* key in _mutableDictionary ){
  122. [result addObject:key];
  123. }
  124.  
  125. return [NSArray arrayWithArray:result];
  126. }
  127.  
  128. -(NSArray*)zwrocBiurka {
  129. NSMutableArray *biurka = [[NSMutableArray alloc] init];
  130. for (NSString *key in _mutableDictionary) {
  131. PBWIPokoj *pokoj = [_mutableDictionary objectForKey:key];
  132. for (PBWIZasob *zasob in [pokoj wszystkieZasoby]) {
  133. if ([zasob class] == [PBWIBiurko class]) {
  134. [biurka addObject:zasob];
  135. }
  136. }
  137. }
  138. return [NSArray arrayWithArray:biurka];
  139. }
  140. -(void)zwrocKrzesla {
  141. NSMutableArray *krzesla = [[NSMutableArray alloc] init];
  142. for (NSString *key in _mutableDictionary) {
  143. PBWIPokoj *pokoj = [_mutableDictionary objectForKey:key];
  144. for (PBWIZasob *zasob in [pokoj wszystkieZasoby]) {
  145. if ([zasob class] == [PBWIKrzeslo class]) {
  146. [krzesla addObject:zasob];
  147. }
  148. }
  149.  
  150. NSLog(@"%@", [NSArray arrayWithArray:krzesla]);
  151. }}
  152.  
  153. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement