Skip to content

Commit

Permalink
Clever lector
Browse files Browse the repository at this point in the history
  • Loading branch information
Pastor committed Oct 6, 2024
1 parent acad68a commit 7f89554
Showing 1 changed file with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public void tick() {
environment.tick();
}

enum Messages implements Transport.Replay {
NOISE, WAT
}

private record Human(String name, Class<? extends Agent> klass) implements Agent.Factory {
public Agent create(Transport transport) {
try {
Expand All @@ -58,7 +62,23 @@ public Optional<Transport.Replay> call(Transport.Message message) {

@Override
public void onEvent(Event event) {
throw new UnsupportedOperationException();
if (event instanceof Event.EventMessage eventMessage
&& eventMessage.message() instanceof Messages message
&& eventMessage.source() != this) {
switch (message) {
case NOISE: {
transport.send(Messages.WAT);
break;
}
case WAT: {
//Skip
break;
}
default: {
break;
}
}
}
}

@Override
Expand All @@ -71,12 +91,31 @@ private record Student(String id, Transport transport) implements Agent {

@Override
public Optional<Transport.Replay> call(Transport.Message message) {
if (message instanceof Messages msg) {
return Optional.empty();
}
return Optional.empty();
}

@Override
public void onEvent(Event event) {
throw new UnsupportedOperationException();
if (event instanceof Event.EventMessage eventMessage
&& eventMessage.message() instanceof Messages message
&& eventMessage.source() != this) {
switch (message) {
case NOISE: {
//Skip
break;
}
case WAT: {
//TODO:
break;
}
default: {
break;
}
}
}
}

@Override
Expand Down

0 comments on commit 7f89554

Please sign in to comment.