Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Martin LOISEAU
QR-Quest
Commits
a2c2c8d0
Commit
a2c2c8d0
authored
Jun 11, 2020
by
Martin LOISEAU
🎄
Browse files
Add atom/node/action base logic
parent
2c8a8f09
Changes
8
Hide whitespace changes
Inline
Side-by-side
project/app/src/main/java/com/example/qrquest/MainActivity.java
View file @
a2c2c8d0
...
...
@@ -8,6 +8,8 @@ import android.media.MediaPlayer;
import
android.os.Build
;
import
android.os.Bundle
;
import
com.example.qrquest.atom.Atom
;
import
com.example.qrquest.node.Node
;
import
com.google.android.gms.common.ConnectionResult
;
import
com.google.android.material.floatingactionbutton.FloatingActionButton
;
import
com.google.android.material.snackbar.Snackbar
;
...
...
@@ -26,14 +28,19 @@ import android.view.Menu;
import
android.view.MenuItem
;
import
android.widget.Toast
;
import
java.util.List
;
import
java.util.Locale
;
public
class
MainActivity
extends
AppCompatActivity
{
MediaPlayer
mp
;
TextToSpeech
tts
;
SpeechRecognizer
sr
;
GoogleApiAvailability
m_gga
;
TTSReader
ttsreader
;
//game logic
public
List
<
Atom
>
Atoms
;
public
List
<
Node
>
OpenNodes
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -41,12 +48,7 @@ public class MainActivity extends AppCompatActivity {
setContentView
(
R
.
layout
.
title_screen
);
Toolbar
toolbar
=
findViewById
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
tts
=
new
TextToSpeech
(
this
,
new
TextToSpeech
.
OnInitListener
()
{
@Override
public
void
onInit
(
int
status
)
{
tts
.
setLanguage
(
Locale
.
FRENCH
);
}
});
ttsreader
=
new
TTSReader
(
this
);
Log
.
d
(
"Debug2"
,
"App launched"
);
m_gga
=
GoogleApiAvailability
.
getInstance
();
...
...
@@ -58,6 +60,18 @@ public class MainActivity extends AppCompatActivity {
}
}
protected
void
CheckOpenNodes
()
{
for
(
Node
n
:
OpenNodes
)
{
if
(
n
.
CheckConditions
(
Atoms
))
{
n
.
Trigger
();
}
}
}
private
void
initializeListeners
()
{
FloatingActionButton
photo
=
findViewById
(
R
.
id
.
photo
);
...
...
@@ -79,7 +93,7 @@ public class MainActivity extends AppCompatActivity {
public
void
onClick
(
View
view
)
{
Snackbar
.
make
(
view
,
"Should read some text out loud using speech synthesis"
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
"Action"
,
null
).
show
();
PlayDemoTTS
(
);
ttsreader
.
PlayTTS
(
"Bonjour"
);
}
});
...
...
@@ -141,15 +155,6 @@ public class MainActivity extends AppCompatActivity {
return
true
;
}
public
boolean
PlayDemoTTS
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
tts
.
speak
(
"Bonjour et bienvenue dans QR Quest"
,
TextToSpeech
.
QUEUE_FLUSH
,
null
,
null
);
}
else
{
tts
.
speak
(
"Bonjour et bienvenue dans QR Quest"
,
TextToSpeech
.
QUEUE_FLUSH
,
null
);
}
return
true
;
}
public
boolean
DemoListener
()
{
requestRecordAudioPermission
();
...
...
project/app/src/main/java/com/example/qrquest/TTSReader.java
0 → 100644
View file @
a2c2c8d0
package
com.example.qrquest
;
import
android.content.Context
;
import
android.os.Build
;
import
android.speech.tts.TextToSpeech
;
import
java.util.Locale
;
public
final
class
TTSReader
{
// basically a static class
final
TextToSpeech
tts
;
public
TTSReader
(
Context
context
)
{
tts
=
new
TextToSpeech
(
context
,
new
TextToSpeech
.
OnInitListener
()
{
@Override
public
void
onInit
(
int
status
)
{
tts
.
setLanguage
(
Locale
.
FRENCH
);
}
});
}
public
boolean
PlayTTS
(
String
TextToPlay
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
tts
.
speak
(
TextToPlay
,
TextToSpeech
.
QUEUE_FLUSH
,
null
,
null
);
}
else
{
tts
.
speak
(
TextToPlay
,
TextToSpeech
.
QUEUE_FLUSH
,
null
);
}
return
true
;
}
}
project/app/src/main/java/com/example/qrquest/actions/Action.java
0 → 100644
View file @
a2c2c8d0
package
com.example.qrquest.actions
;
public
abstract
class
Action
{
public
void
Do
()
{
throw
new
Error
(
"Do() Method from action was not overriden"
);
}
}
project/app/src/main/java/com/example/qrquest/actions/TTSReading.java
0 → 100644
View file @
a2c2c8d0
package
com.example.qrquest.actions
;
import
android.speech.tts.TextToSpeech
;
public
class
TTSReading
extends
Action
{
TextToSpeech
tts
;
private
String
TextToRead
;
public
TTSReading
(
String
TextToRead
)
{
this
.
TextToRead
=
TextToRead
;
}
public
void
Do
()
{
// read TextToRead
}
}
project/app/src/main/java/com/example/qrquest/atom/Atom.java
0 → 100644
View file @
a2c2c8d0
package
com.example.qrquest.atom
;
public
abstract
class
Atom
{
/*
* Représente un item débloqué par le joueur
* Une certaine combinaison d'atome peut permettre de déclencher les actions d'un noeud ouvert
*/
}
project/app/src/main/java/com/example/qrquest/atom/QRAtom.java
0 → 100644
View file @
a2c2c8d0
package
com.example.qrquest.atom
;
public
class
QRAtom
extends
Atom
{
public
String
AtomContent
;
}
project/app/src/main/java/com/example/qrquest/atom/SpeechAtom.java
0 → 100644
View file @
a2c2c8d0
package
com.example.qrquest.atom
;
public
class
SpeechAtom
extends
Atom
{
}
project/app/src/main/java/com/example/qrquest/node/Node.java
0 → 100644
View file @
a2c2c8d0
package
com.example.qrquest.node
;
import
com.example.qrquest.actions.Action
;
import
com.example.qrquest.atom.Atom
;
import
java.util.List
;
public
class
Node
{
/*
* A node is a potential series of actions for the player to do.
* It triggers when the player has gathered every required atoms
*/
public
List
<
Action
>
Actions
;
public
List
<
Atom
>
Conditions
;
public
int
ID
;
public
boolean
CheckConditions
(
List
<
Atom
>
AvailableAtoms
)
{
List
<
Atom
>
UnresolvedConditions
=
Conditions
;
// will be empty at the end if every requirement is met
for
(
Atom
a:
AvailableAtoms
)
{
if
(
UnresolvedConditions
.
contains
(
a
))
UnresolvedConditions
.
remove
(
a
);
}
return
(
UnresolvedConditions
.
size
()
==
0
);
}
public
void
Trigger
()
{
for
(
Action
a:
Actions
)
{
a
.
Do
();
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment