diff --git a/LiarGame/Sources/Model/LiarSubjectModel.swift b/LiarGame/Sources/Model/LiarSubjectModel.swift new file mode 100644 index 0000000..343768f --- /dev/null +++ b/LiarGame/Sources/Model/LiarSubjectModel.swift @@ -0,0 +1,16 @@ +// +// LiarSubjectModel.swift +// LiarGame +// +// Created by Jay on 2022/04/25. +// + +import Foundation + +enum LiarGameSubject{ + case animal + case exercise + case food + case electronicEquipment + case job +} diff --git a/LiarGame/Sources/Reactor/LiarGameSubjectReactor.swift b/LiarGame/Sources/Reactor/LiarGameSubjectReactor.swift index 03ed2d8..0ddf1f8 100644 --- a/LiarGame/Sources/Reactor/LiarGameSubjectReactor.swift +++ b/LiarGame/Sources/Reactor/LiarGameSubjectReactor.swift @@ -6,3 +6,38 @@ // import Foundation +import RxSwift +import RxCocoa +import ReactorKit + + +final class LiarGameSubjectReactor: Reactor{ + enum Action { + case selectSubject(LiarGameSubject) + } + enum Mutation { + case setSubject(LiarGameSubject) + } + struct State { + var selectedSubject: LiarGameSubject? + } + + var initialState = State() + + func mutate(action: Action) -> Observable { + switch action { + case let .selectSubject(subject): + return Observable.just(Mutation.setSubject(subject)) + } + } + + func reduce(state: State, mutation: Mutation) -> State { + switch mutation { + case let .setSubject(subject): + var newState = state + newState.selectedSubject = subject + return newState + } + } + +} diff --git a/LiarGame/Sources/ViewController/HomeViewController.swift b/LiarGame/Sources/ViewController/HomeViewController.swift index 68d385e..bc5d2a1 100644 --- a/LiarGame/Sources/ViewController/HomeViewController.swift +++ b/LiarGame/Sources/ViewController/HomeViewController.swift @@ -45,10 +45,10 @@ final class HomeViewController: UIViewController, View{ self.setupView() } - let flexLayoutContainer: UIView = UIView() + private let flexLayoutContainer: UIView = UIView() var disposeBag: DisposeBag = DisposeBag() - let liarGameStartButton = UIButton() + private let liarGameStartButton = UIButton() } @@ -67,15 +67,14 @@ extension HomeViewController{ // MARK: - Binding extension HomeViewController{ func bind(reactor: Reactor) { - self.liarGameStartButton.rx.tap.asDriver() - .drive(onNext: { + self.liarGameStartButton.rx.tap + .subscribe(onNext:{ reactor.action.onNext(.updateMode("LIAR")) }).disposed(by: disposeBag) reactor.state.map { $0.mode } .subscribe(onNext: { - print($0) if $0 == "LIAR"{ let liarVC = LiarGameModeViewController(reactor: LiarGameModeReactor()) liarVC.modalPresentationStyle = .fullScreen diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameModeViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameModeViewController.swift index ead5eb1..2c6c491 100644 --- a/LiarGame/Sources/ViewController/LiarGame/LiarGameModeViewController.swift +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameModeViewController.swift @@ -100,7 +100,7 @@ extension LiarGameModeViewController{ reactor.state.map { $0.mode } .withUnretained(self) .subscribe(onNext: { `self`, mode in - let liarGameSubjectVC = LiarGameSubjectViewController() + let liarGameSubjectVC = LiarGameSubjectViewController(reactor: LiarGameSubjectReactor() ) liarGameSubjectVC.modalPresentationStyle = .fullScreen self.present(liarGameSubjectVC, animated: true, completion: nil) }).disposed(by: disposeBag) diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift index 1402092..37f01b5 100644 --- a/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameSubjectViewController.swift @@ -6,11 +6,130 @@ // import UIKit +import PinLayout +import FlexLayout +import Then +import ReactorKit -final class LiarGameSubjectViewController: UIViewController{ +final class LiarGameSubjectViewController: UIViewController, View{ + + init(reactor: LiarGameSubjectReactor){ + + super.init(nibName: nil, bundle: nil) + self.reactor = reactor + self.view.addSubview(flexLayoutContainer) + + self.flexLayoutContainer.flex.direction(.row).justifyContent(.center).alignItems(.stretch).wrap(.wrap).define{ flex in + flex.addItem(self.animalButton).width(100).height(25).marginTop(100).margin(10) + flex.addItem(self.exerciseButton).width(100).height(25).marginTop(100).margin(10) + flex.addItem(self.foodButton).width(100).height(25).marginTop(100).margin(10) + flex.addItem(self.electronicEquipmentButton).width(100).height(25).marginTop(10).margin(10) + flex.addItem(self.jobButton).width(100).height(25).marginTop(10).margin(10) + } + } + + @available(*, unavailable) + required init?(coder: NSCoder) { fatalError() } + + override func viewDidLayoutSubviews() { + self.flexLayoutContainer.pin.all() + self.flexLayoutContainer.flex.layout() + } + override func viewDidLoad() { self.view.backgroundColor = .green + self.setupView() + } + + private let flexLayoutContainer: UIView = UIView() + + + var disposeBag: DisposeBag = DisposeBag() + + private let animalButton: UIButton = UIButton() + private let exerciseButton: UIButton = UIButton() + private let foodButton: UIButton = UIButton() + private let electronicEquipmentButton: UIButton = UIButton() + private let jobButton: UIButton = UIButton() + + +} +extension LiarGameSubjectViewController{ + + func setupView(){ + animalButton.do{ + $0.backgroundColor = .yellow + $0.setTitle("동물", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + exerciseButton.do{ + $0.backgroundColor = .yellow + $0.setTitle("운동", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + foodButton.do{ + $0.backgroundColor = .yellow + $0.setTitle("음식", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + electronicEquipmentButton.do{ + $0.backgroundColor = .yellow + $0.setTitle("전자기기", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + jobButton.do{ + $0.backgroundColor = .yellow + $0.setTitle("직업", for: .normal) + $0.setTitleColor(.black, for: .normal) + } + } + + +} +extension LiarGameSubjectViewController{ + + func bind(reactor: LiarGameSubjectReactor) { + animalButton.rx.tap + .subscribe(onNext:{ + reactor.action.onNext(.selectSubject(.animal)) + }).disposed(by: disposeBag) + + exerciseButton.rx.tap + .subscribe(onNext:{ + reactor.action.onNext(.selectSubject(.exercise)) + }).disposed(by: disposeBag) + + + foodButton.rx.tap + .subscribe(onNext:{ + reactor.action.onNext(.selectSubject(.food)) + }).disposed(by: disposeBag) + + electronicEquipmentButton.rx.tap + .subscribe(onNext:{ + reactor.action.onNext(.selectSubject(.electronicEquipment)) + }).disposed(by: disposeBag) + + jobButton.rx.tap.asDriver() + .drive(onNext:{ + reactor.action.onNext(.selectSubject(.job)) + }).disposed(by: disposeBag) + + reactor.state.map{ $0.selectedSubject } + .compactMap{ $0 } + .distinctUntilChanged() + .withUnretained(self) + .subscribe(onNext:{ `self`, subject in + let liarGameVC = LiarGameViewController(subject: subject) + liarGameVC.modalPresentationStyle = .fullScreen + self.present(liarGameVC, animated: true, completion: nil) + + }).disposed(by: disposeBag) + + } + + } diff --git a/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift b/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift new file mode 100644 index 0000000..4897d2b --- /dev/null +++ b/LiarGame/Sources/ViewController/LiarGame/LiarGameViewController.swift @@ -0,0 +1,80 @@ +// +// LiarGameViewController.swift +// LiarGame +// +// Created by Jay on 2022/04/26. +// + +import UIKit +import Then +import RxSwift +import RxCocoa +import ReactorKit +import PinLayout +import FlexLayout + +final class LiarGameViewController: UIViewController{ + + init(subject: LiarGameSubject){ + self.selectSubject = subject + super.init(nibName: nil, bundle: nil) + flexContainer.flex.define{ flex in + flex.addItem(self.curtainView) + + } + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLayoutSubviews() { + self.flexContainer.pin.all() + self.flexContainer.flex.layout() + } + override func viewDidLoad() { + self.view.backgroundColor = .yellow + self.setupView() + } + + private let flexContainer: UIView = UIView() + + private var selectSubject: LiarGameSubject + // 가림막 만들기 가림막은 클릭 시 확인창이 뜸 + private let curtainView: UIView = UIView() + private let curtainLabel: UILabel = UILabel() + private let curtainButton: UIButton = UIButton() + + // 단어 나타나기 화면 만들기 + private let liarView: UIView = UIView() + private let liarLabel: UILabel = UILabel() + private let liarButton: UIButton = UIButton() + + // 게임 시작!!! + private let endView: UIView = UIView() + private let endLabel: UILabel = UILabel() + private let endButton: UIButton = UIButton() + + +} +extension LiarGameViewController{ + + private func setupView(){ +// self.view.addSubview(flexContainer) + + curtainView.do{ + self.view.addSubview($0) + $0.backgroundColor = .yellow + } + + curtainLabel.do{ + self.curtainView.addSubview($0) + $0.backgroundColor = .green + $0.text = "터치해서 가림막을 제거해주세요" + } + curtainButton.do{ + self.curtainView.addSubview($0) + } + } +} diff --git a/xcconfig/LiarGame-Shared.xcconfig b/xcconfig/LiarGame-Shared.xcconfig index 9756fe5..022fe36 100644 --- a/xcconfig/LiarGame-Shared.xcconfig +++ b/xcconfig/LiarGame-Shared.xcconfig @@ -181,4 +181,4 @@ SWIFT_VERSION = 5.0 TARGETED_DEVICE_FAMILY = 1,2 -#include "Secret.xcconfig" \ No newline at end of file +#include "Secret.xcconfig"