Skip to content
Permalink
Browse files
Switched to ECMA6 Module
  • Loading branch information
aa7401 committed Feb 15, 2020
1 parent d32aa82 commit b62b2c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
@@ -1,9 +1,20 @@

const deck = []

export async function gameSetup() {
// get the card data
const deckResponse = await fetch('deck.json')
let { cards } = await deckResponse.json()
for(const card of cards) deck.push(card) // add each card to the deck
buildDeck(cards, 'game')
}

/**
* Builds the deck of cards on the screen
* @param {Array} cards the cards to add to the deck
* @param {String} element the id of the containing div
*/
export function buildDeck(cards, element) {
function buildDeck(cards, element) {
const startLeft = 0.85
const top = 0.6
// const startZ = 10
@@ -14,7 +25,6 @@ export function buildDeck(cards, element) {
for(const index in cards) addCard(index)
// add event handler for the last card only
const topCard = document.querySelector(`img[style*="z-index: ${document.getElementById('game').dataset.zindex};"]`)
// console.log(topCard.id)
topCard.addEventListener('click', cardOnClick)
topCard.style.cursor = 'pointer'
}
@@ -3,7 +3,7 @@

const deck = []

let stackOrder = 10 // each card we click needs to be placed at the top
// let stackOrder = 10 // each card we click needs to be placed at the top
let angle = -20

gameSetup()
@@ -8,7 +8,6 @@
<meta name="description" content="Playing Cards">
<meta name="author" content="Mark Tyers">
<link rel="stylesheet" href="cards.css">
<script type="module" src="cards.js"></script>
</head>

<body data-responses="">
@@ -18,5 +17,9 @@
<p id="score">score 0</p>
</div>
</body>
<script type="module" src="game.js"></script>
<script type="module">
import {gameSetup} from './cards.js'
console.log('GAME SETUP')
gameSetup()
</script>
</html>

0 comments on commit b62b2c8

Please sign in to comment.