Skip to content

Commit

Permalink
Merge pull request #12 from 2jae6/2jae6/liar_subject
Browse files Browse the repository at this point in the history
LiarGame Subject Select View & LiarGame View early Setup
  • Loading branch information
elppaaa committed Apr 26, 2022
2 parents ff0e134 + 7d72cfe commit 7521258
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 8 deletions.
16 changes: 16 additions & 0 deletions LiarGame/Sources/Model/LiarSubjectModel.swift
Original file line number Diff line number Diff line change
@@ -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
}
35 changes: 35 additions & 0 deletions LiarGame/Sources/Reactor/LiarGameSubjectReactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutation> {
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
}
}

}
9 changes: 4 additions & 5 deletions LiarGame/Sources/ViewController/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()


}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}


}
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
2 changes: 1 addition & 1 deletion xcconfig/LiarGame-Shared.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ SWIFT_VERSION = 5.0

TARGETED_DEVICE_FAMILY = 1,2

#include "Secret.xcconfig"
#include "Secret.xcconfig"

0 comments on commit 7521258

Please sign in to comment.