+ 3
Post a link to your code. It will clarify much better, where you're at, and how to help you. Assuming you have a card object something like this: let ip001 = {name: "card1", attack: 7} Then you can refer to its properties with dot notation: ip001.name ip001.attack
26th Jul 2023, 11:51 AM
Tibor Santa
Tibor Santa - avatar
+ 3
You already have the player hands represented as global arrays. Now you only need one more piece of data: which card in the hand is selected. This would be the index number of the card, or null when nothing is selected. You can pass the card object to your displaying functions, rather than passing individual properties.
26th Jul 2023, 12:14 PM
Tibor Santa
Tibor Santa - avatar
+ 2
I still do not really understand your UI and your game mechanics, at least what you are trying to do with the cards. Currently the card names are printed to console log. But I suppose you want to display all cards on the board (in the HTML code) somehow, maybe as DIV's. I think you should work on this part first. Of course you can add these elements to the DOM when the game is started and the cards are dealt. https://www.w3schools.com/jsref/met_node_appendchild.asp Then you can add onclick action to each card, through event listeners. Here you would put a function with the right parameters for the specific card. https://www.w3schools.com/jsref/met_element_addeventlistener.asp Throughout the game I guess the player will use the cards, so the hand array will eventually change. I would actually pass the card object as a parameter to your display function. cardContainer.addEventListener( "click", () => { displayCardInfo(thisCard); } );
27th Jul 2023, 3:29 AM
Tibor Santa
Tibor Santa - avatar