Skip to content
This repository has been archived by the owner on Oct 2, 2018. It is now read-only.

Making cards with ability require a target-selection #115

Merged
merged 20 commits into from
Apr 24, 2018
Merged

Making cards with ability require a target-selection #115

merged 20 commits into from
Apr 24, 2018

Conversation

Masclins
Copy link
Collaborator

This is the first commit on an attempt to resolve #77.

As I understand, the only thing that should be achieved to solve this Issue is the game requiring a target to be selected when playing a card with an ability. Doing something with that target will be solved by #78.

@Masclins
Copy link
Collaborator Author

Masclins commented Apr 18, 2018

This commit is really wrong, but is the first approach I managed to do for solving the issue.

  1. It uses a lot the status.clickedCard, to the point that dragging cards now give an error.
  2. When clicking owned cards, color stays yellow. It seems the problem is that clicking on an owned card implies also clicking on an owned row.

Any help with this two problems will be appreciated.

@Masclins Masclins changed the title Making cards with ability require a targeet-selection Making cards with ability require a target-selection Apr 18, 2018
@Masclins
Copy link
Collaborator Author

Now the only problem is making the card green when clicking an owned card.

...and, of course, the tests. All the tests...

@@ -40,6 +42,12 @@ module.exports = {
newCard.classList.remove("col-1");
newCard.classList.add("col-2");
newCard.innerHTML = cardData["power"];
newCard.addEventListener('click', function() {
if (status.clickedCard !== undefined &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (status.clickedCard !== undefined)
is equivalent to
if (status.clickedCard)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

newCard.addEventListener('click', function() {
if (status.clickedCard !== undefined &&
status.clickedCard.hasAttribute("row-played")) {
play.playCard(true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wut

Copy link
Collaborator Author

@Masclins Masclins Apr 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I click a card on the board and had already selected and played a card (that is, I have assigned it a row-played I call play.playCard to play status.clickedCard.

The true value can be any anything but undefined right now. When we work on passing a target, this value will be the target.

Copy link
Collaborator

@pernilsalat pernilsalat Apr 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then i feel this true should be in a 'target' variable, and that variable would be set to true for now

newCard.innerHTML += showAddPower(cardInHand["add-power"])
newCard.innerHTML = cardInHand["power"];
newCard.setAttribute("add-power", cardInHand["add-power"]);
newCard.innerHTML += showAddPower(cardInHand["add-power"]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ability add-power is set as an attribute, so we can easily check it for a card.
Maybe this two lines can be simplified.

target: target,
};
document.querySelector('.card[index="'+cardindex+'"]').style.background = "yellow";
playCard(target) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we keep track of the status.clickedCard for marking it and handling abilities, passing the playing info here is redundant.

if (target === undefined &&
status.clickedCard.getAttribute("add-power")) {
status.clickedCard.style.background = "yellow";
} else {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I go ahead with the playing only if the card doesn't have add-power or has a defined target. Otherwise I simply mark the card in yellow.

@Masclins
Copy link
Collaborator Author

Last change solves a bug where clicking on an owned card for playing a card gave a bug, since it has no "rownum" attribute.

Copy link
Owner

@kenan-rhoton kenan-rhoton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the "magic parameter" issue in playCard, it would be nice to include some unit tests for this. I can provide some guidance on how to do that if need be.

target: target,
};
document.querySelector('.card[index="'+cardindex+'"]').style.background = "yellow";
playCard() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this function "magically" getting its info from somewhere that isn't even in the same file (status.clickedCard).

It should take the clicked card as an argument or it will grow unmantainable in the future, as this project grows.

@kenan-rhoton
Copy link
Owner

We need a test that checks that on clicking to play a card with an ability, a target selection is requested.

Copy link
Owner

@kenan-rhoton kenan-rhoton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing, it would be nice if, aside from the card turning yellow, we signalled what the player needs to do in the status with "Select a target"

kenan-rhoton
kenan-rhoton previously approved these changes Apr 24, 2018
@kenan-rhoton
Copy link
Owner

Unit tests are failing 🙃

@kenan-rhoton kenan-rhoton merged commit e4582ed into kenan-rhoton:master Apr 24, 2018
@kenan-rhoton kenan-rhoton deleted the select-target branch April 24, 2018 08:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants