From 766016b89306bf3ba5e4e32d888f3af255aaed00 Mon Sep 17 00:00:00 2001 From: sige Date: Mon, 17 Jun 2024 09:50:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=B5=E8=82=B2=E7=9B=98=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=B5=8B=E8=AF=95=E5=8D=A1=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/iflytop/a800/device/Incubator.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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("无可用孵育盘槽位");