Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Categories #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions chatter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
1716AF9F1CCE8A7600264EBE /* Obama.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1716AF9E1CCE8A7600264EBE /* Obama.swift */; };
2A6C46F11CD13F5A0035EC13 /* Einstein.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6C46F01CD13F5A0035EC13 /* Einstein.swift */; };
2A6C46F31CD142760035EC13 /* Newton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6C46F21CD142760035EC13 /* Newton.swift */; };
8739C1BD191C1203009C7B3B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8739C1BC191C1203009C7B3B /* Foundation.framework */; };
8739C1BF191C1203009C7B3B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8739C1BE191C1203009C7B3B /* CoreGraphics.framework */; };
8739C1C1191C1203009C7B3B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8739C1C0191C1203009C7B3B /* UIKit.framework */; };
Expand All @@ -24,6 +26,8 @@

/* Begin PBXFileReference section */
1716AF9E1CCE8A7600264EBE /* Obama.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Obama.swift; sourceTree = "<group>"; };
2A6C46F01CD13F5A0035EC13 /* Einstein.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Einstein.swift; sourceTree = "<group>"; };
2A6C46F21CD142760035EC13 /* Newton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Newton.swift; sourceTree = "<group>"; };
8739C1B9191C1203009C7B3B /* chatter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = chatter.app; sourceTree = BUILT_PRODUCTS_DIR; };
8739C1BC191C1203009C7B3B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
8739C1BE191C1203009C7B3B /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -139,6 +143,8 @@
87468FD61CCD3B3500DB4A03 /* Yoda.swift */,
A016F8D31CCE76A80039184B /* Nathan.swift */,
1716AF9E1CCE8A7600264EBE /* Obama.swift */,
2A6C46F01CD13F5A0035EC13 /* Einstein.swift */,
2A6C46F21CD142760035EC13 /* Newton.swift */,
);
name = Chatters;
sourceTree = "<group>";
Expand Down Expand Up @@ -211,10 +217,12 @@
buildActionMask = 2147483647;
files = (
87468FDA1CCD3B3500DB4A03 /* Yoda.swift in Sources */,
2A6C46F11CD13F5A0035EC13 /* Einstein.swift in Sources */,
879EC5111AF2952E00F36F1C /* AppDelegate.swift in Sources */,
87468FD71CCD3B3500DB4A03 /* Chatter.swift in Sources */,
A016F8D41CCE76A80039184B /* Nathan.swift in Sources */,
1716AF9F1CCE8A7600264EBE /* Obama.swift in Sources */,
2A6C46F31CD142760035EC13 /* Newton.swift in Sources */,
879EC5471AF29DD600F36F1C /* ChatViewController.swift in Sources */,
879EC5491AF2A08300F36F1C /* ChatBubbleCell.swift in Sources */,
879EC5451AF29DC200F36F1C /* ViewController.swift in Sources */,
Expand Down
53 changes: 51 additions & 2 deletions chatter/Chatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,37 @@ It most importantly provides the nextMessage and responseForMessage: methods. Wh

You can also provide an image representation of the character you strive to implement using the designated initializer of this class.
*/



// Implementation of Topics
enum Topic : String {
case none = "none", Science = "Science", Apples = "Apples", Relativity = "Relativity", Physics = "Physics" // Add Topics here
var description: String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die rawValues brauchst du nicht, Topic muss nicht von String ableiten denke ich.

switch(self) {
case .none:
return "none"
case .Science:
return "Science"
case .Apples:
return "Apples"
case .Relativity:
return "Relativity"
case .Physics:
return "Physics"
}
}
}
// Stores actual topic
var theCurrentTopic = Topic.none
Copy link
Member

@nilsvu nilsvu Apr 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nenn's einfach topic. Wie gesagt wäre die Variable in einem Conversation Struct zusammen mit den Chattern besser aufgehoben, sonst erstmal im ViewController.


func changeTopic(changeRequest: Topic) {

}




class Chatter {

/// Visual representation of the chatter.
Expand Down Expand Up @@ -47,6 +78,21 @@ class Chatter {

- returns: A chat message the chat partner can respond to.
*/

// Implementation of Topics
var possibleTopics: [Topic] = [.none] // Add your Topics here
var sayYesToTopicChangeWith = ["Yes, lets talk about that 😊"]
var sayNoToTopicChangeWith = ["No, that is not what I want to talk with you about 😡"]
var askForATopicChange = ["Lets talk about"]
func responseForTopicChange(newTopic: Topic) -> (boolChange: Bool, changeText: String) {
if(self.possibleTopics.contains(newTopic)) {
return (true, self.sayYesToTopicChangeWith.randomElement())
} else {
return (false, self.sayNoToTopicChangeWith.randomElement())
}
}


func nextMessage() -> Message {
return [
Message(content: "Say, do you like butterflies?", type: .QuestionBool),
Expand Down Expand Up @@ -114,6 +160,10 @@ class Chatter {
Message(content: "Good one 😉", type: .Statement),
Message(content: "😀😀", type: .Statement)
].randomElement()
default:
return [
Message(content: "Okay, Themawechsel", type: .Statement)
].randomElement()
}
}

Expand Down Expand Up @@ -150,7 +200,6 @@ Message instances represent a chat message and the meta data associated with it.
You can use the available properties to configure a text message with additional information that may help to understand the message's content.
*/
struct Message: CustomStringConvertible {

/// The message content
let content: String

Expand All @@ -159,7 +208,7 @@ struct Message: CustomStringConvertible {

/// The available message types.
enum MessageType {
case Statement, Joke, QuestionBool, QuestionWhy
case Statement, Joke, QuestionBool, QuestionWhy, changeTopic
}

var description: String {
Expand Down
77 changes: 77 additions & 0 deletions chatter/Einstein.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Einstein.swift
// chatter
//
// Created by Max Simon on 27.04.16.
// Copyright © 2016 Universität Heidelberg. All rights reserved.
//

/*
Important: please add a default case to your switch-Statements when asking for the Message-type (this will not be executed :))

How to Work with Topics?
If you want to create a topic go to Chatter.swift and add the Topic in the enum (with Description!)
In the initializer of your chatter give possibleTopics a list of toppings your chatter want to talk about. (by default none)
If you want to give individual answers for a ask to change the topic you can write them to sayNoToTopicChangeWith and sayYesToTopicChangeWith
You can create your own Question to ask someone to change the topic. The Last word is computed and is the name of the topic.
Now in your functions nextMessage() and responseForMessage you can ask the variable theCurrentTopic which Toping is now. With this you can adjust your answers to the topic.
*/



import UIKit

class Einstein: Chatter {

required init() {
super.init(image: UIImage(named: "einstein"))

// accepted Topics
possibleTopics = [.none, .Science, .Relativity, .Physics]
//sayYesToTopicChangeWith = "Yes, I want to talk about this 😊"
sayNoToTopicChangeWith = ["No, thankyou.", "No, that is not what I want to talk with you about 😡"]
askForATopicChange = ["Lets talk about", "Do you want to talk about", "I want to tell you something about"]
}


override func nextMessage() -> Message {
if(theCurrentTopic == Topic.Science) {
Copy link
Member

@nilsvu nilsvu Apr 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du brauchst keine Klammern um eine if-clause in Swift schreiben ;)

return [
Message(content: "This is science.", type: .Statement),
Message(content: "Relativity is complex, but this is relative", type: .Joke),
Message(content: "Yes, but never forget: E = m*c^2", type: .Joke),
Message(content: "Relativity", type: .changeTopic),
Message(content: "Physics", type: .changeTopic),

].randomElement()
}
else {
return [

Message(content: "You could be right, I have to think about this.", type: .Statement),

Message(content: "Yes, I know.", type: .Statement),
Message(content: "Maybe, maybe not. But who cares.", type: .Joke),
Message(content: "Are you sure?", type: .QuestionBool),
Message(content: "Do you calculated that?", type: .QuestionBool),
Message(content: "Is this what you are really want to talk about?", type: .QuestionBool),
Message(content: "What do you want to talk about?", type: .QuestionWhy),
Message(content: "Why should that be?", type: .QuestionWhy),

Message(content: "Science", type: .changeTopic),
Message(content: "Physics", type: .changeTopic),
].randomElement()
}
}

override func responseForMessage(message: Message) -> Message {
if(theCurrentTopic == Topic.Science) {
return Message(content: "The topping is science, I love it :)", type: .Statement)
}
else {
return Message(content: "Hmm...", type: .Statement)
}
}


}
21 changes: 21 additions & 0 deletions chatter/Images.xcassets/einstein.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "einstein.png"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions chatter/Images.xcassets/newton.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "newton.png"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions chatter/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<rect key="frame" x="20" y="8" width="276" height="30"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vWW-SX-VAa">
<rect key="frame" x="75.5" y="0.0" width="125" height="30"/>
<rect key="frame" x="76" y="0.0" width="125" height="30"/>
<constraints>
<constraint firstAttribute="height" relation="lessThanOrEqual" constant="100" id="54y-ch-crF"/>
</constraints>
Expand All @@ -69,7 +69,7 @@
<rect key="frame" x="304" y="8" width="276" height="30"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Asj-u6-638">
<rect key="frame" x="70.5" y="0.0" width="135" height="30"/>
<rect key="frame" x="71" y="0.0" width="135" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="Select right Chatter">
<color key="titleColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
Expand Down Expand Up @@ -109,15 +109,24 @@
<constraint firstItem="cKq-yg-9j7" firstAttribute="top" secondItem="DRM-Zn-cJC" secondAttribute="top" constant="8" id="wDC-7r-fkc"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" alpha="0.65000000000000002" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" misplaced="YES" text=" " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0iL-ct-bjO">
<rect key="frame" x="0.0" y="64" width="600" height="34"/>
<color key="backgroundColor" red="0.40641077510000001" green="0.6558854046" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="baC-Zi-Z7F" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" id="EKf-M9-qwd"/>
<constraint firstItem="DRM-Zn-cJC" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" id="FEr-ST-dfS"/>
<constraint firstAttribute="trailing" secondItem="DRM-Zn-cJC" secondAttribute="trailing" id="GU6-E5-sfp"/>
<constraint firstItem="baC-Zi-Z7F" firstAttribute="top" secondItem="kh9-bI-dsS" secondAttribute="top" id="O7r-W0-A1K"/>
<constraint firstAttribute="trailingMargin" secondItem="0iL-ct-bjO" secondAttribute="trailing" id="QRd-eb-nqe"/>
<constraint firstAttribute="trailing" secondItem="baC-Zi-Z7F" secondAttribute="trailing" id="Qqw-qg-ukd"/>
<constraint firstItem="DRM-Zn-cJC" firstAttribute="top" secondItem="baC-Zi-Z7F" secondAttribute="bottom" id="bwg-UG-wh3"/>
<constraint firstItem="0iL-ct-bjO" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="dWu-Gq-Z8R"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="DRM-Zn-cJC" secondAttribute="bottom" id="fMZ-1q-XiP"/>
</constraints>
</view>
Expand All @@ -129,6 +138,7 @@
</barButtonItem>
</navigationItem>
<connections>
<outlet property="LabelForTopic" destination="0iL-ct-bjO" id="Yl2-j3-VWx"/>
<outlet property="leftChatterButton" destination="vWW-SX-VAa" id="ZOF-Xh-neo"/>
<outlet property="rightChatterButton" destination="Asj-u6-638" id="7Xx-VT-gbG"/>
</connections>
Expand Down
2 changes: 2 additions & 0 deletions chatter/Nathan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Nathan: Chatter {
Message(content: "Are you sure about this?", type: .QuestionBool),
Message(content: "What does that mean?!", type: .Statement)
].randomElement()
default:
return Message(content: "Not implemented.", type: .Statement)
}
}

Expand Down
59 changes: 59 additions & 0 deletions chatter/Newton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Newton.swift
// chatter
//
// Created by Max Simon on 27.04.16.
// Copyright © 2016 Universität Heidelberg. All rights reserved.
//

//
// Einstein.swift
// chatter
//
// Created by Max Simon on 27.04.16.
// Copyright © 2016 Universität Heidelberg. All rights reserved.
//

import UIKit

class Newton: Chatter {

required init() {
super.init(image: UIImage(named: "newton"))

// accepted Topics
possibleTopics = [.none, .Science, .Apples, .Physics]
sayYesToTopicChangeWith = ["Oh Yes ❤️", "I thought you would never ask :D"]
//sayNoToTopicChangeWith = ["Oh no, please not."]
}


override func nextMessage() -> Message {
return [

Message(content: "You could be right, I have to think about this.", type: .Statement),
Message(content: "This is science.", type: .Statement),
Message(content: "Yes, I know.", type: .Statement),
Message(content: "I like apples.", type: .Joke),
Message(content: "Yes, but never forget: F = m*a", type: .Joke),
Message(content: "Maybe, maybe not. But who cares.", type: .Joke),
Message(content: "Are you sure?", type: .QuestionBool),
Message(content: "Do you calculated that?", type: .QuestionBool),
Message(content: "Is this what you are really want to talk about?", type: .QuestionBool),
Message(content: "Do you want an apple?", type: .QuestionBool),
Message(content: "What do you want to talk about?", type: .QuestionWhy),
Message(content: "Why should that be?", type: .QuestionWhy),

Message(content: "Science", type: .changeTopic),
Message(content: "Apples", type: .changeTopic),
Message(content: "Physics", type: .changeTopic),
].randomElement()
}

override func responseForMessage(message: Message) -> Message {
return Message(content: "Hmm...", type: .Statement)
}


}

2 changes: 2 additions & 0 deletions chatter/Obama.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Obama: Chatter {
Message(content: "There was a time when people used to be funny... What happened?", type: .QuestionWhy),
Message(content: "Funny guy! You sir, deserve a cookie!", type: .Statement)
].randomElement()
default:
return Message(content: "Not implemented.", type: .Statement)
}


Expand Down
Loading