1
0
mirror of https://github.com/mizanxali/uno-online synced 2024-11-05 10:45:25 +00:00

Improvements and bug fixes

This commit is contained in:
Mizanali Panjwani 2021-02-17 07:04:27 +05:30
parent ff7cbe703e
commit 8b12e81206
3 changed files with 16 additions and 20 deletions

View File

@ -483,11 +483,13 @@ const Game = () => {
setDrawCardPile([...copiedDrawCardPileArray]) setDrawCardPile([...copiedDrawCardPileArray])
} }
//else add the drawn card to player1's deck //else add the drawn card to player1's deck
else {
//set new state //set new state
setTurn('Player 2') setTurn('Player 2')
setPlayer1Deck([...player1Deck.slice(0, player1Deck.length), drawCard, ...player1Deck.slice(player1Deck.length)]) setPlayer1Deck([...player1Deck.slice(0, player1Deck.length), drawCard, ...player1Deck.slice(player1Deck.length)])
setDrawCardPile([...copiedDrawCardPileArray]) setDrawCardPile([...copiedDrawCardPileArray])
} }
}
else { else {
//remove 1 new card from drawCardPile and add it to player2's deck (immutably) //remove 1 new card from drawCardPile and add it to player2's deck (immutably)
//make a copy of drawCardPile array //make a copy of drawCardPile array
@ -557,12 +559,14 @@ const Game = () => {
setDrawCardPile([...copiedDrawCardPileArray]) setDrawCardPile([...copiedDrawCardPileArray])
} }
//else add the drawn card to player2's deck //else add the drawn card to player2's deck
else {
//set new state //set new state
setTurn('Player 1') setTurn('Player 1')
setPlayer2Deck([...player2Deck.slice(0, player2Deck.length), drawCard, ...player2Deck.slice(player2Deck.length)]) setPlayer2Deck([...player2Deck.slice(0, player2Deck.length), drawCard, ...player2Deck.slice(player2Deck.length)])
setDrawCardPile([...copiedDrawCardPileArray]) setDrawCardPile([...copiedDrawCardPileArray])
} }
} }
}
return ( return (
gameOver ? <div><h1>GAME FORFEITED</h1>{winner !== '' && <><h1>GAME OVER</h1><h2>{winner} wins!</h2></>}<a href='/'>Home</a></div> : gameOver ? <div><h1>GAME FORFEITED</h1>{winner !== '' && <><h1>GAME OVER</h1><h2>{winner} wins!</h2></>}<a href='/'>Home</a></div> :

View File

@ -1,21 +1,13 @@
import React from 'react' import React from 'react'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { START_GAME } from '../store/actions'
import { connect } from 'react-redux'
const Homepage = (props) => { const Homepage = () => {
return ( return (
<div className='Homepage'> <div className='Homepage'>
<h1>UNO</h1> <h1>UNO</h1>
<Link to='/play'><button onClick={props.onStartGame}>START GAME</button></Link> <Link to='/play'><button>START GAME</button></Link>
</div> </div>
) )
} }
const mapDispatchToProps = (dispatch) => { export default Homepage
return {
onStartGame: () => dispatch({type: START_GAME})
}
}
export default connect(null, mapDispatchToProps)(Homepage)

View File

@ -1,5 +1,5 @@
//pack of 108 cards (# = reverse) //pack of 108 cards (# = reverse)
export default CARDS = [ export default [
'0R', '1R', '1R', '2R', '2R', '3R', '3R', '4R', '4R', '5R', '5R', '6R', '6R', '7R', '7R', '8R', '8R', '9R', '9R', 'skipR', 'skipR', '#R', '#R', 'D2R', 'D2R', '0R', '1R', '1R', '2R', '2R', '3R', '3R', '4R', '4R', '5R', '5R', '6R', '6R', '7R', '7R', '8R', '8R', '9R', '9R', 'skipR', 'skipR', '#R', '#R', 'D2R', 'D2R',
'0G', '1G', '1G', '2G', '2G', '3G', '3G', '4G', '4G', '5G', '5G', '6G', '6G', '7G', '7G', '8G', '8G', '9G', '9G', 'skipG', 'skipG', '#G', '#G', 'D2G', 'D2G', '0G', '1G', '1G', '2G', '2G', '3G', '3G', '4G', '4G', '5G', '5G', '6G', '6G', '7G', '7G', '8G', '8G', '9G', '9G', 'skipG', 'skipG', '#G', '#G', 'D2G', 'D2G',
'0B', '1B', '1B', '2B', '2B', '3B', '3B', '4B', '4B', '5B', '5B', '6B', '6B', '7B', '7B', '8B', '8B', '9B', '9B', 'skipB', 'skipB', '#B', '#B', 'D2B', 'D2B', '0B', '1B', '1B', '2B', '2B', '3B', '3B', '4B', '4B', '5B', '5B', '6B', '6B', '7B', '7B', '8B', '8B', '9B', '9B', 'skipB', 'skipB', '#B', '#B', 'D2B', 'D2B',