Commit a2c2c8d0 authored by Martin LOISEAU's avatar Martin LOISEAU 🎄
Browse files

Add atom/node/action base logic

parent 2c8a8f09
......@@ -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();
......
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;
}
}
package com.example.qrquest.actions;
public abstract class Action {
public void Do()
{
throw new Error("Do() Method from action was not overriden");
}
}
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
}
}
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
*/
}
package com.example.qrquest.atom;
public class QRAtom extends Atom {
public String AtomContent;
}
package com.example.qrquest.atom;
public class SpeechAtom extends Atom {
}
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();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment