Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ConnectItViewController.m
- // ConnectIt
- //
- // Created by Леонид Гребенюк on 7/8/13.
- // Copyright (c) 2013 Леонид Гребенюк. All rights reserved.
- //
- #import "ConnectItViewController.h"
- #import "GameViewController.h"
- #import "Settings.h"
- #import "LAShip.h"
- #import "LAFiledForSettingsShip.h"
- #import "Constants.h"
- #import "MultyEnemy.h"
- #import "ImageMaker.h" // Содание картинок в отдельном классе
- @interface ConnectItViewController () <UIGestureRecognizerDelegate>
- @property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *numberShipsImage;
- @property (strong, nonatomic) NSMutableArray * arrayNumberShip;
- @property (weak, nonatomic) IBOutlet UIImageView *iconImage;
- @property (weak, nonatomic) IBOutlet UIButton *startButon;
- @property (weak, nonatomic) IBOutlet UIImageView *poleImage;
- @property (assign, nonatomic) CGPoint touchOffset;
- @property (assign, nonatomic) CGPoint touchOnDotButton;
- @property (assign, nonatomic) CGPoint firstPositionCenter;
- @property (weak, nonatomic) LAShip *shipButton;
- @property (strong, nonatomic) LAFiledForSettingsShip* filedForSettingsShip;
- @property (strong, nonatomic) NSArray *arrayDots;
- @property (strong, nonatomic) IBOutletCollection(LAShip) NSArray *shipImages;
- @property (weak, nonatomic) IBOutlet UILabel *rankLabel;
- @end
- @implementation ConnectItViewController
- - (LAFiledForSettingsShip*) filedForSettingsShip {
- if (!_filedForSettingsShip) {
- _filedForSettingsShip = [[LAFiledForSettingsShip alloc] init];
- _filedForSettingsShip.delegate = self;
- }
- return _filedForSettingsShip;
- }
- #pragma mark -
- #pragma mark touch
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- {
- UITouch *touch = [[event allTouches]anyObject];
- for (LAShip* ship in self.shipImages) {
- if([touch view]==ship) {
- long taps = [touch tapCount];
- self.shipButton = ship;
- if (taps==1) {
- [self.shipButton setChoisenShip:YES];
- self.firstPositionCenter = self.shipButton.center;
- CGPoint touchPoint = [touch locationInView:ship];
- self.touchOffset = CGPointMake(CGRectGetMidX(ship.bounds) - touchPoint.x,
- CGRectGetMidY(ship.bounds) - touchPoint.y);
- [self.view bringSubviewToFront:self.shipButton];
- }
- if (taps==2&&ship.x>-1) {
- [self.filedForSettingsShip changeDiraction:self.shipButton];
- }
- }
- }
- }
- - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
- if (self.shipButton) {
- UITouch* touch = [touches anyObject];
- CGPoint pointOnMainView = [touch locationInView:self.view];
- CGPoint correction = CGPointMake(pointOnMainView.x + self.touchOffset.x,
- pointOnMainView.y + self.touchOffset.y);
- self.shipButton.center = correction;
- }
- }
- - (void) onTouchesEnded {
- [self.shipButton setChoisenShip:NO];
- self.shipButton = nil;
- }
- - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
- {
- if (self.shipButton) {
- [self.filedForSettingsShip setShip:self.shipButton];
- [self onTouchesEnded];
- if ([self allShipsSetted]) {
- [self.startButon setEnabled:YES];
- }
- }
- }
- - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
- if (self.shipButton) {
- [self onTouchesEnded];
- }
- }
- #pragma mark -
- #pragma mark logic
- -(BOOL) allShipsSetted {
- for (LAShip * ship in self.shipImages) {
- if (ship.x==-1) {
- return NO;
- }
- }
- return YES;
- }
- -(NSInteger) numberUnSettedShipsSize: (NSInteger) size {
- NSInteger number=0;
- for (LAShip * ship in self.shipImages) {
- if ((ship.size==size)&&(ship.x==-1)) {
- number++;
- }
- }
- return number;
- }
- #pragma mark -
- #pragma mark load
- CGSize sizeScreen;
- -(void) viewDidAppear:(BOOL)animated {
- [super viewDidAppear:YES];
- [self allShipsSetted]? [self.startButon setEnabled:YES] : [self.startButon setEnabled:NO];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- UIFont *font;
- if (iPad) {
- font = [UIFont fontWithName:@"BauhausCTT"size:40];
- } else
- {
- font = [UIFont fontWithName:@"BauhausCTT"size:25];
- }
- [self.rankLabel setFont:font];
- self.filedForSettingsShip.frame = self.poleImage.frame;
- for (LAShip* ship in self.shipImages) {
- ship.width= [self sizeShip:ship.tag-1];
- ship.height = 1;
- ship.x=-1;
- }
- [self rankSetting];
- }
- -(void) rankSetting {
- [self.iconImage setImage: [ImageMaker makeMyIcon]];
- self.rankLabel.text = [StringMaker makeMyRank];
- }
- -(NSInteger) sizeShip: (NSInteger) numberShip {
- NSArray* array = @[@"1",@"1",@"1",@"1",@"2",@"2", @"2", @"3", @"3", @"4" ];
- return [array[numberShip] integerValue];
- }
- #pragma mark LAFieldDelegate
- - (void)moveShipBack{
- self.shipButton.center = self.firstPositionCenter;
- [[Settings data] playSoundIShoot];
- }
- -(void)moveShipToX:(NSInteger)x Y:(NSInteger)y {
- [self.shipButton setFrame:CGRectMake(x+1, y+1, self.shipButton.frame.size.width, self.shipButton.frame.size.height)];
- [[Settings data] playSoundShip:MAX(self.shipButton.width, self.shipButton.height) ];
- NSInteger size = [self.shipButton size];
- for (UIImageView *numberIMG in self.numberShipsImage) {
- if (numberIMG.tag==size) {
- NSInteger number = [self numberUnSettedShipsSize:size];
- NSString *strNumber = [NSString stringWithFormat:@"%li",(long)number];
- [numberIMG setImage:[UIImage imageNamed:strNumber]];
- }
- }
- }
- -(void)flipShip {
- [self.shipButton flip];
- [[Settings data] playSoundDoubleShip];
- }
- #pragma mark -
- #pragma mark bottom Button
- - (IBAction)goBack:(id)sender {
- [[Settings data] playSoundKlick];
- [self.navigationController popViewControllerAnimated:YES];
- [self bigBannerShow];
- }
- - (IBAction)start:(id)sender {
- [[Settings data] playSoundKlick];
- }
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- if ([[segue identifier] isEqualToString:@"GameViewController"])
- {
- GameViewController *controller = [segue destinationViewController];
- controller.shipsArray = self.shipImages;
- }
- }
- - (IBAction)pushButton:(id)sender {
- [self bigBannerShow];
- [[Settings data] playSoundKlick];
- }
- - (IBAction)goShopAction:(id)sender {
- [[Settings data] playSoundKlick];
- [LAUserDefaults boolForKey:@"Kids"] ? [self askParents:KidsShoping]: [self rightAnswerShoping];
- }
- #pragma mark LAKidsDelegate
- - (void)rightAnswerShoping{
- [self performSegueWithIdentifier:@"goShop" sender:self];
- [self bigBannerShow];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement