diff --git a/README.md b/README.md
index 7435989..b9095d4 100644
--- a/README.md
+++ b/README.md
@@ -1,48 +1,13 @@
# Pick your own project
-Build an app of your choice.
-
-- You are free to use any technologies covered so far, but feel free to try new technologies you find interesting.
-- Keep it simple. Aim to get the basic functionality working on day one. You can then extend it on days two and three.
-- Feel free to use an external API to provide additional functionality to your app. Use an API that either does not have any authentication or uses API keys.
-- This is an opportunity to practice the parts you have challenging so far and improve your understanding of them.
-- Use pen and paper to draw a diagram of the webpage layout before starting to code. Have a think about what components you will need in advance.
-- Use prop-types and stateless components where appropriate.
-- Try to use Sass to create a separate stylesheet for each component.
-- Try to add some unit testing. Some parts will be easier to test than others, focus on those first.
-- Think about how to organise your data in advance
-- Make sure your app is responsive
-- Commit frequently
-- Create pull request at the end
-- Demos will be at 4pm on Friday
-- Keep it simple
-
-## Technical notes
-
-* Run `npm install` after cloning to download all dependencies
-* Use `npm run dev -- --watch` to build React
-* Use `npm test` or `npm test -- --watchAll` to run tests
-
-## README
-
-* Produce a README.md which explains
- * what the project does
- * what technologies it uses
- * how to build it and run it
- * any unresolved issues the user should be aware of
-
-## Inspiration
-
-- Take a look at [https://public-apis.jeremyfairbank.com/](https://public-apis.jeremyfairbank.com/) or [https://github.com/toddmotto/public-apis](https://github.com/toddmotto/public-apis) for possible APIs to use.
-
-## Default option
-
-If you are struggling to think of a project to build. Try to create a Top Trumps using the [Star Wars API](https://swapi.co/) which allows one user to play the game against the computer.
-
-- On load, fetch all vehicles from [https://swapi.co/api/vehicles/](https://swapi.co/api/vehicles/) end point.
-- Randomise the cards and deal half to player and half to computer.
-- Display top card to user
-- Allow user to pick an attribute from their card such as `cost_in_credits`, `length`, `max_atmosphering_speed`, `crew`, `passengers`, `cargo_capacity`.
-- If the value for chosen attribute is higher on the user's card than on computer's top card, they win the computer's card and it should be taken from computer's deck and added to the bottom of the user's deck. If the attribute is higher on the computer's top card, then user's card should be taken from the user's deck and added to the bottom of computer's deck.
-- Game continues until either user or computer has all the cards.
-- Implement some features of your choosing.
+This is a pokemon game where:
+-you can search for pokemon and view their stats
+-select up to 6 for your team (these can be removed and changed as needed)
+-you can view you Team
+-then you can play a top trumps type game against the computer (only you make selections though)
+
+Tech stuff
+-Uses pokeapi
+-There are no tests due to a tough week
+-scss was used in a last min rush
+-little attention was given to BEM, pure functions
diff --git a/index.html b/index.html
index f8102eb..e3bc72f 100644
--- a/index.html
+++ b/index.html
@@ -5,7 +5,7 @@
-
diff --git a/src/components/App.js b/src/components/App.js
index a4aaba8..dea1c5f 100644
--- a/src/components/App.js
+++ b/src/components/App.js
@@ -1,4 +1,8 @@
import React from 'react';
+import Search from './Search.js';
+import SearchResults from './SearchResults.js'
+import Team from './Team.js'
+import Game from './Game.js'
import '../styles/components/app.scss';
@@ -6,12 +10,123 @@ class App extends React.Component {
constructor(){
super();
+
+ this.state = {
+ pokemonList: [],
+ searchQuery: "",
+ searchList: [],
+ searchListDetails: [],
+ team: [],
+ opponent: [],
+ play: false
+ }
+
+ this.handleSearchSubmit = this.handleSearchSubmit.bind(this);
+ this.handleSearchChange = this.handleSearchChange.bind(this);
+ this.addPokemonToTeam = this.addPokemonToTeam.bind(this);
+ this.removePokemonFromTeam = this.removePokemonFromTeam.bind(this);
+ this.handleClick = this.handleClick.bind(this);
+ this.generateComputerCard = this.generateComputerCard.bind(this);
}
+componentDidMount(){
+ fetch(`https://pokeapi.co/api/v2/pokemon/`)
+ .then(response => response.json())
+ .then (body => {
+ console.log(body.results)
+ this.setState({
+ pokemonList: body.results
+ })
+ })
+}
+
+
+handleSearchSubmit(){
+ this.setState({
+ searchList: this.state.pokemonList.filter((item) => {
+ return item.name.includes(this.state.searchQuery.toLowerCase())
+ })
+ }, () => {
+
+ Promise.all(this.state.searchList.map(pokemon =>
+ fetch(pokemon.url).then(response => response.json())
+ ))
+ .then(results => {
+ console.log("test", results);
+ this.setState({
+ searchListDetails: results
+ })
+ })
+
+
+ })
+
+}
+
+handleSearchChange(searchQuery){
+ this.setState({
+ searchQuery: searchQuery
+ }, () => {
+ console.log(this.state.searchQuery)
+ })
+}
+
+addPokemonToTeam(pokemon){
+ if (this.state.team.length < 6){
+ this.setState({
+ team: this.state.team.concat(pokemon)
+ })
+ } else {
+ alert("You can only have 6 pokemon in a team!")
+ }
+}
+
+
+removePokemonFromTeam(pokemon){
+ const filteredTeam = this.state.team.filter( currentTeam => {
+ return currentTeam.id !== pokemon.id
+ })
+
+ this.setState({
+ team: filteredTeam
+ })
+}
+
+generateComputerCard(){
+ let randomPokemonNumber = Math.floor(Math.random() * (800 - 1 + 1)) + 1;
+ fetch(`https://pokeapi.co/api/v2/pokemon/${randomPokemonNumber}/`)
+ .then(response => response.json())
+ .then (body => {
+ this.setState({
+ opponent: this.state.opponent.concat(body)
+ })
+ })
+ .catch(error => {
+ console.log(error);
+ })
+ }
+
+
+handleClick(){
+ for(let i =0; i<6; i++){
+ this.generateComputerCard()
+ this.setState({
+ play: !this.state.play
+ })
+ }
+ console.log(this.state.opponent)
+}
+
render(){
return (
- App goes here
+
+ {this.state.play ?
:
+
+
+
+ this.handleClick()}>Play
+
}
)
}
diff --git a/src/components/Cards.js b/src/components/Cards.js
new file mode 100644
index 0000000..55db30b
--- /dev/null
+++ b/src/components/Cards.js
@@ -0,0 +1,36 @@
+import React from 'react';
+
+import '../styles/components/Cards.scss';
+
+class Cards extends React.Component{
+ constructor(){
+ super();
+
+ this.state = {
+ currentCardIndex: 0
+ }
+
+
+ }
+
+
+render(){
+ return(
+
+
+ {this.props.playerCard.name}
+
+ Speed: {this.props.playerCard.stats[0].base_stat}
this.props.handleClick(this.props.playerCard.stats[0].base_stat, this.props.computerCard.stats[0].base_stat) }>Select
+ Special Defense: {this.props.playerCard.stats[1].base_stat}
this.props.handleClick(this.props.playerCard.stats[1].base_stat, this.props.computerCard.stats[1].base_stat) }>Select
+ Special Attack: {this.props.playerCard.stats[2].base_stat}
this.props.handleClick(this.props.playerCard.stats[2].base_stat, this.props.computerCard.stats[2].base_stat) }>Select
+ Defense: {this.props.playerCard.stats[3].base_stat}
this.props.handleClick(this.props.playerCard.stats[3].base_stat, this.props.computerCard.stats[3].base_stat) }>Select
+ Attack: {this.props.playerCard.stats[4].base_stat}
this.props.handleClick(this.props.playerCard.stats[4].base_stat, this.props.computerCard.stats[4].base_stat) }>Select
+ HP: {this.props.playerCard.stats[5].base_stat}
this.props.handleClick(this.props.playerCard.stats[5].base_stat, this.props.computerCard.stats[5].base_stat) }>Select
+
+
+)
+}
+
+}
+
+export default Cards
diff --git a/src/components/Game.js b/src/components/Game.js
new file mode 100644
index 0000000..8fcc943
--- /dev/null
+++ b/src/components/Game.js
@@ -0,0 +1,63 @@
+import React from 'react'
+import Cards from './Cards.js'
+
+import '../styles/components/Game.scss';
+
+class Game extends React.Component{
+ constructor(){
+ super()
+
+ this.state = {
+ playerScore: 0,
+ computerScore: 0,
+ playerTurn: true,
+ playerCard: {},
+ computerCard: {},
+ cardIndex: 0
+ }
+
+ this.handleClick = this.handleClick.bind(this);
+
+ }
+
+
+handleClick(playerStat, computerStat){
+const playerCard = this.props.team[this.state.cardIndex];
+const computerCard = this.props.opponent[this.state.cardIndex];
+ if (playerStat > computerStat){
+ this.setState({
+ playerScore: this.state.playerScore + 1,
+ cardIndex: this.state.cardIndex + 1
+ })
+ alert(`${playerCard.name} beat ${computerCard.name}`)
+
+ } else if (playerStat < computerStat){
+ this.setState({
+ computerScore: this.state.computerScore + 1,
+ cardIndex: this.state.cardIndex + 1
+ })
+ alert(`${computerCard.name} beat ${playerCard.name}`)
+ }
+
+ if (this.state.playerScore === 3){
+ alert("Player Wins")
+ let win = new Audio('win.mp3');
+ win.play();
+ }
+
+}
+
+render(){
+ const playerCard = this.props.team[this.state.cardIndex];
+ const computerCard = this.props.opponent[this.state.cardIndex];
+ return(
+
+
Player Score: {this.state.playerScore} --- Computer Score: {this.state.computerScore}
+
+
+ )
+}
+
+
+}
+export default Game
diff --git a/src/components/Playercard.js b/src/components/Playercard.js
new file mode 100644
index 0000000..262b0e2
--- /dev/null
+++ b/src/components/Playercard.js
@@ -0,0 +1,30 @@
+import React from 'react';
+
+class Cards extends React.Component{
+ constructor(){
+ super();
+
+ this.state = {
+ currentCardIndex: 0
+ }
+
+ this.handleClick = this.handleClick.bind(this);
+ }
+
+handleClick(){
+ console.log("the")
+}
+
+
+render(){
+ return(
+
+ {this.props.team[${this.state.currentCardIndex}].name}
+ {pokemon.stats[${this.state.currentCardIndex}].stat.name}{pokemon.stats[${this.state.currentCardIndex}].base_stat} this.handleClick(pokemon)}>Select
+
+)
+}
+
+}
+
+export default Cards
diff --git a/src/components/Pokemon.js b/src/components/Pokemon.js
new file mode 100644
index 0000000..0f04b8c
--- /dev/null
+++ b/src/components/Pokemon.js
@@ -0,0 +1,55 @@
+import React from 'react';
+
+class Pokemon extends React.Component {
+ constructor(){
+ super();
+
+ this.state= {
+
+ }
+
+ this.handleClick = this.handleClick.bind(this);
+ }
+
+handleClick(){
+ if(this.props.onTeam){
+ this.props.removePokemonFromTeam(this.props.pokemon);
+ } else {
+ this.props.addPokemonToTeam(this.props.pokemon);
+ }
+}
+
+ render(){
+ return(
+
+
+
+
+ {this.props.pokemon.name}
+ {this.props.pokemon.stats[0].stat.name}
+ {this.props.pokemon.stats[1].stat.name}
+ {this.props.pokemon.stats[2].stat.name}
+ {this.props.pokemon.stats[3].stat.name}
+ {this.props.pokemon.stats[4].stat.name}
+ {this.props.pokemon.stats[5].stat.name}
+
+
+
+ {this.props.pokemon.stats[0].base_stat}
+ {this.props.pokemon.stats[1].base_stat}
+ {this.props.pokemon.stats[2].base_stat}
+ {this.props.pokemon.stats[3].base_stat}
+ {this.props.pokemon.stats[4].base_stat}
+ {this.props.pokemon.stats[5].base_stat}
+
+
+
+
{this.props.pokemon.species.name}
+
{ this.props.onTeam ? 'Remove from team' : 'Add to team'}
+
+ )
+ }
+
+}
+
+export default Pokemon
diff --git a/src/components/Search.js b/src/components/Search.js
new file mode 100644
index 0000000..e2d99dd
--- /dev/null
+++ b/src/components/Search.js
@@ -0,0 +1,36 @@
+import React from 'react';
+
+class Search extends React.Component{
+ constructor(){
+ super();
+
+ this.state = {
+
+ }
+
+ this.handleChange = this.handleChange.bind(this);
+ this.handleSubmit = this.handleSubmit.bind(this);
+ }
+
+handleChange(event){
+ this.props.handleSearchChange(event.target.value)
+}
+
+handleSubmit(event){
+ event.preventDefault();
+ this.props.handleSearchSubmit();
+ }
+
+
+
+render(){
+ return (
+
+ )
+}
+
+}
+export default Search;
diff --git a/src/components/SearchResults.js b/src/components/SearchResults.js
new file mode 100644
index 0000000..3d094db
--- /dev/null
+++ b/src/components/SearchResults.js
@@ -0,0 +1,29 @@
+import React from 'react';
+import Pokemon from './Pokemon.js'
+
+class SearchResults extends React.Component{
+ constructor(){
+ super();
+
+
+
+ }
+
+
+render(){
+ return(
+
+ {this.props.searchListDetails.map(pokemon => {
+
+ const onTeam = this.props.team.find( currentTeam => {
+ return currentTeam.id === pokemon.id;
+ });
+ return(
+
+ );
+ })}
+
+ )
+ }
+}
+export default SearchResults
diff --git a/src/components/Team.js b/src/components/Team.js
new file mode 100644
index 0000000..63e4d87
--- /dev/null
+++ b/src/components/Team.js
@@ -0,0 +1,54 @@
+import React from 'react';
+
+class Team extends React.Component{
+ constructor(){
+ super();
+
+ this.handleClick = this.handleClick.bind(this);
+ }
+
+handleClick(pokemon){
+ this.props.removePokemonFromTeam(pokemon);
+}
+
+
+render(){
+ return(
+
+
My PokeTeam
+ {this.props.team.map(pokemon => {
+ return
+
+
+
+ {pokemon.name}
+ {pokemon.stats[0].stat.name}
+ {pokemon.stats[1].stat.name}
+ {pokemon.stats[2].stat.name}
+ {pokemon.stats[3].stat.name}
+ {pokemon.stats[4].stat.name}
+ {pokemon.stats[5].stat.name}
+
+
+
+ {pokemon.stats[0].base_stat}
+ {pokemon.stats[1].base_stat}
+ {pokemon.stats[2].base_stat}
+ {pokemon.stats[3].base_stat}
+ {pokemon.stats[4].base_stat}
+ {pokemon.stats[5].base_stat}
+
+
+
+
{pokemon.species.name}
+
this.handleClick(pokemon)}>Remove from Team
+
+ })}
+
+ )
+
+}
+
+}
+
+export default Team
diff --git a/src/components/win.mp3 b/src/components/win.mp3
new file mode 100644
index 0000000..09bc097
Binary files /dev/null and b/src/components/win.mp3 differ
diff --git a/src/styles/components/Cards.scss b/src/styles/components/Cards.scss
new file mode 100644
index 0000000..583b0dd
--- /dev/null
+++ b/src/styles/components/Cards.scss
@@ -0,0 +1,4 @@
+.sprite {
+ display: block;
+ max-width: 20vw;
+}
diff --git a/src/styles/components/Game.scss b/src/styles/components/Game.scss
new file mode 100644
index 0000000..27eccbb
--- /dev/null
+++ b/src/styles/components/Game.scss
@@ -0,0 +1,16 @@
+.game {
+ border: 4mm ridge rgb(170, 50, 220);
+}
+
+
+.scores{
+ text-align: center;
+}
+
+
+.card{
+ text-align: center;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+}
diff --git a/win.mp3 b/win.mp3
new file mode 100644
index 0000000..09bc097
Binary files /dev/null and b/win.mp3 differ