Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "PBWIZasob.h"
- #import "PBWIZasobyWydzialu.h"
- #import "PBWIPokoj.h"
- #import "PBWIBiurko.h"
- #import "PBWIKrzeslo.h"
- @implementation PBWIZasobyWydzialu
- -(id) init {
- self = [super init];
- if (self) {
- _mutableDictionary=[[NSMutableDictionary alloc] init];
- _zasoby=[[NSMutableArray alloc] init];
- _nrPokoju=0;
- }
- return self;
- }
- -(int) dodajPokoj: (PBWIPokoj *) pokoj iParametr2:(int)nrPokoju1 {
- //int i=0;
- //NSNumber * nr= [NSNumber numberWithInt:nrPokoju1];
- [_mutableDictionary setObject: pokoj forKey:[@(nrPokoju1) stringValue]];
- nrPokoju1++;
- NSLog(@"Dodano pokoj");
- return nrPokoju1;
- //i++;
- }
- -(void) dodajZasob: (PBWIZasob *) zasob iParametr2:(int) nr_Pokoju1 {
- if([_mutableDictionary objectForKey:[@(nr_Pokoju1) stringValue]]){
- PBWIPokoj *pokoj=[_mutableDictionary objectForKey:[@(nr_Pokoju1) stringValue]] ;
- [pokoj dodajZasob:zasob];
- [_zasoby addObject:zasob];
- NSLog(@"Dodano zasob do pokoju");
- }
- else{
- NSLog(@"Nie ma takiego pokoju");
- }
- }
- -(void) przeniesZasob: (PBWIZasob *) zasob iParametr2:(int) nr_Pokoju {
- if([_mutableDictionary objectForKey:[@(nr_Pokoju) stringValue]])
- {
- if([_zasoby containsObject:zasob])
- {
- for(NSString *key in _mutableDictionary)
- {
- PBWIPokoj *pokoj=[_mutableDictionary objectForKey:key];
- if([[pokoj wszystkieZasoby] containsObject:zasob] )
- {
- [pokoj usunZasob:zasob];
- PBWIPokoj *pokoj2=[_mutableDictionary objectForKey:[@(nr_Pokoju) stringValue]];
- [pokoj2 dodajZasob:zasob];
- }
- }
- NSLog(@"Zasob przeniesiono");
- }
- else
- {
- NSLog(@"Nie ma takiego zasobu");
- }
- }
- else{
- NSLog(@"Nie ma takiego pokoju");
- }
- //PBWIPokoj* pokoj=[_mutableDictionary objectForKey:[@(nr_Pokoju) stringValue]];
- //[pokoj usunZasob:zasob];
- //[_zasobyWszystkie removeObject:zasob];
- //PBWIPokoj *pokoj2=[_mutableDictionary objectForKey:@"nr_Pokoju2"];
- //[pokoj2 dodajZasob:zasob];
- //[_zasobyWszystkie addObject:zasob];
- }
- -(void) usunZasob: (PBWIZasob *) zasob iParametr2:(int) nr_Pokoju{
- if([_mutableDictionary objectForKey:[@(nr_Pokoju) stringValue]])
- {
- if([_zasoby containsObject:zasob])
- {
- for(NSString *key in _mutableDictionary)
- {
- PBWIPokoj *pokoj=[_mutableDictionary objectForKey:key];
- if([[pokoj wszystkieZasoby] containsObject:zasob] )
- {
- [pokoj usunZasob:zasob];
- [_zasoby removeObject:zasob];
- }
- }
- NSLog(@"Zasob usunieto");
- }
- else
- {
- NSLog(@"Nie ma takiego zasobu");
- }
- }
- else{
- NSLog(@"Nie ma takiego pokoju");
- }
- //PBWIPokoj *pokoj=[_mutableDictionary objectForKey:@"nr_Pokoju"];
- //[pokoj usunZasob:zasob];
- //[_zasobyWszystkie removeObject:zasob];
- }
- -(NSArray *) wszystkieZasoby {
- return [_zasoby copy];
- }
- -(void) zwrocZasoby{
- NSLog(@"%@",_zasoby);
- }
- -(NSMutableArray*) zwrocNrPokoi{
- NSMutableArray* result= [NSMutableArray array];
- for(NSString* key in _mutableDictionary ){
- [result addObject:key];
- }
- return [NSArray arrayWithArray:result];
- }
- -(NSArray*)zwrocBiurka {
- NSMutableArray *biurka = [[NSMutableArray alloc] init];
- for (NSString *key in _mutableDictionary) {
- PBWIPokoj *pokoj = [_mutableDictionary objectForKey:key];
- for (PBWIZasob *zasob in [pokoj wszystkieZasoby]) {
- if ([zasob class] == [PBWIBiurko class]) {
- [biurka addObject:zasob];
- }
- }
- }
- return [NSArray arrayWithArray:biurka];
- }
- -(void)zwrocKrzesla {
- NSMutableArray *krzesla = [[NSMutableArray alloc] init];
- for (NSString *key in _mutableDictionary) {
- PBWIPokoj *pokoj = [_mutableDictionary objectForKey:key];
- for (PBWIZasob *zasob in [pokoj wszystkieZasoby]) {
- if ([zasob class] == [PBWIKrzeslo class]) {
- [krzesla addObject:zasob];
- }
- }
- NSLog(@"%@", [NSArray arrayWithArray:krzesla]);
- }}
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement