SHARE
TWEET

Untitled

a guest Oct 18th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. APP.JS
  2. 'use strict'
  3.  
  4. const suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']
  5. const values = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
  6.  
  7. const Deck = require('./Deck')
  8. const Player = require('./Player')
  9.  
  10. let deck = new Deck()
  11. let player = new Player()
  12. deck.createDeck(suits, values)
  13. console.log(deck.cards)
  14. deck.shuffle()
  15.  
  16. console.log(player)
  17.  
  18. PLAYER.JS
  19. 'use strict'
  20.  
  21. class Player {
  22.   constructor () {
  23.     this.hand = []
  24.   }
  25.  
  26.   playerAmount (players) {
  27.       for (let i = 0; i < players; i++) {
  28.           new Player
  29.       }
  30.   }
  31. }
  32.  
  33. let player = new Player()
  34. module.exports = Player
  35.  
  36. DECK.JS
  37. 'use strict'
  38.  
  39. const suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']
  40. const values = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
  41.  
  42. const Card = require('./Card')
  43.  
  44. class Deck {
  45.   constructor () {
  46.     this.cards = []
  47.   }
  48.  
  49.   createDeck (suits, values) {
  50.     for (const suit of suits) {
  51.       for (const value of values) {
  52.         this.cards.push(new Card(suit, value))
  53.       }
  54.     }
  55.     return this.cards
  56.   }
  57.  
  58.   shuffle () {
  59.     let i = this.cards.length // 52, Arrayens längd
  60.     console.log(i)
  61.     let j // Random tal mellan 0-51
  62.     let temp // för att byta värdet
  63.     while (--i > 0) { // sänker i till 51 direkt, tills mindre än 1
  64.       j = Math.floor(Math.random() * (i + 1)) // tal mellan 0- 51
  65.       // console.log(j)
  66.       temp = this.cards[j]
  67.       // console.log(temp)
  68.       this.cards[j] = this.cards[i]
  69.       this.cards[i] = temp
  70.     }
  71.   }
  72. }
  73.  
  74. module.exports = Deck
  75.  
  76. CARDS.JS
  77. 'use strict'
  78.  
  79. class Card {
  80.   constructor (suit, value) {
  81.     this.suits = suit
  82.     this.value = value
  83.   }
  84. }
  85.  
  86. module.exports = Card
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top