Commit 9f184048 authored by Martin LOISEAU's avatar Martin LOISEAU 🎄
Browse files

Improve logics, begin test implementation

parent 9aef0478
......@@ -8,7 +8,12 @@ import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import com.example.qrquest.actions.Action;
import com.example.qrquest.actions.AddAtom;
import com.example.qrquest.actions.RemoveAtom;
import com.example.qrquest.actions.TTSReading;
import com.example.qrquest.atom.Atom;
import com.example.qrquest.atom.ItemAtom;
import com.example.qrquest.node.Node;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
......@@ -28,6 +33,8 @@ import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
......@@ -39,8 +46,8 @@ public class MainActivity extends AppCompatActivity {
public TTSReader ttsreader;
//game logic
public List<Atom> Atoms;
public List<Node> OpenNodes, EveryNode;
public ArrayList<Atom> Atoms;
public ArrayList<Node> OpenNodes, EveryNode;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -58,6 +65,33 @@ public class MainActivity extends AppCompatActivity {
Dialog errorDia = m_gga.getErrorDialog(this,status, GOOGLE_SERVICES_REQUEST);
errorDia.show();
}
Atoms = new ArrayList<Atom>();
Atoms.add(new ItemAtom(0));
EveryNode = new ArrayList<Node>();
OpenNodes = new ArrayList<Node>();
ArrayList<Action> A1 = new ArrayList<Action>();
A1.add(new AddAtom(this, new ItemAtom(2)));
A1.add(new TTSReading(this, "Test 1"));
A1.add(new RemoveAtom(this, new ItemAtom(0)));
A1.add(new AddAtom(this, new ItemAtom(1)));
ArrayList<Atom> C1 = new ArrayList<Atom>();
C1.add(new ItemAtom(0));
ArrayList<Action> A2 = new ArrayList<Action>();
A1.add(new TTSReading(this, "Test 2"));
ArrayList<Atom> C2 = new ArrayList<Atom>();
C1.add(new ItemAtom(1));
Node n1 = new Node(A1, C1);
Node n2 = new Node(A2, C2);
EveryNode.add(n1);
EveryNode.add(n2);
OpenNodes.add(n1);
CheckOpenNodes();
}
protected void CheckOpenNodes()
......@@ -67,8 +101,8 @@ public class MainActivity extends AppCompatActivity {
if (n.CheckConditions(Atoms))
{
n.Trigger();
CheckOpenNodes();
}
}
}
......
package com.example.qrquest.actions;
import android.util.Log;
import com.example.qrquest.MainActivity;
import com.example.qrquest.atom.Atom;
......@@ -14,6 +16,7 @@ public class AddAtom extends Action {
public void Do()
{
Log.d("Debug2", "Added Atom");
mainActivity.Atoms.add((atom));
}
}
package com.example.qrquest.actions;
import android.util.Log;
import com.example.qrquest.MainActivity;
import com.example.qrquest.node.Node;
......@@ -14,6 +16,7 @@ public class AddNode extends Action {
public void Do()
{
Log.d("Debug2", "Added Node " + node.ID);
mainActivity.OpenNodes.add(node);
}
}
package com.example.qrquest.actions;
import android.util.Log;
import com.example.qrquest.MainActivity;
import com.example.qrquest.atom.Atom;
......@@ -19,6 +21,11 @@ public class RemoveAtom extends Action {
if(atom.isSame(_atom)) atomToRemove = atom;
}
if(atomToRemove != null) mainActivity.Atoms.remove(atomToRemove);
if(atomToRemove != null)
{
Log.d("Debug2", "Removed atom");
mainActivity.Atoms.remove(atomToRemove);
}
else Log.d("Debug2", "Tried to remove an atom that doesn't exist");
}
}
package com.example.qrquest.actions;
import android.util.Log;
import com.example.qrquest.MainActivity;
import com.example.qrquest.node.Node;
......@@ -14,7 +16,7 @@ public class RemoveNode extends Action {
public void Do()
{
if(!mainActivity.OpenNodes.contains(mainActivity.GetNode(_nodeID))) throw new Error("Tried to remove a node that wasn't open");
Log.d("Debug2", "Removed node " + _nodeID);
mainActivity.OpenNodes.remove(mainActivity.GetNode(_nodeID));
}
}
package com.example.qrquest.atom;
public final class ItemAtom {
public final class ItemAtom extends Atom {
int ID;
public ItemAtom(int ID)
......
......@@ -23,8 +23,12 @@ public class Node {
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);
for (Atom a1:AvailableAtoms) {
for(Atom a2:UnresolvedConditions)
{
if(a2.isSame(a1)) UnresolvedConditions.remove(a2);
}
}
return (UnresolvedConditions.size() == 0);
......@@ -35,7 +39,7 @@ public class Node {
for (Action a: Actions
) {
a.Do();
while(!a.isOver{ };
while(!a.isOver){ };
}
}
}
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