Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play Your Cards Right #6

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2a014cb
project initialised and dependencies installed
joelamb Oct 2, 2018
aadd46c
Google map set up
joelamb Oct 2, 2018
ca8bb26
fetch data, shuffle and deal hands
joelamb Oct 3, 2018
fc370f6
render cards
joelamb Oct 3, 2018
86f165b
basic card styling for mobile
joelamb Oct 3, 2018
81bf276
refactor data clean
joelamb Oct 3, 2018
e92be27
click handler on card
joelamb Oct 3, 2018
fc15c1f
calculate winner
joelamb Oct 3, 2018
6e04731
save roundResult in state
joelamb Oct 3, 2018
2654ca0
advance round with win or lose result
joelamb Oct 3, 2018
726fc2a
parse vehicle property data as integers
joelamb Oct 3, 2018
b3c7304
next round advance
joelamb Oct 3, 2018
ed37ade
rearrange player and computer cards for next round
joelamb Oct 3, 2018
067aa05
card deal test (incomplete)
joelamb Oct 4, 2018
c2d9b0f
winner/loser result
joelamb Oct 4, 2018
9391566
play again
joelamb Oct 4, 2018
5f6b833
refactor data cleaning and test string to number
joelamb Oct 4, 2018
9d1af5e
simplify conditional render logic
joelamb Oct 4, 2018
9a0b7ef
round result message
joelamb Oct 4, 2018
d00094b
refactoring
joelamb Oct 4, 2018
d48fe6c
scoreboard data
joelamb Oct 4, 2018
fcdf32a
start screen initialise
joelamb Oct 4, 2018
d492d9f
Start screen and EndScreen
joelamb Oct 4, 2018
66854b0
conditional load of start screen
joelamb Oct 4, 2018
e7ce31e
MVP
joelamb Oct 4, 2018
9850f7d
styling
joelamb Oct 4, 2018
3ff567c
disable start until data is ready
joelamb Oct 4, 2018
1281343
fonts
joelamb Oct 4, 2018
f97804b
Endscreen
joelamb Oct 4, 2018
356fb47
include time factor in score
joelamb Oct 4, 2018
7b393b4
recalculate hi score
joelamb Oct 4, 2018
75d641b
hi score with timing
joelamb Oct 4, 2018
e5e778c
leaderboard scores
joelamb Oct 4, 2018
1c58262
MVP play your cards right
joelamb Oct 5, 2018
a8f3401
assets
joelamb Oct 5, 2018
08264dd
start page styling
joelamb Oct 5, 2018
c7bd137
gameplay styling
joelamb Oct 5, 2018
135712b
ready for demo
joelamb Oct 5, 2018
72f79c1
refactoring
joelamb Oct 8, 2018
040c1e6
debugging
joelamb Oct 8, 2018
d422ccf
handle bids in separate component
joelamb Oct 8, 2018
70aac86
abstract next round button
joelamb Oct 8, 2018
f50d3b9
refactoring and styling
joelamb Oct 8, 2018
ac11f6a
tests
joelamb Oct 8, 2018
d0aaca0
tetests
joelamb Oct 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor data cleaning and test string to number
  • Loading branch information
joelamb committed Oct 4, 2018
commit 5f6b833c40efd855ade3d7a53b87bbd88ffcf72a
23 changes: 14 additions & 9 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -79,18 +79,21 @@ class App extends React.Component {
return Object.assign({}, {
name: card.name,
properties: {
'crew': !+card.crew ? "No data" : +card.crew,
'maximum speed': !+card.max_atmosphering_speed ? "No data" : +card.max_atmosphering_speed,
'passengers': !+card.passengers ? "No data" : +card.passengers,
'cargo capacity': !+card.cargo_capacity ? "No data" : +card.cargo_capacity,
// 'consumable': card.consumables,
'length': !+card.length ? "No data" : +card.length,
'cost (in credits)': !+card.cost_in_credits ? "No data" : +card.cost_in_credits
'crew': this.stringToNumber(card.crew),
'maximum speed': this.stringToNumber(card.max_atmosphering_speed),
'passengers': this.stringToNumber(card.passengers),
'cargo capacity': this.stringToNumber(card.cargo_capacity),
'length': this.stringToNumber(card.length),
'cost (in credits)': this.stringToNumber(card.cost_in_credits)
}
})
});
};

stringToNumber(string) {
return !parseInt(string, 10) ? 'No data' : parseInt(string, 10);
}

handleCardClick(value, key) {
(value === 'No data') ? console.log("Please choose a different property") : this.findRoundWinner(value, this.state.computerCards[0].properties[key]);
};
@@ -191,14 +194,16 @@ class App extends React.Component {

{this.state.winner === 'player' &&
<React.Fragment>
<h2>The winner you are! The Force is strong in you</h2>
<h2>The winner you are!</h2>
<h3>The Force is strong in you</h3>
<button className='btn btn__again' onClick={e => this.playAgain(this.state.allCards, this.state.numCards)}>Play Again</button>
</React.Fragment>

}
{this.state.winner === 'computer' &&
<React.Fragment>
<h2>Lost you have young Jedi. Trust in the Force next time.</h2>
<h2>Lost you have young Jedi.</h2>
<h3>Trust in the Force you must.</h3>
<button
className='btn btn__again'
onClick={e => this.playAgain(this.state.allCards, this.state.numCards)}> Play Again
29 changes: 19 additions & 10 deletions tests/components/App.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import React from 'react';
import { shallow } from 'enzyme';

import App from '../../src/components/App';
import renderer from 'react-test-renderer';

global.fetch = require('jest-fetch-mock');

describe('App', () => {
// test('matches the snapshot', () => {
// const tree = renderer.create(<App />).toJSON();
// expect(tree).toMatchSnapshot();
// });

test('deal cards', () => {
const expected = 3;
const result = this.dealCards([])
test('string to number', () => {
const wrapper = shallow(< App />);
const instance = wrapper.instance();
const result = instance.stringToNumber("12");
const expected = 12;
expect(result).toEqual(expected);
});

test('string to number handles NaN', () => {
const wrapper = shallow(<App />);
const instance = wrapper.instance();
const result = instance.stringToNumber('unknown');
const expected = 'No data';
expect(result).toEqual(expected);
});

}

)
});