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

Ports - Jillianne #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class App extends Component {

onItemClicked = () => {
// Fill this in!
this.setState({
points: this.state.points + 1,
})
}

render() {
Expand All @@ -49,7 +52,8 @@ class App extends Component {
height={item.height} // Height - used for a CSS style to position on the screen
layer={100 + i} // Layer - used for a CSS style to show items on-top of bg
key={item.id} // Key - to help React with performance

type={item.type}
addPoint={this.onItemClicked}
// Additional props (event callbacks, etc.) can be passed here
/>;
});
Expand Down
37 changes: 31 additions & 6 deletions src/components/GameItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,34 @@ import ItemIcons from '../ItemIcons.js';
import PropTypes from 'prop-types';

class GameItem extends Component {
propTypes = {
constructor(state) {
super(state);

this.state = {
type: this.props.type,
className: 'game-item',
addPoint: this.props.addPoint,
};
}

static propTypes = {
height: PropTypes.number.isRequired,
layer: PropTypes.number.isRequired,
type: PropTypes.string.isRequired,
addPoint: PropTypes.func.isRequired,

Choose a reason for hiding this comment

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

👍

}

onImgClick = () => {
if (this.props.type === "litter") {
this.state.addPoint();
this.setState({
className: 'game-item spotted-litter',
})
} else {
this.setState({
className: 'game-item spotted-nature'
})
}
}

render() {
Expand All @@ -16,14 +41,14 @@ class GameItem extends Component {
};

// Update this to select the correct icon for each item
const icon = ItemIcons.rock;

const icon = ItemIcons[this.state.type];
return (
<div className="game-item" style={itemStyle}>
<img src={icon} alt="Item" className="icon-item"></img>
<div className={this.state.className} style={itemStyle}>
<img src={icon} alt="Item" className="icon-item" onClick={this.onImgClick}></img>
</div>
);
}
}

export default GameItem;
export default GameItem;