diff --git a/src/main/java/com/iflytop/a800/device/Incubator.java b/src/main/java/com/iflytop/a800/device/Incubator.java index 5b5f075..7f76020 100644 --- a/src/main/java/com/iflytop/a800/device/Incubator.java +++ b/src/main/java/com/iflytop/a800/device/Incubator.java @@ -9,9 +9,12 @@ import java.util.Map; public class Incubator { // 槽位 private final List slots; + // 槽位起始索引 + private Integer slotStartIndex = 0; // 构造函数 public Incubator() { + this.slotStartIndex = 0; this.slots = new ArrayList<>(); for ( int i = 0; i < 20; i++ ) { var slot = new IncubatorSlot(); @@ -20,14 +23,20 @@ public class Incubator { } } + public void lock() {} + public void unlock() {} + // 推送新卡片 public IncubatorSlot pushNewCard(TestCard card) { IncubatorSlot slot = null; - for ( var s : this.slots ) { - if ( s.card == null ) { - slot = s; - break; + for ( int i=0; i<20; i++ ) { + var tmpSlot = this.slots.get(this.slotStartIndex); + this.slotStartIndex = (this.slotStartIndex + 1) % 20; + if ( tmpSlot.card != null ) { + continue ; } + slot = tmpSlot; + break; } if ( slot == null ) { throw new RuntimeException("无可用孵育盘槽位");