ฉันกำลังสร้างเกม และต้องใช้สี่เหลี่ยมจำนวนไม่สิ้นสุด ตัวอย่างเช่น สมมติว่าฉันตั้งชื่อตัวแปรว่า car:
public Rectangle car1;
public Rectangle car2;
public Rectangle car3;
และอื่นๆ
จะมีวิธีที่ง่ายกว่านี้ไหม? ชอบ:
public int carNumber;
public Rectange car + carNumber;//if carNumber was one, it would be called car1
นอกจากนี้ ฉันจะต้องทดสอบว่าสี่เหลี่ยมนั้นมีอย่างอื่นด้วยหรือไม่ ‹-- ฉันรู้วิธีการทำเช่นนี้