forked from Github/uno-online
Added game code generator
This commit is contained in:
parent
0fefbf1d45
commit
bfe3fb5374
@ -701,6 +701,7 @@ const Game = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
(!roomFull) ? <>
|
(!roomFull) ? <>
|
||||||
|
<h1>Game Code: {room}</h1>
|
||||||
|
|
||||||
{users.length===2 ? <>
|
{users.length===2 ? <>
|
||||||
|
|
||||||
@ -737,12 +738,6 @@ const Game = (props) => {
|
|||||||
<button onClick={onCardDrawnHandler}>DRAW CARD</button>
|
<button onClick={onCardDrawnHandler}>DRAW CARD</button>
|
||||||
</div> }
|
</div> }
|
||||||
<hr />
|
<hr />
|
||||||
<div>
|
|
||||||
<h1>Users in room:</h1>
|
|
||||||
{users.map(user => {
|
|
||||||
return <h6>{user.name}</h6>
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
<a href='/'>Home</a>
|
<a href='/'>Home</a>
|
||||||
</div>}
|
</div>}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
|
import randomCodeGenerator from '../utils/randomCodeGenerator'
|
||||||
|
|
||||||
const Homepage = () => {
|
const Homepage = () => {
|
||||||
const [roomCode, setRoomCode] = useState('')
|
const [roomCode, setRoomCode] = useState('')
|
||||||
@ -7,8 +8,10 @@ const Homepage = () => {
|
|||||||
return (
|
return (
|
||||||
<div className='Homepage'>
|
<div className='Homepage'>
|
||||||
<h1>UNO</h1>
|
<h1>UNO</h1>
|
||||||
<div><input type='text' placeholder='Room' onChange={(event) => setRoomCode(event.target.value)} /></div>
|
<div><input type='text' placeholder='Game Code' onChange={(event) => setRoomCode(event.target.value)} /></div>
|
||||||
<Link to={`/play?roomCode=${roomCode}`}><button>START GAME</button></Link>
|
<Link to={`/play?roomCode=${roomCode}`}><button>JOIN GAME</button></Link>
|
||||||
|
<h1>OR</h1>
|
||||||
|
<Link to={`/play?roomCode=${randomCodeGenerator(5)}`}><button>CREATE GAME</button></Link>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
9
client/src/utils/randomCodeGenerator.js
Normal file
9
client/src/utils/randomCodeGenerator.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export default function makeid(length) {
|
||||||
|
var result = '';
|
||||||
|
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
var charactersLength = characters.length;
|
||||||
|
for ( var i = 0; i < length; i++ ) {
|
||||||
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user