Mercurial > hg > Members > nobuyasu > Alice > DPPAlice
changeset 5:2db314b1a970
add EatCodeSegment TakeForkCodeSegment, ForkState, Table
author | one |
---|---|
date | Sun, 25 Nov 2012 17:08:21 +0900 |
parents | 2794091a7058 |
children | b59c04a332a1 |
files | src/alice/test/dpp/codesegment/EatCodeSegment.java src/alice/test/dpp/codesegment/TakeForkCodeSegment.java src/alice/test/dpp/model/ForkState.java src/alice/test/dpp/model/Table.java |
diffstat | 4 files changed, 72 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/dpp/codesegment/EatCodeSegment.java Sun Nov 25 17:08:21 2012 +0900 @@ -0,0 +1,18 @@ +package alice.test.dpp.codesegment; + +import alice.codesegment.CodeSegment; +import alice.test.dpp.model.Philosophy; + +public class EatCodeSegment extends CodeSegment { + + Philosophy phil; + public EatCodeSegment(Philosophy p) { + phil = p; + } + + @Override + public void run() { + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/dpp/codesegment/TakeForkCodeSegment.java Sun Nov 25 17:08:21 2012 +0900 @@ -0,0 +1,36 @@ +package alice.test.dpp.codesegment; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.test.dpp.model.Fork; +import alice.test.dpp.model.Philosophy; + +public class TakeForkCodeSegment extends CodeSegment { + + Philosophy phil; + Receiver arg1 = ids.create(CommandType.TAKE); + Receiver arg2 = ids.create(CommandType.TAKE); + + public TakeForkCodeSegment(Philosophy p) { + phil = p; + arg1.setKey(phil.getLeftFork()); + arg2.setKey(phil.getRightFork()); + } + + @Override + public void run() { + System.out.println(phil + " is trying to take the fork."); + Fork leftFork = arg1.asClass(Fork.class); + Fork rightFork = arg2.asClass(Fork.class); + if (leftFork.getFork(phil) && rightFork.getFork(phil) ) { + new EatCodeSegment(phil); + } else { + leftFork.onTheTable(phil); + rightFork.onTheTable(phil); + } + ods.update("local", leftFork.getForkName(), leftFork); + ods.update("local", rightFork.getForkName(), rightFork); + } + +}