Skip to content

Commit c5d31bb

Browse files
committed
second commit
1 parent f47c335 commit c5d31bb

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

src/components/Card/Card.css

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
:root {
2-
--primary-red: #d36e7a;
2+
--primary-red: #b35a65;
3+
--primary-blue: #6989b9;
34
}
45

56
.Card {
67
background-color: white;
78
border-radius: 10px;
89
margin: 15px auto;
9-
padding: 40px;
10+
padding: 20px;
1011
border: 1px solid #eee;
1112
box-shadow: 0 2px 3px #ccc;
1213
width: 100%;
1314
text-align: center;
1415
}
1516

17+
.Card--selected {
18+
background-color: var(--primary-blue);
19+
color:white;
20+
}
21+
1622
.button {
1723
font: inherit;
1824
cursor: pointer;
@@ -31,4 +37,12 @@
3137
.button:hover {
3238
color: white;
3339
background-color: var(--primary-red);
40+
}
41+
42+
.button--currentTurn {
43+
color: var(--primary-blue);
44+
}
45+
46+
.button--currentTurn:hover {
47+
background-color: var(--primary-blue);
3448
}

src/components/Card/Card.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import React from 'react';
22
import './Card.css';
33

4-
const Card = ({ character, onHitCard, isHisTurn, ...props }) => (
5-
<div className="Card">
4+
const Card = ({ character, onHitCard, isHisTurn, onGetPower, isSelected, hasAnyCardBeenSelected, ...props }) => (
5+
<div className={`Card ${isSelected ? 'Card--selected' : ''}`}>
66
<h3>{character.name}</h3>
77
<p>{character.race}</p>
88
<p>Health {character.health}</p>
99
<p>Power {character.power}</p>
10-
<button onClick={onHitCard} disabled={isHisTurn} className="button">Hit Card</button>
10+
{
11+
isHisTurn ?
12+
<button onClick={onGetPower} className="button button--currentTurn">Pick Hitter</button>
13+
:
14+
<button onClick={onHitCard} disabled={!hasAnyCardBeenSelected} className="button">Hit Card</button>
15+
}
1116
</div>
1217
);
1318

src/containers/Board/Board.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ class Board extends Component {
1313
constructor(props) {
1414
super(props)
1515
this.state = {
16-
16+
hitterCardId: null,
17+
hitterCardPower: 0
1718
}
1819
}
1920

2021
handleHit = (isFirstPlayer, id, damage) => {
21-
this.props.onPassTurn()
2222
this.props.onHitCard(isFirstPlayer, id, damage)
23+
this.props.onPassTurn()
24+
this.setState({
25+
hitterCardId: null,
26+
hitterCardPower: 0
27+
})
28+
}
29+
30+
handleGetPower = (hitterCardId, hitterCardPower) => {
31+
this.setState({ hitterCardId: hitterCardId, hitterCardPower: hitterCardPower})
2332
}
2433

2534
render() {
@@ -30,7 +39,10 @@ class Board extends Component {
3039
<Card
3140
key={card.id}
3241
character={card}
33-
onHitCard={() => this.handleHit(this.props.isFirstPlayer, card.id, 20)}
42+
hasAnyCardBeenSelected = {this.state.hitterCardId !== null}
43+
isSelected={card.id === this.state.hitterCardId}
44+
onHitCard={() => this.handleHit(this.props.isFirstPlayer, card.id, this.state.hitterCardPower)}
45+
onGetPower={() => this.handleGetPower(card.id, card.power)}
3446
isHisTurn={this.props.isFirstPlayer}
3547
/>
3648
)
@@ -43,7 +55,10 @@ class Board extends Component {
4355
<Card
4456
key={card.id}
4557
character={card}
46-
onHitCard={() => this.handleHit(this.props.isFirstPlayer, card.id, 20)}
58+
hasAnyCardBeenSelected = {this.state.hitterCardId !== null}
59+
isSelected={card.id === this.state.hitterCardId}
60+
onHitCard={() => this.handleHit(this.props.isFirstPlayer, card.id, this.state.hitterCardPower)}
61+
onGetPower={() => this.handleGetPower(card.id, card.power)}
4762
isHisTurn={!this.props.isFirstPlayer}
4863
/>
4964
)

src/store/reducers/board.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import * as actionTypes from '../actions/actionTypes'
33
const initialState = {
44
player1: {
55
cards: [
6-
{id: 1, name: 'Tranchetemon', race: 'Digimon', health: '150', power: '200'},
7-
{id: 2, name: 'Tranchete Gris', race: 'Mage', health: '75', power: '300'},
8-
{id: 3, name: 'Tranchete Dobby', race: 'Domestic Elf', health: '50', power: '500'},
6+
{id: 1, name: 'Tranchetemon', race: 'Digimon', health: '1300', power: '200'},
7+
{id: 2, name: 'Tranchete Gris', race: 'Mage', health: '1100', power: '300'},
8+
{id: 3, name: 'Tranchete Dobby', race: 'Domestic Elf', health: '1000', power: '500'},
99
]
1010
},
1111
player2: {
1212
cards: [
13-
{id: 4, name: 'Tranchetemon 2', race: 'Digimon', health: '150', power: '200'},
14-
{id: 5, name: 'Tranchete Gris 2', race: 'Mage', health: '75', power: '300'},
15-
{id: 6, name: 'Tranchete Dobby 2', race: 'Domestic Elf', health: '50', power: '500'},
13+
{id: 4, name: 'Tranchetemon 2', race: 'Digimon', health: '1500', power: '200'},
14+
{id: 5, name: 'Tranchete Gris 2', race: 'Mage', health: '1200', power: '300'},
15+
{id: 6, name: 'Tranchete Dobby 2', race: 'Domestic Elf', health: '1000', power: '500'},
1616
]
1717
},
1818
}

0 commit comments

Comments
 (0)