Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ViceMarauder committed Jan 31, 2022
1 parent be97ae9 commit f59fee2
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 68 deletions.
13 changes: 10 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="destini_challenge_starting"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -28,12 +28,19 @@
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />
<!-- Theme to apply as soon as Flutter begins rendering frames -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package co.appbrewery.destinichallengestarting;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
}
5 changes: 3 additions & 2 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
13 changes: 13 additions & 0 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\Users\Chirayu Pant\src\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\Chirayu Pant\Desktop\Codes\Flutter\destini-challenge-starting"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
63 changes: 47 additions & 16 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'story_brain.dart';

// ignore: todo
//TODO: Step 15 - Run the app and see if you can see the screen update with the first story. Delete this TODO if it looks as you expected.

void main() => runApp(Destini());
Expand All @@ -13,7 +15,9 @@ class Destini extends StatelessWidget {
}
}

// ignore: todo
//TODO: Step 9 - Create a new storyBrain object from the StoryBrain class.
StoryBrain storyBrain = StoryBrain();

class StoryPage extends StatefulWidget {
_StoryPageState createState() => _StoryPageState();
Expand All @@ -24,7 +28,12 @@ class _StoryPageState extends State<StoryPage> {
Widget build(BuildContext context) {
return Scaffold(
body: Container(
//TODO: Step 1 - Add background.png to this Container as a background image.
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/background.png'),
fit: BoxFit.fill,
),
),
padding: EdgeInsets.symmetric(vertical: 50.0, horizontal: 15.0),
constraints: BoxConstraints.expand(),
child: SafeArea(
Expand All @@ -35,8 +44,9 @@ class _StoryPageState extends State<StoryPage> {
flex: 12,
child: Center(
child: Text(
// ignore: todo
//TODO: Step 10 - use the storyBrain to get the first story title and display it in this Text Widget.
'Story text will go here.',
storyBrain.getStory(),
style: TextStyle(
fontSize: 25.0,
),
Expand All @@ -45,17 +55,25 @@ class _StoryPageState extends State<StoryPage> {
),
Expanded(
flex: 2,
child: FlatButton(
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.red,
),
onPressed: () {
//Choice 1 made by user.
// ignore: todo
//TODO: Step 18 - Call the nextStory() method from storyBrain and pass the number 1 as the choice made by the user.
setState(() {
storyBrain.nextStory(1);
});
},
color: Colors.red,
child: Text(
// ignore: todo
//TODO: Step 13 - Use the storyBrain to get the text for choice 1.
'Choice 1',
storyBrain.getChoice1(),
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
),
Expand All @@ -65,19 +83,32 @@ class _StoryPageState extends State<StoryPage> {
),
Expanded(
flex: 2,
// ignore: todo
//TODO: Step 26 - Use a Flutter Visibility Widget to wrap this FlatButton.
// ignore: todo
//TODO: Step 28 - Set the "visible" property of the Visibility Widget to equal the output from the buttonShouldBeVisible() method in the storyBrain.
child: FlatButton(
onPressed: () {
//Choice 2 made by user.
//TODO: Step 19 - Call the nextStory() method from storyBrain and pass the number 2 as the choice made by the user.
},
color: Colors.blue,
child: Text(
//TODO: Step 14 - Use the storyBrain to get the text for choice 2.
'Choice 2',
style: TextStyle(
fontSize: 20.0,
child: Visibility(
visible: storyBrain.buttonShouldBeVisible(),
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.blue,
),
onPressed: () {
//Choice 2 made by user.
// ignore: todo
//TODO: Step 19 - Call the nextStory() method from storyBrain and pass the number 2 as the choice made by the user.
setState(() {
storyBrain.nextStory(2);
});
},
child: Text(
// ignore: todo
//TODO: Step 14 - Use the storyBrain to get the text for choice 2.
storyBrain.getChoice2(),
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
),
),
Expand Down
11 changes: 9 additions & 2 deletions lib/story.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// ignore: todo
//TODO: Step 2 - Create a new class called Story.

class Story{
// ignore: todo
//TODO: Step 3 - Create 3 properties for this class, A. storyTitle to store the story text. B. choice1 to store the text for choice 1, C. choice2 to store the text for choice 2.

String storyTitle;
String choice1;
String choice2;
// ignore: todo
//TODO: Step 4 - Create a Constructor for this class to be able to initialise the properties created in step 3.
Story({this.storyTitle,this.choice1,this.choice2});
}
129 changes: 94 additions & 35 deletions lib/story_brain.dart
Original file line number Diff line number Diff line change
@@ -1,59 +1,118 @@
// ignore: todo
//TODO: Step 6 - import the story.dart file into this file.
import 'story.dart';

// ignore: todo
//TODO: Step 5 - Create a new class called StoryBrain.
class StoryBrain{

// ignore: todo
//TODO: Step 7 - Uncomment the lines below to include storyData as a private property in StoryBrain. Hint: You might need to change something in story.dart to make this work.

//List<Story> _storyData = [
// Story(
// storyTitle:
// 'Your car has blown a tire on a winding road in the middle of nowhere with no cell phone reception. You decide to hitchhike. A rusty pickup truck rumbles to a stop next to you. A man with a wide brimmed hat with soulless eyes opens the passenger door for you and asks: "Need a ride, boy?".',
// choice1: 'I\'ll hop in. Thanks for the help!',
// choice2: 'Better ask him if he\'s a murderer first.'),
// Story(
// storyTitle: 'He nods slowly, unphased by the question.',
// choice1: 'At least he\'s honest. I\'ll climb in.',
// choice2: 'Wait, I know how to change a tire.'),
// Story(
// storyTitle:
// 'As you begin to drive, the stranger starts talking about his relationship with his mother. He gets angrier and angrier by the minute. He asks you to open the glovebox. Inside you find a bloody knife, two severed fingers, and a cassette tape of Elton John. He reaches for the glove box.',
// choice1: 'I love Elton John! Hand him the cassette tape.',
// choice2: 'It\'s him or me! You take the knife and stab him.'),
// Story(
// storyTitle:
// 'What? Such a cop out! Did you know traffic accidents are the second leading cause of accidental death for most adult age groups?',
// choice1: 'Restart',
// choice2: ''),
// Story(
// storyTitle:
// 'As you smash through the guardrail and careen towards the jagged rocks below you reflect on the dubious wisdom of stabbing someone while they are driving a car you are in.',
// choice1: 'Restart',
// choice2: ''),
// Story(
// storyTitle:
// 'You bond with the murderer while crooning verses of "Can you feel the love tonight". He drops you off at the next town. Before you go he asks you if you know any good places to dump bodies. You reply: "Try the pier".',
// choice1: 'Restart',
// choice2: '')
//];
List<Story> _storyData = [
Story(
storyTitle:
'Your car has blown a tire on a winding road in the middle of nowhere with no cell phone reception. You decide to hitchhike. A rusty pickup truck rumbles to a stop next to you. A man with a wide brimmed hat with soulless eyes opens the passenger door for you and asks: "Need a ride, boy?".',
choice1: 'I\'ll hop in. Thanks for the help!',
choice2: 'Better ask him if he\'s a murderer first.'),
Story(
storyTitle: 'He nods slowly, unphased by the question.',
choice1: 'At least he\'s honest. I\'ll climb in.',
choice2: 'Wait, I know how to change a tire.'),
Story(
storyTitle:
'As you begin to drive, the stranger starts talking about his relationship with his mother. He gets angrier and angrier by the minute. He asks you to open the glovebox. Inside you find a bloody knife, two severed fingers, and a cassette tape of Elton John. He reaches for the glove box.',
choice1: 'I love Elton John! Hand him the cassette tape.',
choice2: 'It\'s him or me! You take the knife and stab him.'),
Story(
storyTitle:
'What? Such a cop out! Did you know traffic accidents are the second leading cause of accidental death for most adult age groups?',
choice1: 'Restart',
choice2: ''),
Story(
storyTitle:
'As you smash through the guardrail and careen towards the jagged rocks below you reflect on the dubious wisdom of stabbing someone while they are driving a car you are in.',
choice1: 'Restart',
choice2: ''),
Story(
storyTitle:
'You bond with the murderer while crooning verses of "Can you feel the love tonight". He drops you off at the next town. Before you go he asks you if you know any good places to dump bodies. You reply: "Try the pier".',
choice1: 'Restart',
choice2: '')
];

// ignore: todo
//TODO: Step 23 - Use the storyNumber property inside getStory(), getChoice1() and getChoice2() so that it gets the updated story and choices rather than always just the first (0th) one.

// ignore: todo
//TODO: Step 8 - Create a method called getStory() that returns the first storyTitle from _storyData.
String getStory(){
return _storyData[_storyNumber].storyTitle;
}

// ignore: todo
//TODO: Step 11 - Create a method called getChoice1() that returns the text for the first choice1 from _storyData.
String getChoice1(){
return _storyData[_storyNumber].choice1;
}

// ignore: todo
//TODO: Step 12 - Create a method called getChoice2() that returns the text for the first choice2 from _storyData.
String getChoice2(){
return _storyData[_storyNumber].choice2;
}

// ignore: todo
//TODO: Step 25 - Change the storyNumber property into a private property so that only story_brain.dart has access to it. You can do this by right clicking on the name (storyNumber) and selecting Refactor -> Rename to make the change across all the places where it's used.

// ignore: todo
//TODO: Step 16 - Create a property called storyNumber which starts with a value of 0. This will be used to track which story the user is currently viewing.

int _storyNumber = 0;
void restart(){
_storyNumber = 0;
}
// ignore: todo
//TODO: Step 17 - Create a method called nextStory(), it should not have any outputs but it should have 1 input called choiceNumber which will be the choice number (int) made by the user.
void nextStory(int choiceNumber){
// ignore: todo
//TODO: Step 21 - Using the story plan, update nextStory() to change the storyNumber depending on the choice made by the user. e.g. if choiceNumber was equal to 1 and the storyNumber is 0, the storyNumber should become 2.
if(_storyNumber == 0 && choiceNumber == 1){
_storyNumber = 2;
}
else if(_storyNumber == 0 && choiceNumber == 2){
_storyNumber = 1;
}
else if(_storyNumber == 1 && choiceNumber == 1){
_storyNumber = 2;
}
else if(_storyNumber == 1 && choiceNumber == 2){
_storyNumber = 3;
}
else if(_storyNumber == 2 && choiceNumber == 1){
_storyNumber = 5;
}
else if(_storyNumber == 2 && choiceNumber == 2){
_storyNumber = 4;
}
// ignore: todo
//TODO: Step 22 - In nextStory() if the storyNumber is equal to 3 or 4 or 5, that means it's the end of the game and it should call a method called restart() that resets the storyNumber to 0.
else if(_storyNumber == 3 || _storyNumber == 4 || _storyNumber == 5){
_storyNumber = 0;
}

}
// ignore: todo
//TODO: Step 20 - Download the story plan here: https://drive.google.com/uc?export=download&id=1KU6EghkO9Hf2hRM0756xFHgNaZyGCou3

//TODO: Step 21 - Using the story plan, update nextStory() to change the storyNumber depending on the choice made by the user. e.g. if choiceNumber was equal to 1 and the storyNumber is 0, the storyNumber should become 2.

//TODO: Step 22 - In nextStory() if the storyNumber is equal to 3 or 4 or 5, that means it's the end of the game and it should call a method called restart() that resets the storyNumber to 0.

// ignore: todo
//TODO: Step 27 - Create a method called buttonShouldBeVisible() which checks to see if storyNumber is 0 or 1 or 2 (when both buttons should show choices) and return true if that is the case, else it should return false.
bool buttonShouldBeVisible(){
if(_storyNumber == 0 || _storyNumber == 1 || _storyNumber == 2){
return true;
}
else{
return false;
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
cupertino_icons: ^1.0.4

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit f59fee2

Please sign in to comment.