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

Add more actions and atom types

parent 85c0c3af
......@@ -40,7 +40,7 @@ public class MainActivity extends AppCompatActivity {
//game logic
public List<Atom> Atoms;
public List<Node> OpenNodes;
public List<Node> OpenNodes, EveryNode;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -72,6 +72,19 @@ public class MainActivity extends AppCompatActivity {
}
}
public Node GetNode(int ID)
{
for (Node n :
EveryNode) {
if (n.ID == ID)
{
return n;
}
}
throw new Error("No existing node has the requested ID.");
}
private void initializeListeners() {
FloatingActionButton photo = findViewById(R.id.photo);
......
package com.example.qrquest.actions;
import com.example.qrquest.MainActivity;
import com.example.qrquest.atom.Atom;
public class RemoveAtom extends Action {
Atom _atom;
public RemoveAtom(MainActivity mainActivity, Atom atom) {
super(mainActivity);
_atom = atom;
}
public void Do()
{
Atom atomToRemove = null;
for (Atom atom: mainActivity.Atoms
) {
if(atom.isSame(_atom)) atomToRemove = atom;
}
if(atomToRemove != null) mainActivity.Atoms.remove(atomToRemove);
}
}
package com.example.qrquest.actions;
import com.example.qrquest.MainActivity;
import com.example.qrquest.node.Node;
public class RemoveNode extends Action {
private int _nodeID;
public RemoveNode(MainActivity mainActivity, int nodeID) {
super(mainActivity);
_nodeID = nodeID;
}
public void Do()
{
if(!mainActivity.OpenNodes.contains(mainActivity.GetNode(_nodeID))) throw new Error("Tried to remove a node that wasn't open");
mainActivity.OpenNodes.remove(mainActivity.GetNode(_nodeID));
}
}
......@@ -5,4 +5,21 @@ 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
*/
public boolean isSame(Atom atom)
{
if(atom.getClass() != this.getClass())
{
return false;
}
else
{
return (hasSameValue(atom));
}
}
public boolean hasSameValue(Atom atom)
{
throw new Error(("has same value should be overriden for every final atom class"));
}
}
package com.example.qrquest.atom;
public final class ItemAtom {
int ID;
public ItemAtom(int ID)
{
this.ID = ID;
}
public boolean hasSameValue(ItemAtom atom)
{
return (atom.ID == ID);
}
}
package com.example.qrquest.atom;
public class QRAtom extends Atom {
public final class QRAtom extends Atom {
public String AtomContent;
public QRAtom(String AtomContent)
{
this.AtomContent = AtomContent;
}
public boolean hasSameValue(QRAtom atom)
{
return (atom.AtomContent == AtomContent);
}
}
package com.example.qrquest.atom;
public class SpeechAtom extends Atom {
public final class SpeechAtom extends Atom {
String AtomContent;
public SpeechAtom(String AtomContent)
{
this.AtomContent = AtomContent;
}
public boolean hasSameValue(QRAtom atom)
{
return (atom.AtomContent == AtomContent);
}
}
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