posted by 프띠버리 2013. 8. 26. 18:38




AppDelegate.h


#import <UIKit/UIKit.h>


@class ViewController;


@interface AppDelegate : UIResponder <UIApplicationDelegate>


@property (strong, nonatomic) UIWindow *window;


@property (strong, nonatomic) ViewController *viewController;


@end



AppDelegate.m

#import "AppDelegate.h"


#import "ViewController.h"


@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

    self.window.rootViewController = self.viewController;

    [self.window makeKeyAndVisible];

    return YES;

}



ViewController.h

#import <UIKit/UIKit.h>


@interface ViewController : UIViewController <UITextFieldDelegate>

{

    IBOutlet UILabel *label;

    IBOutlet UISlider *redSlider;

    IBOutlet UISlider *blueSlider;

    IBOutlet UISlider *greenSlider;

    IBOutlet UITextField *userInputField;

    IBOutlet UIView *colorView;

    UIActivityIndicatorView *activityIndicator;

}

- (IBAction)onColorSliderChanged:(id)sender;

- (IBAction)powerOnOff:(id)sender;


@end



ViewController.m

#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    activityIndicator.center = self.view.center;

    [self.view addSubview:activityIndicator];

    [activityIndicator stopAnimating];

    

//    [redSlider setThumbImage:[UIImage imageNamed:@"red.png"] forState:UIControlStateNormal];

//    [greenSlider setThumbImage:[UIImage imageNamed:@"green.png"] forState:UIControlStateNormal];

//    [blueSlider setThumbImage:[UIImage imageNamed:@"blue.png"] forState:UIControlStateNormal];

    

    [self onColorSliderChanged:nil];

}


- (IBAction)onColorSliderChanged:(id)sender

{

    if([activityIndicator isAnimating])

    {

        [activityIndicator stopAnimating];

    }

    colorView.backgroundColor = [UIColor colorWithRed:(float)redSlider.value/255.0f green:(float)greenSlider.value/255.0f blue:(float)blueSlider.value/255.0f alpha:1.0];

    

}


- (IBAction)powerOnOff:(id)sender

{

    BOOL isOn = ((UISwitch *)sender).on;

    redSlider.enabled = isOn;

    greenSlider.enabled = isOn;

    blueSlider.enabled = isOn;

    

    if(isOn)

    {

        [activityIndicator startAnimating];

        [self performSelector:@selector(onColorSliderChanged:) withObject:nil afterDelay:1.0];

    }

    else

    {

        colorView.backgroundColor = [UIColor grayColor];

    }

}


- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    label.text = userInputField.text;

    [userInputField resignFirstResponder];

    return YES;

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end




TextSliderTest.zip



슬라이더 바를 이용해서 레벨 색상 조정 및 텍스트 필드에서 입력받은 내용 레벨에 보여주기.

온오프 스위치로 활성, 비활성 선택


'Programing > IOS' 카테고리의 다른 글

테이블뷰에 웹뷰가 포함된 소스  (0) 2013.09.11
카드 짝 맞추기 게임  (0) 2013.08.29
TableView 연습 코딩  (0) 2013.08.26
기본 MP3 플레이어 기능 어플  (0) 2013.08.21
숫자야구 게임으로 앱 흉내내기  (0) 2013.08.20
posted by 프띠버리 2013. 8. 26. 17:42

AppDelegate.h

//

//  AppDelegate.h

//  TableVieww

//

//  Created by Lab10 on 13. 8. 21..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import <UIKit/UIKit.h>


@class RootViewController;


@interface AppDelegate : UIResponder <UIApplicationDelegate>

{

    UINavigationController *navigationController;

}


@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) UINavigationController *navigationController;


@end



AppDelegate.m

#import "AppDelegate.h"


//#import "ViewController.h"

#import "RootViewController.h"


@implementation AppDelegate

@synthesize window;

@synthesize navigationController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    // 애플리케이션 시작 수행될 개발자가 원하는 코드를 추가하는 부분

    UIViewController *rootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

    navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    [self.window addSubview:navigationController.view];

    

    [self.window makeKeyAndVisible];

    return YES;

}



RootViewController.h



#import <UIKit/UIKit.h>

@class BooksViewController;

@interface RootViewController : UITableViewController

{

    NSArray *authorList;

    BooksViewController *booksController;

}


@property (strong, nonatomic) NSArray *authorList;

@property (strong, nonatomic) IBOutlet BooksViewController *booksController;


@end



RootViewController.m

#import "RootViewController.h"

#import "BooksViewController.h"


@interface RootViewController ()


@end


@implementation RootViewController

@synthesize authorList;

@synthesize booksController;


- (id)initWithStyle:(UITableViewStyle)style

{

    self = [super initWithStyle:style];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    self.authorList = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", nil];

    self.title = @"Month";

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [self.authorList count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    

    cell.textLabel.text = [self.authorList objectAtIndex:[indexPath row]];

    

    return cell;

}


#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    if(0 == indexPath.row)

    {

        self.booksController.title = @"1";

    }

    else if(1 == indexPath.row)

    {

        self.booksController.title = @"2";

    }

    else

    {

        self.booksController.title = @"3";

    }

    

    [self.navigationController pushViewController:self.booksController animated:YES];

}


@end



BooksViewController.h


#import <UIKit/UIKit.h>

@class NiceViewController;

@interface BooksViewController : UITableViewController

{

    NSArray *books;

    NiceViewController *niceController;

}

@property (strong, nonatomic) NSArray *books;

@property (strong, nonatomic) IBOutlet NiceViewController *niceController;


@end



BooksViewController.m


#import "BooksViewController.h"

#import "NiceViewController.h"


@interface BooksViewController ()


@end


@implementation BooksViewController

@synthesize books;

@synthesize niceController;


- (id)initWithStyle:(UITableViewStyle)style

{

    self = [super initWithStyle:style];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];


}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [books count];

}


- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    if([self.title isEqualToString:@"1"])

    {

        books = [[NSArray alloc] initWithObjects:@"1 1", @"1 2", @"1 3", @"1 4", @"1 5", @"1 6", nil];

    }

    else if([self.title isEqualToString:@"2"])

    {

        books = [[NSArray alloc] initWithObjects:@"2 1", @"2 2", @"2 3", @"2 4", @"2 5", nil];

    }

    else

    {

        books = [[NSArray alloc] initWithObjects:@"3 1", @"3 2", @"3 3", @"3 4", @"3 5", @"3 6", nil];

    }


    [self.tableView reloadData];

    

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    

    cell.textLabel.text = [books objectAtIndex:[indexPath row]];

    

    return cell;

}



#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    if([self.title isEqualToString:@"1"])

    {

        if(0 == indexPath.row)

        {

            self.niceController.title = @"1 1";

        }

        else if(1 == indexPath.row)

        {

            self.niceController.title = @"1 2";

        }

        else if(2 == indexPath.row)

        {

            self.niceController.title = @"1 3";

        }

        else if(3 == indexPath.row)

        {

            self.niceController.title = @"1 4";

        }

        else if(4 == indexPath.row)

        {

            self.niceController.title = @"1 5";

        }

        else

        {

            self.niceController.title = @"1 6";

        }

    }

    else if([self.title isEqualToString:@"2"])

    {

        if(0 == indexPath.row)

        {

            self.niceController.title = @"2 1";

        }

        else if(1 == indexPath.row)

        {

            self.niceController.title = @"2 2";

        }

        else if(2 == indexPath.row)

        {

            self.niceController.title = @"2 3";

        }

        else if(3 == indexPath.row)

        {

            self.niceController.title = @"2 4";

        }

        else

        {

            self.niceController.title = @"2 5";

        }

    }

    else

    {

        if(0 == indexPath.row)

        {

            self.niceController.title = @"3 1";

        }

        else if(1 == indexPath.row)

        {

            self.niceController.title = @"3 2";

        }

        else if(2 == indexPath.row)

        {

            self.niceController.title = @"3 3";

        }

        else if(3 == indexPath.row)

        {

            self.niceController.title = @"3 4";

        }

        else if(4 == indexPath.row)

        {

            self.niceController.title = @"3 5";

        }

        else

        {

            self.niceController.title = @"3 6";

        }

    }


    [self.navigationController pushViewController:self.niceController animated:YES];

}

@end



NiceViewController.h

#import <UIKit/UIKit.h>


@interface NiceViewController : UITableViewController

{

    NSArray *nice;

}


@property (strong, nonatomic) NSArray *nice;


@end



NiceViewController.m

#import "NiceViewController.h"


@interface NiceViewController ()


@end


@implementation NiceViewController

@synthesize nice;


- (id)initWithStyle:(UITableViewStyle)style

{

    self = [super initWithStyle:style];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [nice count];

}


- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    if([self.title isEqualToString:@"1 1"])

    {

         nice = [[NSArray alloc] initWithObjects:@"1kg", @"1cm", @"1", @"", nil];

    }

    else if([self.title isEqualToString:@"1 2"])

    {

        nice = [[NSArray alloc] initWithObjects:@"2kg", @"2cm", @"2", @"", nil];

    }

    else if([self.title isEqualToString:@"1 3"])

    {

        nice = [[NSArray alloc] initWithObjects:@"3kg", @"3cm", @"3", @"", nil];

    }

    else if([self.title isEqualToString:@"1 4"])

    {

        nice = [[NSArray alloc] initWithObjects:@"4kg", @"4cm", @"4", @"", nil];

    }

    else if([self.title isEqualToString:@"1 5"])

    {

        nice = [[NSArray alloc] initWithObjects:@"5kg", @"5cm", @"5", @"", nil];

    }

    else if([self.title isEqualToString:@"1 6"])

    {

        nice = [[NSArray alloc] initWithObjects:@"6kg", @"6cm", @"6", @"", nil];

    }

    else if([self.title isEqualToString:@"2 1"])

    {

        nice = [[NSArray alloc] initWithObjects:@"7kg", @"7cm", @"7", @"", nil];

    }

    else if([self.title isEqualToString:@"2 2"])

    {

        nice = [[NSArray alloc] initWithObjects:@"8kg", @"8cm", @"8", @"", nil];

    }

    else if([self.title isEqualToString:@"2 3"])

    {

        nice = [[NSArray alloc] initWithObjects:@"9kg", @"9cm", @"9", @"", nil];

    }

    else if([self.title isEqualToString:@"2 4"])

    {

        nice = [[NSArray alloc] initWithObjects:@"10kg", @"10cm", @"10", @"", nil];

    }

    else if([self.title isEqualToString:@"2 5"])

    {

        nice = [[NSArray alloc] initWithObjects:@"11kg", @"11cm", @"10", @"", nil];

    }

    else if([self.title isEqualToString:@"3 1"])

    {

        nice = [[NSArray alloc] initWithObjects:@"12kg", @"12cm", @"11", @"", nil];

    }

    else if([self.title isEqualToString:@"3 2"])

    {

        nice = [[NSArray alloc] initWithObjects:@"13kg", @"13cm", @"12", @"", nil];

    }

    else if([self.title isEqualToString:@"3 3"])

    {

        nice = [[NSArray alloc] initWithObjects:@"14kg", @"14cm", @"13", @"", nil];

    }

    else if([self.title isEqualToString:@"3 4"])

    {

        nice = [[NSArray alloc] initWithObjects:@"15kg", @"15cm", @"14", @"", nil];

    }

    else if([self.title isEqualToString:@"3 5"])

    {

        nice = [[NSArray alloc] initWithObjects:@"16kg", @"16cm", @"15", @"", nil];

    }

    else

    {

        nice = [[NSArray alloc] initWithObjects:@"17kg", @"17cm", @"16", @"", nil];

    }

    

    [self.tableView reloadData];

    

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    

    // Configure the cell...

    cell.textLabel.text = [nice objectAtIndex:[indexPath row]];

    

    return cell;

}



#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    

}

@end



테이블뷰를 이용한 이동 관련 소스

posted by 프띠버리 2013. 8. 21. 17:40





MasterViewController.h


//

//  MasterViewController.h

//  MP3Player

//

//  Created by Lab10 on 13. 8. 6..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import <UIKit/UIKit.h>


// 헤더 추가

//#import "AVFoundation/AVAudioPlayer.h"

//#define AUDIO_PLAYER_EXAM   // AVAudioPlayer 기능 테스트


@class DetailViewController;


@interface MasterViewController : UITableViewController

{

    // 오디오 재생 클래스

    //AVAudioPlayer *audioPlayer;

    

    // mp3 리스트

    NSArray *dirContents;

    

}


@property (strong, nonatomic) DetailViewController *detailViewController;


@end



MasterViewController.m


//

//  MasterViewController.m

//  MP3Player

//

//  Created by Lab10 on 13. 8. 6..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import "MasterViewController.h"


#import "DetailViewController.h"


// 헤더 추가

#import "MP3ViewController.h"



@interface MasterViewController () {

    NSMutableArray *_objects;

}


@end


@implementation MasterViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        //self.title = NSLocalizedString(@"Master", @"Master");

        self.title = @"MP3 Player";

        

    }

    return self;

}

- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    

#ifdef AUDIO_PLAYER_EXAM

    // 번들 mp3파일 경로 생성

    NSString *mp3FilePath=[[NSBundle mainBundle] pathForResource:@"tellmetellme" ofType:@"mp3"];

    

    // NSURL 형식으로 변환

    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:mp3FilePath];

    

    // 오디오 플레이어 생성

    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];

    

    // 사운드 재생 준비 확인

    [audioPlayer prepareToPlay];

    

#endif

    

    // 상태 스타일 변경

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];

    

    // 네비게이션 스타일 변경

    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;

    

    // 도큐먼트 디렉터리에서 mp3 파일을 획득하여 리스트 생성

    NSArray *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *docDir = [docPath objectAtIndex:0];

    NSArray *extensions = [NSArray arrayWithObjects:@"mp3", @"MP3", nil];

    NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docDir error:nil];

    dirContents = [contents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"pathExtension IN %@", extensions]];

    

//    self.navigationItem.leftBarButtonItem = self.editButtonItem;


//    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];

//    self.navigationItem.rightBarButtonItem = addButton;

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (void)insertNewObject:(id)sender

{

    if (!_objects) {

        _objects = [[NSMutableArray alloc] init];

    }

    [_objects insertObject:[NSDate date] atIndex:0];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

}


//#pragma mark - Table View


//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

//{

//    return 1;

//    return [dirContents count];

//}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    //return _objects.count;

    return [dirContents count];

}


// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    }



   // NSDate *object = _objects[indexPath.row];

   // cell.textLabel.text = [object description];

    

#ifdef AUDIO_PLAYER_EXAM

    if(audioPlayer.isPlaying)

    {

        // 재생 중이면 [일시정지] 표시

        cell.textLabel.text = @"PAUSE";

    }

    else

    {

        // 재생 중이 아니면 [재생] 표시

        cell.textLabel.text = @"PLAY";

    }

#endif

    

    cell.textLabel.text = [dirContents objectAtIndex:indexPath.row];

    

    return cell;

}


- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    // Return NO if you do not want the specified item to be editable.

    return YES;

}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (editingStyle == UITableViewCellEditingStyleDelete) {

        [_objects removeObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

    } else if (editingStyle == UITableViewCellEditingStyleInsert) {

        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.

    }

}


/*

// Override to support rearranging the table view.

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath

{

}

*/


/*

// Override to support conditional rearranging of the table view.

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    // Return NO if you do not want the item to be re-orderable.

    return YES;

}

*/


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

#ifdef AUDIO_PLAYER_EXAM

    if(audioPlayer.isPlaying)

    {

        // 재생 중이면 일시정지

        [audioPlayer pause];

    }

    else

    {

        // 재생 중이 아니면 재생 시작

        [audioPlayer play];

    }

    // 테이블 갱신

    [self.tableView reloadData];

#endif

    // MP3ViewController 생성 삽입

    MP3ViewController *subViewController = [[MP3ViewController alloc] initWithNibName:@"MP3ViewController" bundle:nil];

    [subViewController setFileList:dirContents fileIndex:indexPath.row];

    [self.navigationController pushViewController:subViewController animated:YES];

    

}


@end


DetailViewController.h


//

//  DetailViewController.h

//  MP3Player

//

//  Created by Lab10 on 13. 8. 6..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface DetailViewController : UIViewController


@property (strong, nonatomic) id detailItem;


@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;

@end



DetailViewController.m

//

//  DetailViewController.m

//  MP3Player

//

//  Created by Lab10 on 13. 8. 6..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import "DetailViewController.h"


@interface DetailViewController ()

- (void)configureView;

@end


@implementation DetailViewController


#pragma mark - Managing the detail item


- (void)setDetailItem:(id)newDetailItem

{

    if (_detailItem != newDetailItem) {

        _detailItem = newDetailItem;

        

        // Update the view.

        [self configureView];

    }

}


- (void)configureView

{

    // Update the user interface for the detail item.


    if (self.detailItem) {

        self.detailDescriptionLabel.text = [self.detailItem description];

    }

}


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    [self configureView];

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        self.title = NSLocalizedString(@"Detail", @"Detail");

    }

    return self;

}

@end



MP3ViewController.h


//

//  MP3ViewController.h

//  MP3Player

//

//  Created by Lab10 on 13. 8. 6..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import <UIKit/UIKit.h>


// 헤더 추가

#import "AVFoundation/AVAudioPlayer.h"

#import "MediaPlayer/MPVolumeView.h"


// 메타 데이터 관련 헤더

#import "AVFoundation/AVAsset.h"

#import "AVFoundation/AVMetadataItem.h"


// 재생 상태 열거

typedef enum PLAY_STATE{

    NOT_READY = 0// 준비되지 않음

    PLAYING,        // 재생

    PAUSED,         // 일시정지

    STOPPED,        // 정지

}_PLAY_STATE;



@interface MP3ViewController : UIViewController

{

    // 오디오 재생 클래스

    AVAudioPlayer *audioPlayer;

    

    // 파일 리스트

    NSArray *fileList;

    

    // 파일 인덱스

    NSInteger fileIndex;

    

    // 타임라인 슬라이더

    UISlider *timeSlider;

    

    // 볼륨 컨트롤

    MPVolumeView *volumeView;

    

    // 현재 시간

    UILabel *curTime;

    

    // 재생 시간

    UILabel *totTime;

    

    // 재생 버튼

    UIButton *btnPlay;

    

    // 파일 이름

    NSString *fileName;

    

    // 컨트롤 배경

    UIImageView *ctrlBg;

    

    // 슬라이더 배경

    UIImageView *progBg;

    

    // 이전 버튼

    UIButton *btnPrev;

    

    // 일시정지 버튼

    UIButton *btnPause;

    

    // 다음 버튼

    UIButton *btnNext;

    

    // 재킷 이미지

    UIImageView *artworkView;

    

    // 재생 상태

    int playState;

    

    // 오버레이 상태

    BOOL bOverlay;

    

    // 드래깅 상태

    BOOL bDragging;

    

    // 타이머

    NSTimer *tsTimer;

}


// 파일 리스트 설정

- (void) setFileList:(NSArray *)list fileIndex:(NSInteger) index;


@end



MP3ViewController.m


//

//  MP3ViewController.m

//  MP3Player

//

//  Created by Lab10 on 13. 8. 6..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import "MP3ViewController.h"


@interface MP3ViewController ()


@end


@implementation MP3ViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

    

    // 타이틀을 파일명으로 변경

    self.title = [fileList objectAtIndex:fileIndex];

    

    

    // 파일 URL 생성

    NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *docDirectory = [sysPaths objectAtIndex:0];

    NSString *filePath = [NSString stringWithFormat:@"%@/%@", docDirectory, [fileList objectAtIndex:fileIndex]];

    

    // 재킷 이미지 출력

    [self artworksForFileAtPath:filePath];

    

    // 플레이어 컨트롤 초기화

    [self initPlayerControls];

    

    // 오디오 플레이어 생성

    NSURL *url = [NSURL fileURLWithPath:filePath];

    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

    audioPlayer.delegate = (id)self;

    

    if(audioPlayer == nil)

    {

        return;

    }

    else

    {

        if([audioPlayer prepareToPlay])

        {

            // 탐색 슬라이더 설정

            [timeSlider setMaximumValue:[audioPlayer duration]];

            

            // 현재 시간 업데이트 타이머 시작

            tsTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTimeStamp) userInfo:nil repeats:YES];

            

            // 재생 시작

            [audioPlayer play];

            

        }

    }

}



// 뷰가 사라질 처리를 위해서 추가

- (void) viewWillDisappear:(BOOL)animated

{

    // 재생 중인 경우 정지

    if(audioPlayer.isPlaying)

    {

        [audioPlayer stop];

    }

    

    [super viewWillDisappear:animated];

    

}


// 재생 종료 델리게이트 매서드

- (void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag

{

    // 다음 곡을 재생

    [self onBtnNext];

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


// 오디오 파일 리스트 인덱스 설정

- (void) setFileList:(NSArray *)list fileIndex:(NSInteger)index

{

    // 파일 리스트 저장

    fileList = list;

    

    // 현재 파일 인덱스 저장

    fileIndex = index;

    

}


// MP3 파일에서 Artwork 이미지 추출

- (void)artworksForFileAtPath:(NSString *)path

{

    if (!artworkView)

    {

        // 재킷 이미지 출력을 위한 이미지 뷰를 생성

        artworkView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];

        artworkView.userInteractionEnabled = YES;

        [self.view addSubview:artworkView];

        

        // 제스처를 등록

        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(overlaySwitch)];

        [tap setNumberOfTapsRequired:1];

        [artworkView addGestureRecognizer:tap];

        

    }

    

    // 파일의 메타데이터를 획득

    AVAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:path] options:nil];

    NSArray *metadata = [asset commonMetadata];

    

    // artwork 데이터를 artworkView 적용

    for (AVMetadataItem* item in metadata)

    {

        if([[item commonKey] isEqualToString:@"artwork"])

        {

            UIImage *artworkImage = nil;

            if([[item value] isKindOfClass:[NSDictionary class]])

            {

                NSDictionary *imageDic = (NSDictionary *) [item value];

                

                if([imageDic objectForKey:@"data"] != nil)

                {

                    NSData *imageData = [imageDic objectForKey:@"data"];

                    artworkImage = [UIImage imageWithData:imageData];

                    artworkView.image = artworkImage;

                }

            }

        }

    }

}



// 오디오 파일 다시 재생

- (void) restartPlayer

{

    // 타이틀 변경

    self.title = [fileList objectAtIndex:fileIndex];

    

    // 파일 URL 생성

    

    NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *docDirectory = [sysPaths objectAtIndex:0];

    NSString *filePath = [NSString stringWithFormat:@"%@/%@", docDirectory, [fileList objectAtIndex:fileIndex]];

    

    NSURL *url = [NSURL fileURLWithPath:filePath];

    

    

    // 오디오 플레이어 생성 적용

    AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

    player.delegate = (id)self;

    audioPlayer = player;

    

    

    // 컨트롤 세팅 재생 시작

    if([audioPlayer prepareToPlay])

    {

        // 탐색 범위 설정

        [timeSlider setMaximumValue:[audioPlayer duration]];

        

        // 타이머 리셋

        [tsTimer invalidate];

        tsTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTimeStamp) userInfo:nil repeats:YES];

        

        // 재킷 이미지 변경

        [self artworksForFileAtPath:filePath];

        

        // 재생 시작

        [audioPlayer play];

        

    }

}


// 이전 버튼 이벤트

- (void) onBtnPrev

{

    if(fileIndex == 0)

    {

        fileIndex = [fileList count]-1;

    }

    else

    {

        fileIndex--;

    }

    btnPlay.hidden = YES;

    btnPause.hidden = NO;

    [self restartPlayer];

}



// 다음 버튼 이벤트

- (void) onBtnNext

{

    if([fileList count] <= fileIndex+1)

    {

        fileIndex = 0;

    }

    else

    {

        fileIndex++;

    }

    btnPlay.hidden = YES;

    btnPause.hidden = NO;

    [self restartPlayer];

}



// 재생 버튼 이벤트

- (void) onBtnPlay

{

    // 상태 변경 재생 시작

    playState = PLAYING;

    btnPlay.hidden = YES;

    btnPause.hidden = NO;

    [audioPlayer play];

}



// 일시정지 버튼 이벤트

- (void) onBtnPause

{

    // 상태 변경 일시정지

    playState = PAUSED;

    btnPlay.hidden = NO;

    btnPause.hidden = YES;

    [audioPlayer pause];

}



// 오버레이 보이기/숨기기

- (void) showOverlay:(BOOL) show

{

    progBg.hidden = timeSlider.hidden = curTime.hidden = totTime.hidden = !show;

}


// 오버레이 상태 변경

- (void) overlaySwitch

{

    // 오버레이 플래그를 변경

    bOverlay = !bOverlay;

    [self showOverlay:bOverlay];

}


// 재생시간 업데이트

- (void) updateTimeStamp

{

    // 플레이어가 생성되지 않은 경우 타이머 종료

    if(audioPlayer == nil)

    {

        [tsTimer invalidate];

        tsTimer = nil;

        return;

    }

    

    // 드레깅 중에는 취소

    if(bDragging) return;

    

    // 현재 시간, 남은 시간 계산

    int cur = (int)[audioPlayer currentTime];

    int ext = (int)[audioPlayer duration]-cur;

    

    // 슬라이더 위치 변경

    [timeSlider setValue:[audioPlayer currentTime]];

    

    // 시간 업데이트

    [curTime setText:[NSString stringWithFormat:@"%02d:%02d", cur/60, cur%60]];

    [totTime setText:[NSString stringWithFormat:@"-%02d:%02d", ext/60, ext%60]];

    

}



// 타임라인 드래그 처리

- (void) slideDragging

{

    

    // 현재 시간, 남은 시간 계산

    int cur = (int)timeSlider.value;

    int ext = (int)timeSlider.maximumValue-cur;

    

    // 시간 업데이트

    if(audioPlayer != nil)

    {

        [curTime setText:[NSString stringWithFormat:@"%02d:%02d", cur/60, cur%60]];

        [totTime setText:[NSString stringWithFormat:@"-%02d:%02d", ext/60, ext%60]];

        

    }

}



// 슬라이드 선택

- (void) slideSelected

{

    // 플래그 변경

    bDragging = YES;

}


// 슬라이드 해제

- (void) slideRelease

{

    // 플래그 변경

    bDragging = NO;

    

    // 재생 위치를 변경

    [audioPlayer setCurrentTime:timeSlider.value];

    

}



// 플레이어 컨트롤 초기화

- (void) initPlayerControls

{

    

    // 아래쪽 생성

    ctrlBg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bottom_bar.png"]];

    ctrlBg.frame = CGRectMake(0, 320, 320, 96);

    [self.view addSubview:ctrlBg];

    

    // 탐색 슬라이더 배경

    progBg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"progress_bg.png"]];

    progBg.frame = CGRectMake(0, 0, 320, 44);

    progBg.alpha = 0.9f;

    [self.view addSubview:progBg];

    

    // 탐색 슬라이더

    timeSlider = [[UISlider alloc] initWithFrame:CGRectMake(50, 12, 220, 22)];

    [self.view addSubview:timeSlider];

    [timeSlider addTarget:self action:@selector(slideDragging) forControlEvents:UIControlEventTouchDragInside];

    [timeSlider addTarget:self action:@selector(slideSelected) forControlEvents:UIControlEventTouchDown];

    [timeSlider addTarget:self action:@selector(slideRelease) forControlEvents:UIControlEventTouchUpInside];

    [timeSlider addTarget:self action:@selector(slideRelease) forControlEvents:UIControlEventTouchUpOutside];

    

    // 현재 시간, 남은 시간 출력 레이블

    curTime = [[UILabel alloc] initWithFrame:CGRectMake(10, 12, 35, 22)];

    curTime.text = @"00:00";

    totTime = [[UILabel alloc] initWithFrame:CGRectMake(275, 12, 40, 22)];

    totTime.text = @"-00:00";

    curTime.backgroundColor = totTime.backgroundColor = [UIColor clearColor];

    curTime.textColor = totTime.textColor = [UIColor whiteColor];

    curTime.font = totTime.font = [UIFont boldSystemFontOfSize:12];

    // curTime.textAlignment = UITextAlignmentRight;

    [self.view addSubview:curTime];

    [self.view addSubview:totTime];

    

    // 이전 버튼

    btnPrev = [[UIButton alloc] init];

    btnPrev.frame = CGRectMake(64, 325, 44, 44);

    [btnPrev setImage:[UIImage imageNamed:@"button_prev.png"] forState:UIControlStateNormal];

    [btnPrev addTarget:self action:@selector(onBtnPrev) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btnPrev];

    

    // 재생시작 버튼

    btnPlay = [[UIButton alloc] init];

    btnPlay.frame = CGRectMake(138, 325, 44, 44);

    [btnPlay setImage:[UIImage imageNamed:@"button_play.png"] forState:UIControlStateNormal];

    [btnPlay addTarget:self action:@selector(onBtnPlay) forControlEvents:UIControlEventTouchUpInside];

    btnPlay.hidden = YES;

    [self.view addSubview:btnPlay];

    

    // 일시정지 버튼

    btnPause = [[UIButton alloc] init];

    btnPause.frame = CGRectMake(138, 325, 44, 44);

    [btnPause setImage:[UIImage imageNamed:@"button_pause.png"] forState:UIControlStateNormal];

    [btnPause addTarget:self action:@selector(onBtnPause) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btnPause];


    // 다음 버튼

    btnNext = [[UIButton alloc] init];

    btnNext.frame = CGRectMake(212, 325, 44, 44);

    [btnNext setImage:[UIImage imageNamed:@"button_next.png"] forState:UIControlStateNormal];

    [btnNext addTarget:self action:@selector(onBtnNext) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btnNext];

    

    // 볼륨 조절 컨트롤

    volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(30, 370, 260, 46)];

    [volumeView sizeToFit];

    [self.view addSubview:volumeView];

    

    // 오버레이 컨트롤 감춤

    [self showOverlay:bOverlay];

    

}

@end

posted by 프띠버리 2013. 8. 20. 17:30






NumberBaseball2.zip



소스 부분

ViewController.h

//

//  ViewController.h

//  NumberBaseball2

//

//  Created by Lab10 on 13. 8. 19..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface ViewController : UIViewController


- (IBAction)playball;

- (IBAction)help;


@end


ViewController.m

//

//  ViewController.m

//  NumberBaseball2

//

//  Created by Lab10 on 13. 8. 19..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import "ViewController.h"

// 게임과 도움 헤더파일 포함

#import "playball.h"

#import "help.h"


@interface ViewController ()


@end


@implementation ViewController


// 게임 시작 화면으로 이동

- (IBAction)playball

{

    playball *view = [[playball alloc] initWithNibName:@"playball" bundle:nil];

    view.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    [self presentViewController:view animated:YES completion:nil];

}


// 도움말 화면으로 이동

- (IBAction)help

{

    help *view = [[help alloc] initWithNibName:@"help" bundle:nil];

    view.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    [self presentViewController:view animated:YES completion:nil];

}


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


help.h

//

//  help.h

//  NumberBaseball2

//

//  Created by Lab10 on 13. 8. 19..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface help : UIViewController


- (IBAction)mainmenu;


@end


help.m

//

//  help.m

//  NumberBaseball2

//

//  Created by Lab10 on 13. 8. 19..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import "help.h"


@interface help ()


@end


@implementation help


// 메인화면으로 돌아가기

- (IBAction)mainmenu

{

    [self dismissViewControllerAnimated:YES completion:nil];

}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


playball.h

//

//  playball.h

//  NumberBaseball2

//

//  Created by Lab10 on 13. 8. 19..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import <UIKit/UIKit.h>

// 사운드를 위해  AVAFound 포함

#import <AVFoundation/AVFoundation.h>


@interface playball : UIViewController<AVAudioPlayerDelegate>

{

    AVAudioPlayer *theAudio;

}


@property (strong, nonatomic) IBOutlet UITextField *InputNum1;

@property (strong, nonatomic) IBOutlet UITextField *InputNum2;

@property (strong, nonatomic) IBOutlet UITextField *InputNum3;

@property (strong, nonatomic) IBOutlet UITextView *viewText;

- (IBAction)btnHit:(id)sender;


- (IBAction)mainmenu;


@end


playball.m

//

//  playball.m

//  NumberBaseball2

//

//  Created by Lab10 on 13. 8. 19..

//  Copyright (c) 2013 Lab10. All rights reserved.

//


#import "playball.h"


@interface playball ()


@end


@implementation playball

@synthesize InputNum1;              // 텍스트필드 1 정의

@synthesize InputNum2;              // 텍스트필드 2 정의

@synthesize InputNum3;              // 텍스트필드 3 정의

@synthesize viewText;               // 텍스트뷰 정의

NSString *result;                   // 결과를 보여줄 문자열 전역으로 정의

NSNumber *nnum1;                    // 랜덤 생성할 1 숫자

NSNumber *nnum2;                    // 랜덤 생성할 2 숫자

NSNumber *nnum3;                    // 랜덤 생성할 3 숫자

int count = 0;                      // 카운트 표시


- (IBAction)btnHit:(id)sender {

    // 스트라이크와 볼을 구하기 위한 변수 선언

    int ball = 0, strick = 0;

    

    // 텍스트 필드로 입력 받은 넘기기

    NSNumber *num1 = [[NSNumber alloc] initWithInt:[InputNum1.text intValue]];

    NSNumber *num2 = [[NSNumber alloc] initWithInt:[InputNum2.text intValue]];

    NSNumber *num3 = [[NSNumber alloc] initWithInt:[InputNum3.text intValue]];

    

    // 배열에 텍스트 필드로 받은 넣기

    NSArray *intNum = [NSArray arrayWithObjects: num1, num2, num3, nil];

    

    // 랜덤 숫자 배열에 넣기

    NSArray *resNum = [NSArray arrayWithObjects: nnum1, nnum2, nnum3, nil];

    

    // 텍스트 필드가 공백일때

    if([InputNum1.text isEqualToString:@""] || [InputNum2.text isEqualToString:@""] || [InputNum3.text isEqualToString:@""])

    {

        viewText.text = @"공백은 입력할수 없습니다.";

        NSLog(@"빈칸이랑께");

    }

    // 텍스트 필드에 문자가 입력되었을때

//    else if(![InputNum1.text intValue] || ![InputNum2.text intValue] || ![InputNum3.text intValue])

//    {

//        viewText.text = @"문자는 입력할수 없습니다.";

//        NSLog(@"문자시져");

//    }

    // 텍스트 필드의 숫자가 두자리 이상일때

    else if([InputNum1.text intValue] > 9 || [InputNum2.text intValue] > 9 || [InputNum3.text intValue] > 9)

    {

        viewText.text = @"숫자는 한자리수만 가능합니다.";

        NSLog(@"숫자많앙");

    }

    // 텍스트 필드의 숫자가 중복되었을때

    else if([InputNum1.text intValue] == [InputNum2.text intValue] || [InputNum1.text intValue] == [InputNum3.text intValue] || [InputNum2.text intValue] == [InputNum3.text intValue])

    {

        viewText.text = @"중복된 숫자는 사용할수 없습니다.";

        NSLog(@"중복이양");

    }

    // 모든 예외체크를 통과 했다면

    else

    {

        count = count + 1;

        // 스트라이크와 볼을 구하는 부분

        for(int i=0;i<3;i++)

        {

            // 입력받은 수와 지정된 임의의 수를 비교하여 스트라이크 구하기

            if([intNum objectAtIndex:i] == [resNum objectAtIndex:i])

            {

                strick = strick + 1;                    // 자리와 숫자가 일치하면 스트라이크+1

                NSLog(@"%d 스트라이크", strick);

            }

            

            // 입력받은 수와 지정된 임의의 수를 비교하여 구하기

            if([intNum objectAtIndex:i] != [resNum objectAtIndex:i])

            {

                // 첫번째 숫자 부터 같은지 비교 시작

                for(int j=0;j<3;j++)

                {

                    // 만약 자리가 다르고 같은수가 있다면

                    if([intNum objectAtIndex:i] == [resNum objectAtIndex:j])

                    {

                        ball = ball + 1;                // +1

                        NSLog(@"%d ", ball);

                    }

                }

            }

        }

        

        // 텍스트 필드로 입력받은 숫자와 스트라이크 표시

        NSString *msg = [NSString stringWithFormat:@"%2d : %@ %@ %@ () %d %d 스트라이크 입니다.\n", count, [intNum objectAtIndex:0], [intNum objectAtIndex:1], [intNum objectAtIndex:2], ball, strick];

        

        // 앞의 진행상황을 계속해서 보여줌

        result = [NSString stringWithFormat:@"%@%@", result, msg];

        

        // 뷰텍스트에 표시

        viewText.text = result;

        

    }

    // 3스트라이크가 되었을때 승리창 띄우기

    if(strick == 3)

    {

        // 승리 사운드

        NSString *path = [[NSBundle mainBundle] pathForResource:@"woo" ofType:@"wav"];

        theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

        theAudio.delegate = self;

        [theAudio play];

        

        // 경고창

        NSString *msg = [NSString stringWithFormat:@"축하합니다! 당신의 승리입니다."];

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You WIN!!" message:msg delegate:self cancelButtonTitle:@"메인으로" otherButtonTitles:@"다시하기", nil];

        alert.tag = 11;

        [alert show];

    }

    // 10 동안안에 맞추면 패배창 띄우기

    if(strick !=3 && count == 10)

    {

        // 패배 사운드

        NSString *path2 = [[NSBundle mainBundle] pathForResource:@"boo" ofType:@"wav"];

        theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path2] error:NULL];

        theAudio.delegate = self;

        [theAudio play];

        

        // 경고창

        NSString *msg = [NSString stringWithFormat:@"당신은 패배하였습니다."];

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You LOSE!!" message:msg delegate:self cancelButtonTitle:@"메인으로" otherButtonTitles:@"다시하기", nil];

        alert.tag = 12;

        [alert show];

    }

    

    // 텍스트 필드 초기화

    InputNum1.text = @"";

    InputNum2.text = @"";

    InputNum3.text = @"";

    

    // 텍스트 필드 리턴시 자판 내려가기

    [InputNum1 resignFirstResponder];

    [InputNum2 resignFirstResponder];

    [InputNum3 resignFirstResponder];

}


// UIALertView설정

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if(buttonIndex == alertView.firstOtherButtonIndex)

    {

        [self initPlayball];

    }else

    {

        [self mainmenu];

    }

}


// 메인 화면으로 돌아가기

- (IBAction)mainmenu

{

    [self dismissViewControllerAnimated:YES completion:nil];

}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

 

    [self initPlayball];

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


// 게임 초기화

- (void)initPlayball

{

    // 텍스트 필드에서 자판 번호모양으로 표시

    InputNum1.keyboardType=UIKeyboardTypeNumberPad;

    InputNum2.keyboardType=UIKeyboardTypeNumberPad;

    InputNum3.keyboardType=UIKeyboardTypeNumberPad;

    

    // 텍스트 필드 초기화

    [InputNum1 setText:@""];

    [InputNum2 setText:@""];

    [InputNum3 setText:@""];

    

    // nnum 초기화 시켜주기

    nnum1 = 0;

    nnum2 = 0;

    nnum3 = 0;

    count = 0;

    

    viewText.text = @"";

    

    // 랜덤 숫자 3 구하기

    while(nnum1 == nnum2 || nnum2 == nnum3 || nnum3 == nnum1)

    {

        nnum1 = [[NSNumber alloc] initWithInt:arc4random()%10];

        nnum2 = [[NSNumber alloc] initWithInt:arc4random()%10];

        nnum3 = [[NSNumber alloc] initWithInt:arc4random()%10];

    }

    

    NSLog(@"%@ %@ %@", nnum1, nnum2, nnum3);   // 개발자 CMD화면에 랜덤 찍어보기

    

    // 텍스트 결과창 초기화

    result = @"";


}

@end



'Programing > IOS' 카테고리의 다른 글

테이블뷰에 웹뷰가 포함된 소스  (0) 2013.09.11
카드 짝 맞추기 게임  (0) 2013.08.29
Slider 및 TextField 및 OnOff 스위치 연습  (0) 2013.08.26
TableView 연습 코딩  (0) 2013.08.26
기본 MP3 플레이어 기능 어플  (0) 2013.08.21
posted by 프띠버리 2012. 8. 28. 23:11

 

글중 네이버 제이피의 세상 나들이 블로그에서 통째로 퍼와진 글들이

있는데 그것은 제이피와 제가 함께 블로그를 써서 중복되는 글들이 있어서 그런것입니다.

 

posted by 프띠버리 2012. 8. 28. 23:08

디아블로3와 같은 조작방식의 마블히어로즈PC / GAME

2012/08/16 16:05수정삭제

복사http://blog.naver.com/darkngel77/50147928240

마블히어로즈(MARVEL HEROES)라는 게임이 15일 열린 게임스컴 개막식에서 새로운 트레일러를 선보였습니다.

액션MMORPG로써 디아블로와 같은 방식의 조작법을 가진 게임인데요. 원체 히어로물을 좋아하는 지라가 관심이 생겨서 한번 살펴보게 되었습니다.

가질리언엔터테인먼트에서 개발중인 이 게임은 마블 코믹스의 세계관을 배경으로 하고 있으면, 유저는 마블 히어로가 되어서 코스믹 큐브의 힘을 악용하려는 닥터 둠을 저지해야 하는것이 전체적인 내용입니다.









게임에서 선택할수 있는 캐릭터는 아이언맨, 헐크, 울버린, 캡틴 아메리카, 스파이더맨등 다양한 캐릭터가 준비중인 것으로 보이며 방식은 핵앤슬래쉬(디아블로3)로 액션성을 강조 하였습니다.

의상의 문제에 있어서 늘 같은 옷만 입는 히어로들의 코스튬을 조금 배려해 준것인지는 모르겠지만, 같은 영웅이라도 스파이더맨의 경우라면 클래식(파랗고 빨간)스타일 혹은 심비오트에게 감염되었던 모습의 블랙슈트의 복장을 할 수 도 있습니다.









전반적인 게임의 스크린샷이나 동영상으로는 타격감이라던가 게임의 진입방식은 잘 알수 없었으나, 액션MMORPG에다가 디아3와 비슷한 조작을 선보일것 같기에 게임방식 역시 디아3와 유사하지 않나라는 추측을 하게 됩니다.









여러 영웅들이 나오고 아직 개발중이긴 하지만 막강한 디아3에 맞서서 나오는 후발주자인 만큼 어느정도 관심을 끌지 사뭇 기대가 되기도 하는데요.

전체적인 스크린샷으로 따로 따로 보는 느낌은 그래픽이 그렇게 뛰어나 보이질 않는다? 라는 생각이 먼저 떠오르는군요. 요즘 국산게임에 너무 눈이 높아져서 인지도 모르겠지만 확실히 완연한 미국형 디자인답다라는 생각이 들면서도 어. 왠지 예전의 온라인 게임의 그래픽 느낌이 나는것도 같습니다.

아직 게임의 베타버전도 공개되지 않은 관계로 섣부른 장담은 하기 어려우나 히어로물을 좋아하는 북미나 유럽에 비해 국내에서는 들여온다 하더라도 디아블로3가 선점하고 있는 국내시장상 지난 사례를 봤을때 성공가능성은 지극히 낮을거라는 예상이 먼저 들었습니다.

그래도 게임이 재미가 있고 뭔가 다른 참신한점이 유저들의 마음을 사로잡는다면 성공할 가능성도 많겠지요.

posted by 프띠버리 2012. 8. 28. 23:07

이번에 소개할 보드게임음 SET 이라는 게임입니다.

제목처럼 멘사에서 추천하는 게임으로 판단력, 집중력, 관찰력, 사고력에 도움이 되는 게임 입니다.

SET은 혼자서도 할수 있고 여러명이서도 할수 있는 게임인데요.

카드 자체만 보면 별다른 내용없이 도형들만 있어서 이게 뭐하는 게임인가 하는 의문이 먼저 들지도 모릅니다. 이 게임의 특징은 특정 조건에 부합하는 3장의 카드를 찾아내어서 SET을 만들어서 가장 많은 카드를 모으는 사람이 이기는 게임입니다.

각 카드는 도형이 그러져 있고 도형들은 테두리만 있는것, 빗금이 쳐진것, 색이 완전히 채워져 있는것으로 구분이 되며 SET이 원하는 조건!

3장의 카드의 개수가 완전히 똑같거나 완전히 다른가?

3장의 카드의 색상이 완전히 똑같거나 완전히 다른가?

3장의 카드의 모양이 완전히 똑같거나 완전히 다른가?

3장의 카드의 내부가 완전히 똑같거나 완전히 다른가?

를 충족하는 3장의 카드를 찾아 내어야 합니다. 색, 모양, 개수, 채워짐등을 보고 판단해서 카드를 자신에게 가져와야 하는것이죠.

이 게임을 하게 되면 대채적으로 SET의 조건을 충족하는 카드를 찾아서 SET이라고 외치며 자신의 앞으로 가져오기 까지는 의외로 게임하는 동안 조용합니다. 아도 카드에 집중을 하게 되다 보니 다른곳에 정신을 쏟기가 힘들기 때문이죠.

위에서 언급한것처럼 SET은 비슷한 도형들의 카드들이 늘어서 있기 때문에 집중해서 보아야 하는 집중력을 길러주고 자신의 눈으로 본 카드들의 조합을 맞추기 위해 관찰력과 판단력이 요구 되는 게임입니다.

주위가 산만한 아이들같이 집중력이 부족한 아이들에게 SET게임을 가르쳐주고 해보게 하는것도 많은 도움이 될거 같습니다. 가격은 2만5천원에서 3만원 사이로 보드게임몰에서 판매가 되고 있는데요, 사는게 부담스럽다면 자체적으로 제작(핸드메이드)해 보는것은 어떨까요?

'게임 > 보드 게임' 카테고리의 다른 글

끊임없이 생각하자. 쿼리도르!  (0) 2012.08.28
추리게임하면 역시 클루!!  (0) 2012.08.28
쉽고 재미있는 로보77!  (0) 2012.08.28
콩을 팔아 돈을 벌자~ 보난자~!  (0) 2012.08.28
보드게임이란?  (0) 2012.07.10
posted by 프띠버리 2012. 8. 28. 23:06

이번 소개할 게임은 쿼리도르라는 게임입니다.

올해의 게임등 다수의 수상경력을 가지고 있는 이 쿼리도르라는 게임은 무척이나 단순한 진행을 가지고 있는 것이 특징인데, 하지만 룰이 단순하다고하여서 얕보면 항상 필패를 면치 못하는 게임이기도 합니다.

단순히 상대방의 진영 라인까지 나의 말을 먼저 보내면 이기게 되는 게임이긴 하지만 자신이 보유하고 있는 방해물을 이용하여 적시 적소에 사용하여 견제를 함으로써 상대방을 자신의 진영까지 멀리 돌아오게 만들어야합니다.

그러다 보니 전체적인 공간의 형태를 파악해야 되고 어떻게 하면 상대방은 멀리 돌아오게 만들고 나는 빠르게 상대방의 진영에 닿을까 하는 고민을 하게 되는 게임입니다.

기본적으로 2명이서 즐기는 게임이지만 최대 4명까지 할수 있는 게임인데요.

4명이서 하게 되면 견제를 어떻게 하느냐에 따라서 누가 이길지 모른다는 미묘한 심리전 또한 즐길만한 거리가 됩니다.





체스나 장기등에 비해 전략적인 면이 한층 약한것 같아 보이기는 하지만 장애물을 설치해서 상대를 방해해야 한다는 점에서 항상 변하는 미로가 생성되기 때문에 나무막대를 이용해 어떻게 막느냐는 판단력또한 중요합니다. 즉, 이 게임의 재미는 바로 상대방의 진로를 어떻게 방해해서 멀리 돌아오게 만드느냐에 있다고 볼 수 있습니다.

공간지각능력과 판단력을 길러주며 지루해하질 않을 만큼의 게임시간을 가지고 있는 만큼 아이들에게 학습교제로서도 좋고 어른들이 즐기기에도 꽤나 즐거운 게임인 만큼 한번쯤은 경험을 해보시라고 권해드리고 싶은 게임입니다.

현제 국내에서 판매하는 곳중에서는 예전부터 그래왔는데 꽤 구하기가 힘든 게임이지만 내용물이 비교적 간단하기에 수제로 한번 만들어서 써봄직하기도 합니다.

굳이 사진들의 퀄리티 만큼 만들지 않더라도 일회용으로 지우개 조각이나 일상의 말이 될만한 것을 2개 정도 준비한후 펜과 종이만 있어도 간단하게 그려서 해보는것도 괜찮지 않나 하네요.

'게임 > 보드 게임' 카테고리의 다른 글

멘사에서 추천하는 보드게임 SET!!  (0) 2012.08.28
추리게임하면 역시 클루!!  (0) 2012.08.28
쉽고 재미있는 로보77!  (0) 2012.08.28
콩을 팔아 돈을 벌자~ 보난자~!  (0) 2012.08.28
보드게임이란?  (0) 2012.07.10
posted by 프띠버리 2012. 8. 28. 23:05

CLUE New Kor

클루 2009년판 : 대저택 살인사건

악몽의 시작

느닷없이 날라온 백만장자의 호화로운 파티 초대장.하지만 여러분을 기다리는 것은 싸늘하게 식은 파티 주최자의 시체입니다.여러분은 대저택의 구석구석을 돌아다니며 누가, 어디서, 무엇으로 주최자를 살해했는지 밝혀내야 합니다.

2009년에 발매된 클루 – 대저택 살인사건은 기존의 만화 같은 캐릭터를 벗어나 새롭게 실사 캐릭터를 도입하여 보다 세련되고 고급스러운 이미지로 바뀌었습니다. 카드와 보드의 디자인 또한 현대적인 감각으로 재무장했을뿐만 아니라 몇가지 요소들을 추가하여 조금더 추리를 하는 재미를 주었습니다.

추가된 내용은

1. 캐릭터마다 게임 중 한 번, 독특한 능력을 사용할 수 있습니다.
2. 22장의 음모 카드가 추가되어 플레이어간의 상호작용이 증가하였습니다.
3. 8장의 미궁 카드로 인해 플레이시간이 1시간 이내로 줄었으며 게임이 끝날 때까지 긴장을 늦출 수

없게 되었습니다.
4. 수영장이 추가되어 게임의 밸런스가 재조정되었습니다.
5. 흉기의 개수가 6개에서 9개로 변경되어 경우의 수가 늘어났습니다.





리메이크전에 비해서 좀더 생각할 거리가 많아졌다는 점에서는 꽤나 환영할만한 부분입니다.

사실 게임이 몇판 반복되다 보면 약간 지루한 감이 느껴질때도 있었거든요.

클루는 게임의 룰은 설명서를 보면 매우 복잡한듯이 느껴지기는 하지만 명제는 무척이나 단순합니다.

누가, 어디서, 무엇으로 살인을 저질렀나라는 정답을 맞추면 되기 때문이죠.

오래전이지만 리메이크전의 게임을 했을때 추리시트지를 이용하여 체크를 했다고 생각했음에도 불구하고 잘못된 체크로 인해서 오답을 내고 게임에서 물러가거나 혹은 다른 사람이 먼저 맞출까봐 조급증에 그만 먼저 답을 내었는데 오답인 경우가 꽤나 많았습니다.

그리고 정답보다는 오답을 내고 정답을 확인하후 룰에 의거하여 아무런 말도 할 수 없는 상태로 게임이 끝날때까지 조용히 지켜보면서 다른 사람이 오답을 낼때 사악한 미소를 짓던 기억들이 꽤나 재미있었다고 기억납니다.

클루의 장점은 일단 차분하게 생각을 정리할수 있는 시간과 판단력에 도움이 되는 게임이지만 어떻게 보면 의외로 추리게임이라는 명성에는 조금 부족함이 있다고 생각이 들기도 하는데요. 일단 주어진 환경(범인, 흉기, 장소)가 정해져 있고 시트지에서는 게임을 진행하면서 그저 상대방의 카드를 확인하여 무엇이 빠져있는가를 찾아내기만 하면 되었기에 누가 먼저 빠진 정답 카드를 맞추는가를 겨루는 게임이었기 때문입니다. 딱히 뭔가 추리를 한다는 느낌이 없었지요.

그런데 2009년판에서는 음모 카드가 추가 되어서 과연 어떻게 바뀌었을지도 아쉽게도 해보질 못해서 잘 모르겠군요. 그럼에도 불구하고 추리게임의 터줏대감자리를 내놓지 않는 클루를 보면 대단한다는 생각도 듭니다.

오히려 제 기억속에서는 인코그니토(INKOGNITO)라는 게임이 추리 게임으로써는 더 재미가 있었습니다. 인코그니토는 다음에 한번 글을 적도록 하겠습니다.

(인코그니토)

클루는 인기가 좋았던 만큼 여러버전이 소개 되었는데 다음과 같습니다.

(심프슨 클루)



(클루 카드)




(해리포터 클루)










(던전앤드래곤스 클루)

클루역시 직접 만들어서 플레이를 할 수 가 있는데요. 클루 카드 버전을 응용한다던지 하는 방식으로 나름 자신의 휴대성에 맞게 만드신분들도 있고 저같은 경우는 간단하게 즐기기 위해 카드로만 이루어지게 만들어 본적도 있습니다. 제가 직접만들었던것을 올리고 싶은데 제작한지 오래되어 자료가 하나도 남아있지 않는게 아쉽네요.

아이들과 혹은 친구들이나 가족과 함께 약간의 머리를 써가면서 즐겨보는게 어떨까요?

※이미지중 심슨클루를 제외한 이미지는 다이브다이스에서 가져왔습니다.

'게임 > 보드 게임' 카테고리의 다른 글

멘사에서 추천하는 보드게임 SET!!  (0) 2012.08.28
끊임없이 생각하자. 쿼리도르!  (0) 2012.08.28
쉽고 재미있는 로보77!  (0) 2012.08.28
콩을 팔아 돈을 벌자~ 보난자~!  (0) 2012.08.28
보드게임이란?  (0) 2012.07.10
posted by 프띠버리 2012. 8. 28. 23:04

로보77(LOBO77)

이보다 간단한 룰은 없다! 라는 명칭을 가진 게임 로보77입니다.

로보77은 단순히 차례대로 돌아가면서 카드를 내려 놓으며 숫자를 더해 가는 게임입니다. 그러다가 숫자의 합이 77을 넘어가거나 11의 배수(22, 33, 44등등)가 되었을때 자신이 가지고 있던 3개의 칩중 하나를 잃어버리게 되고 자신의 칩을 모두 다 잃어버리게 되면 게임에서 탈락하게 됩니다.



단순히 더하기만 하면 재미가 없겠죠? 그래서, 특수카드들이 존재해서 게임을 더욱 재미있게 해줍니다. 다음사람이 2장을 내게 하거나 반대방향으로 돌리기등의 특수카드들이 존재하죠.

게임은 상당히 빠른시간내에 끝이나는데 이 게임의 특징 카드를 내려 놓으며 더해가는것인데요. 이 더하기로 인해서 아이들의 암기와 수리능력에 큰 도움을 줍니다.



게임진행상 항상 더한 숫자를 암기하고 있어야 하고 자신의 차례에 카드를 내려 놓을때 자신의 숫자를 합한 수를 외치면서 내려놓아야 하기 때문이죠. 쉽고 간단하며 빠른 진행으로 인해서 아이들이 무척이나 좋아하는 게임중 하나입니다.

포스팅을 하면서 글을 좀더 길게 쓰고 싶었지만 게임특성상 어째 길게 쓰기가 힘드네요.

다음에는 좀더 알찬 글로 포스팅을 하도록 하겠습니다.