應你的要求,我進一步闡述了你第一個問題的答案。我之前的解決方案的訣竅是,可以使用for循環中的幾行來檢查每個點的沖突,這也是為什么在這樣的情況下使用數組通常更好。 現在,在hard-coded點上使用數組肯定有好處。 let height = 700;let width = 700;let s = 4;let d = 50;let gamestate = 'running';let level = 0;let x = 25;let y = 25;function setup() { createCanvas(width, height);}let dots = [ {y: height / 4, x: 0, s: s, d: d, direction: 'h' }, { y: height / 2, x: 0, s: s, d: d, direction: 'h' }, { y: height / 9, x: 0, s: s, d: d, direction: 'h' }, { x: width / 4, y: 0, s: s, d: d, direction: 'v' }, { x: width / 2, y: 0, s: s, d: d, direction: 'v' }, { x: width / 9, y: 0, s: s, d: d, direction: 'v' },]