@@ -11,7 +11,7 @@ import { Card, CARD_WIDTH, CARD_HEIGHT, TWEEN_DURATION } from './Card.js';
1111
1212/**
1313 * Table container for displaying cards in the center play area.
14- * Uses a 2x2 quadrant system where each quadrant holds at most one card.
14+ * Uses a 1x4 cell system (1 column, 4 rows) where each cell holds at most one card.
1515 * @extends Container
1616 */
1717export class Table extends Container {
@@ -35,8 +35,8 @@ export class Table extends Container {
3535 maxY : 0
3636 } ;
3737
38- // Track which card is in each quadrant (null = empty)
39- // Layout: [0: top-left , 1: top-right , 2: bottom-left , 3: bottom-right ]
38+ // Track which card is in each cell (null = empty)
39+ // Layout: [0: top, 1: second , 2: third , 3: bottom]
4040 this . _quadrantCards = [ null , null , null , null ] ;
4141
4242 // Debug bounds outline (set alpha to 0 to hide)
@@ -79,33 +79,37 @@ export class Table extends Container {
7979 }
8080
8181 /**
82- * Gets the bounds for a specific quadrant .
83- * @param {number } index - Quadrant index (0-3)
84- * @returns {object } Object with minX, maxX, minY, maxY for the quadrant
82+ * Gets the bounds for a specific cell .
83+ * @param {number } index - Cell index (0-3), from top to bottom
84+ * @returns {object } Object with minX, maxX, minY, maxY for the cell
8585 * @private
8686 */
8787 _getQuadrantBounds ( index ) {
8888 const { minX, maxX, minY, maxY } = this . _bounds ;
89- const midX = ( minX + maxX ) / 2 ;
90- const midY = ( minY + maxY ) / 2 ;
89+ const height = maxY - minY ;
90+ const quarterHeight = height / 4 ;
9191
9292 switch ( index ) {
93- case 0 : // top-left
94- return { minX, maxX : midX , minY, maxY : midY } ;
95- case 1 : // top-right
96- return { minX : midX , maxX, minY, maxY : midY } ;
97- case 2 : // bottom-left
98- return { minX, maxX : midX , minY : midY , maxY } ;
99- case 3 : // bottom-right
100- return { minX : midX , maxX, minY : midY , maxY } ;
93+ case 0 :
94+ // top cell
95+ return { minX, maxX, minY, maxY : minY + quarterHeight } ;
96+ case 1 :
97+ // second cell
98+ return { minX, maxX, minY : minY + quarterHeight , maxY : minY + 2 * quarterHeight } ;
99+ case 2 :
100+ // third cell
101+ return { minX, maxX, minY : minY + 2 * quarterHeight , maxY : minY + 3 * quarterHeight } ;
102+ case 3 :
103+ // bottom cell
104+ return { minX, maxX, minY : minY + 3 * quarterHeight , maxY } ;
101105 default :
102106 return { minX, maxX, minY, maxY } ;
103107 }
104108 }
105109
106110 /**
107- * Gets indices of quadrants that don't have a card.
108- * @returns {number[] } Array of free quadrant indices
111+ * Gets indices of cells that don't have a card.
112+ * @returns {number[] } Array of free cell indices
109113 * @private
110114 */
111115 _getFreeQuadrants ( ) {
@@ -128,7 +132,7 @@ export class Table extends Container {
128132 }
129133
130134 /**
131- * Draws 4 quadrant rectangles for debugging purposes.
135+ * Draws 4 cell rectangles for debugging purposes.
132136 * Shows the area where card centers can be placed.
133137 * @private
134138 */
@@ -143,7 +147,7 @@ export class Table extends Container {
143147 }
144148
145149 /**
146- * Repositions all cards to stay within their quadrant bounds after resize.
150+ * Repositions all cards to stay within their cell bounds after resize.
147151 * @private
148152 */
149153 _repositionCards ( ) {
@@ -160,43 +164,40 @@ export class Table extends Container {
160164 }
161165
162166 /**
163- * Adds a card to the table in a random free quadrant .
167+ * Adds a card to the table in the first free cell (top to bottom order) .
164168 * @param {object } spriteSheet - The sprite sheet containing card textures
165169 * @param {string } textureKey - The texture key for the card (e.g., "AS", "KH")
166170 * @param {object|null } startPos - Starting position for animation, or null for initial placement
167171 * @param {number|null } startAngle - Starting angle for animation
168172 * @param {number|null } startAlpha - Starting alpha for animation
169173 * @param {Function|null } clickHandler - Optional click handler callback
170- * @returns {boolean } True if card was added, false if all quadrants are full
174+ * @returns {boolean } True if card was added, false if all cells are full
171175 */
172176 addCard ( spriteSheet , textureKey , startPos , startAngle , startAlpha , clickHandler = null ) {
173- const freeQuadrants = this . _getFreeQuadrants ( ) ;
177+ const freeCells = this . _getFreeQuadrants ( ) ;
174178
175- if ( freeQuadrants . length === 0 ) {
179+ if ( freeCells . length === 0 ) {
176180 return false ;
177181 }
178182
179- // Pick a random free quadrant
180- const quadrantIndex = freeQuadrants [ Math . floor ( Math . random ( ) * freeQuadrants . length ) ] ;
181- const qb = this . _getQuadrantBounds ( quadrantIndex ) ;
183+ // Pick the first free cell (top to bottom order)
184+ const cellIndex = freeCells [ 0 ] ;
185+ const qb = this . _getQuadrantBounds ( cellIndex ) ;
182186
183- // Random position within the quadrant
187+ // Random position within the cell
184188 const x = qb . minX + Math . random ( ) * ( qb . maxX - qb . minX ) ;
185189 const y = qb . minY + Math . random ( ) * ( qb . maxY - qb . minY ) ;
186190
187- // Each card rotates 20 degrees more clockwise than the previous
188- // Starting at -40 degrees for the first card
189- const baseAngle = - 40 + this . _getCardCount ( ) * 20 ;
190- const jitter = Math . random ( ) * 10 - 5 ; // +/- 5 degrees
191- const angle = baseAngle + jitter ;
191+ // Random rotation in range [-20, 20] degrees
192+ const angle = Math . random ( ) * 40 - 20 ;
192193
193194 const card = new Card ( spriteSheet , textureKey , clickHandler , x , y , angle ) ;
194195 card . baseX = x ;
195196 card . baseY = y ;
196197 this . addChild ( card ) ;
197198
198- // Mark quadrant as occupied
199- this . _quadrantCards [ quadrantIndex ] = card ;
199+ // Mark cell as occupied
200+ this . _quadrantCards [ cellIndex ] = card ;
200201
201202 if ( startPos ) {
202203 // Animate card from startPos to target position
@@ -220,11 +221,11 @@ export class Table extends Container {
220221 }
221222
222223 /**
223- * Removes a card from the table and frees its quadrant .
224+ * Removes a card from the table and frees its cell .
224225 * @param {Card } card - The card to remove
225226 */
226227 removeCard ( card ) {
227- // Find which quadrant the card was in and free it
228+ // Find which cell the card was in and free it
228229 for ( let i = 0 ; i < this . _quadrantCards . length ; i ++ ) {
229230 if ( this . _quadrantCards [ i ] === card ) {
230231 this . _quadrantCards [ i ] = null ;
0 commit comments