Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="game"></div>
              
            
!

CSS

              
                @import (css) url(https://fonts.googleapis.com/css2?family=Lilita+One&display=swap);

body,
html {
  height: 100%;
}

body {
  padding: 0;
  margin: 0;
  perspective: 1000px;
  background-color: #016f8e;
  display: flex;
  align-items: center;

  div {
    transform-style: preserve-3d;
  }
}

.loading {
  height: 116px;
  font: 40px "Lilita One", sans-serif;
  color: white;
  text-align: center;
  margin: auto;
  line-height: 116px;
  .dots {
    &:not(:last-child){
      animation: loading-1 1s infinite;
        &:after{
          content: '.';
          opacity: 0;
          animation: loading-2 1s infinite;
        }
    }
    &:last-child{
      opacity: 0;
      animation: loading-3 1s infinite;
    }
  }
}

.game {
  margin: auto;
  width: 1380px;

  &__display {
    display: flex;
    width: 1080px;
    min-height: 421px;
  }

  &__main {
    padding-top: 40px;
  }
}

.hand {
  &__card {
    position: absolute;
    opacity: 0;
    transition: margin 0.1s;

    flex-direction: column;
    align-items: center;

    &.selected {
      &:before,
      &:after {
        content: "";
        border-radius: 100%;
        height: 120px;
        width: 120px;
        margin-top: -60px;
        z-index: 1;
        box-sizing: border-box;
        left: 40px;
        bottom: -40px;
        position: absolute;
      }

      &:before {
        content: "Hold";
        font: 24px "Lilita One", sans-serif;
        color: white;
        text-align: center;
        line-height: 100px;
        background: #884dff;
        border: 10px double whitesmoke; //#012a58;
        box-shadow: 0 6px darken(#884dff, 50%);
        text-shadow: 2px 2px 3px black;
      }
    }
  }
}

.card {
  width: 200px;
  height: 309.5px;
  border-radius: 14px;

  &__front,
  &__back {
    width: 100%;
    height: 100%;
    position: absolute;
  }

  &__back {
    transform: translateZ(-1px);
    background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/1443237/back.png);
  }
}

each(range(13), .(@v, @k, @i){
    each(range(4), {
      @number: @v - 1;
      @suit: @value - 1;
      .card-@{number}-@{suit} {
        background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/1443237/cards.png) unit(@number * -200, px) unit(@suit * 309.5, px);
      }
    })
  });

.deck {
  position: relative;
  width: 200px;
  height: 309.5px;
  border-radius: 14px;
  left: unit((1000 + (4 * 20) + 100), px);

  > div {
    background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/1443237/back.png);
    height: 100%;
    width: 100%;
    position: absolute;
    each(range(13), {
        &:nth-child(@{value}) {
          transform: translateZ(unit(@value * 4, px));
        }
      });
    &.hide {
      visibility: hidden;
    }
  }
}

.score-table {
  width: 640px;
  padding: 0 13px 10px 13px;
  color: #d0cb67;

  > div {
    &:last-child {
      height: 3px;
      position: absolute;
      background: white;
      width: 50%;
      left: 25%;
      bottom: 0px;
    }
  }
  &__line {
    display: flex;
    background-color: rgb(1, 42, 88);
    padding: 2px 10px;
    text-shadow: 2px 2px 4px black;
    font: 18px "Lilita One", sans-serif;

    &:nth-child(2) {
      text-align: center;
      background-color: #012a58;
      margin: 10px 0;
      border-radius: 10px;
      height: 40px;

      > div {
        margin: auto;

        &:not(:nth-child(1)) {
          margin-left: 40px;
        }
      }
    }

    &:not(:nth-child(2)) {
      > div {
        &:not(:nth-child(1)) {
          text-align: right;
          color: rgb(250, 250, 222);
        }
      }
    }

    &__name {
      flex: 0 0 200px;
      border-left: none;
      padding: 5px;
    }

    &__pay {
      width: 88px;
      padding: 5px;
    }

    &:nth-child(odd) {
      background-color: transparent;
    }

    &--win {
      &:after {
        content: "";
        width: 100%;
        height: 100%;
        position: absolute;
        background-color: #108fe8;
        z-index: -1;
        top: 0;
        left: 0;
      }
    }
  }

  &:before,
  &:after {
    content: "";
    height: calc(100% - 16px);
    width: 258px;
    position: absolute;
    border: 3px solid white;
    box-sizing: border-box;
    margin-top: 16px;
    top: 0;
  }

  &:before {
    left: 0;
    border-right: none;
    border-top-left-radius: 16px;
    border-bottom-left-radius: 16px;
  }

  &:after {
    right: 0;
    border-left: none;
    border-top-right-radius: 16px;
    border-bottom-right-radius: 16px;
  }
}

// hud
.hud {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  padding-left: 30px;
  box-sizing: border-box;

  > div {
    &:first-child {
      flex-grow: 1;
      text-align: center;
      font: 50px "Lilita One", sans-serif;
      color: white;

      img {
        height: 70px;
        vertical-align: middle;
      }
    }
  }
}

.controls {
  display: flex;
  height: 116px;

  button {
    font: 24px "Lilita One", sans-serif;
    color: white;
    background: #108fe8;
    border: 3px solid #fff;
    box-shadow: 0 -2px 0 3px #0d72b8 inset, 0 5px 5px rgba(3, 25, 41, 0.17),
      0 15px rgba(255, 255, 255, 0.25) inset;
    transition: box-shadow 0.1s;
  }
}

.hud-title {
  font: 28px "Lilita One", sans-serif;
  text-align: center;
  color: white;
}

.bet {
  margin-right: 16px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;

  &:before,
  &:after {
    content: "";
    height: calc(100% - 16px);
    position: absolute;
    border: 3px solid white;
    box-sizing: border-box;
    width: 104px;
    margin-top: 16px;
    z-index: -1;
  }

  &:before {
    border-right: 0;
    border-top-left-radius: 16px;
    border-bottom-left-radius: 16px;
  }

  &:after {
    border-left: 0;
    right: 0;
    border-top-right-radius: 16px;
    border-bottom-right-radius: 16px;
  }

  &__amount {
    font: 48px "Lilita One", sans-serif;
    text-align: center;
    color: white;
    width: 60px;
    height: 100%;
    border-bottom: 3px solid white;
    box-sizing: border-box;
    line-height: 68px;
  }

  &__button {
    height: 100%;
    flex-grow: 1;

    button {
      border-radius: 100%;
      height: 68px;
      width: 68px;
      display: block;
      margin: auto;
    }
  }

  & + button {
    border-radius: 16px;
    width: 100px;
    height: 100px;
    align-self: flex-end;

    &.deal-button-can-draw {
      animation: flash-deal 1s infinite;
    }
  }

  > div:not(.hud-title) {
    display: flex;
    align-items: center;
    flex-grow: 1;
  }
}

@keyframes flash-deal {
  0% {
    background: lighten(#108fe8, 10%);
    box-shadow: 0 -2px 0 3px lighten(#0d72b8, 10%) inset,
      0 5px 5px rgba(3, 25, 41, 0.17), 0 15px rgba(255, 255, 255, 0.25) inset;
    text-shadow: 0 0 2px black;
  }
  60% {
    background: lighten(#108fe8, 10%);
    box-shadow: 0 -2px 0 3px lighten(#0d72b8, 10%) inset,
      0 5px 5px rgba(3, 25, 41, 0.17), 0 15px rgba(255, 255, 255, 0.25) inset;
    text-shadow: 0 0 2px black;
  }
  100% {
    background: #108fe8;
    box-shadow: 0 -2px 0 3px #0d72b8 inset, 0 5px 5px rgba(3, 25, 41, 0.17),
      0 15px rgba(255, 255, 255, 0.25) inset;
    text-shadow: none;
  }
}

.credits {
  height: 116px;
  display: flex;
  flex-direction: column;

  &:before,
  &:after {
    content: "";
    height: calc(100% - 16px);
    width: 139px;
    position: absolute;
    border: 3px solid white;
    box-sizing: border-box;
    margin-top: 16px;
  }

  &:before {
    border-right: none;
    border-top-left-radius: 16px;
    border-bottom-left-radius: 16px;
  }

  &:after {
    border-left: none;
    right: 0;
    border-top-right-radius: 16px;
    border-bottom-right-radius: 16px;
  }

  &__amount {
    height: 100%;
    border-bottom: 3px solid white;
    margin: 0 14px;
    font: 48px "Lilita One", sans-serif;
    text-align: center;
    color: white;
    line-height: 68px;
  }

  &--wide {
    &:before,
    &:after {
      width: 123px;
    }
  }
}

@keyframes loading-1 {
  0%{
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  90.1% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

@keyframes loading-2 {
  0%{
    opacity: 0;
  }
  33%{
    opacity: 0;
  }
  33.1%{
    opacity: 1;
  }
    90% {
    opacity: 1;
  }
  90.1% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

@keyframes loading-3 {
  0%{
    opacity: 0;
  }
  66%{
    opacity: 0;
  }
  66.1%{
    opacity: 1;
  }
    90% {
    opacity: 1;
  }
  90.1% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

              
            
!

JS

              
                /*
 * VIDEO POKER
 * A slot machine style poker game built using Vue & Vuex
 * How to play:
 * 1. Place a bet and click deal
 * 2. Select which cards to hold and discard
 * 3. Click deal again to redraw
 * 
 * By Hai Le
 * https://twitter.com/misfitdeveloper
 *
 * Credits:
 * Glossy button style from dodozhang21 (https://codepen.io/dodozhang21/pen/Ewftz)
 * Card images from Game Asset Studio https://assetstore.unity.com/packages/3d/props/tools/free-playing-cards-pack-154780
 */

const actionTypes = {
  SHUFFLE_DECK: 'SHUFFLE_DECK',
  DEAL_CARD: 'DEAL_CARD',
  INITIALIZE_DECK: 'INITIALIZE_DECK',
  REMOVE_FROM_HAND: 'REMOVE_FROM_HAND',
  RESET_HAND: 'RESET_HAND',
  PLACE_BET: 'PLACE_BET',
  PLAY_HAND: 'PLAY_HAND',
  FINALIZE: 'FINALIZE'
};

const mutationTypes = {
  SET_DECK: 'SET_DECK',
  SET_HAND: 'SET_HAND',
  SET_DEAD_STACK: 'SET_DEAD_STACK',
  SET_BET: 'SET_BET',
  SET_CREDITS: 'SET_CREDITS',
  SET_GAMESTATE: 'SET_GAMESTATE',
  SET_PAYLINE: 'SET_PAYLINE',
  SET_WINNINGS: 'SET_WINNINGS'
};

const gamestates = {
  READY: 'READY',
  DEALING: 'DEALING',
  SWAP: 'SWAP',
  SWAPPING: 'SWAPPING'
};

const payLines = {
  ROYAL_FLUSH: 'ROYAL_FLUSH',
  STRAIGHT_FLUSH: 'STRAIGHT_FLUSH',
  FOUR_OF_A_KIND: 'FOUR_OF_A_KIND',
  FULL_HOUSE: 'FULL_HOUSE',
  FLUSH: 'FLUSH',
  STRAIGHT: 'STRAIGHT',
  THREE_OF_A_KIND: 'THREE_OF_A_KIND',
  TWO_PAIR: 'TWO_PAIR',
  PAIR: 'PAIR'
};

const actions = {
  async [actionTypes.INITIALIZE_DECK]({commit, dispatch}){
    const deck = [];
    Array.from(Array(13).keys()).forEach((number) => {
      Array.from(Array(4).keys()).forEach((suit) => {
        deck.push([number, suit]);
      });
    });

    commit(mutationTypes.SET_DECK, await dispatch(actionTypes.SHUFFLE_DECK, deck));
  },

  [actionTypes.SHUFFLE_DECK]({state, commit}, deck) {
    const shuffleArray = arr => arr
      .map((a) => ({sort: Math.random(), value: a}))
      .sort((a, b) => a.sort - b.sort)
      .map((a) => a.value);
    
    return shuffleArray(deck);
  },

  async [actionTypes.DEAL_CARD]({state, commit, dispatch}) {
    if (!state.deck.length) {
      commit(mutationTypes.SET_DECK, await dispatch(actionTypes.SHUFFLE_DECK, state.dead));
      commit(mutationTypes.SET_DEAD_STACK, []);
    }
    const hand = [...state.hand, ...state.deck.splice(0, 1)];

    commit(mutationTypes.SET_DECK, state.deck);
    commit(mutationTypes.SET_HAND, hand);
  },

  [actionTypes.REMOVE_FROM_HAND]({state, commit}, args) {
    const dead = [...state.dead, ...args.selectedCards];
    commit(mutationTypes.SET_HAND, args.remainingCards);
    commit(mutationTypes.SET_DEAD_STACK, dead);
  },

  async [actionTypes.RESET_HAND]({state, commit, dispatch}) {
    const dead = [...state.dead, ...state.hand];
    const newDeck = await dispatch(actionTypes.SHUFFLE_DECK, [...state.deck, ...dead]);

    //commit(mutationTypes.SET_DEAD_STACK, dead);
    commit(mutationTypes.SET_DEAD_STACK, []);
    commit(mutationTypes.SET_DECK, newDeck);
    commit(mutationTypes.SET_HAND, []);
  },

  [actionTypes.PLACE_BET]({state, commit}, amount) {
    let total = state.bet + amount;
    if(total > 5) {
      total = 5;
    }
    if(total < 0){
      total = 0;
    }
    commit(mutationTypes.SET_BET, total);
  },

  [actionTypes.PLAY_HAND]({state, commit}){
    const credits = state.credits - state.bet;
    commit(mutationTypes.SET_CREDITS, credits);
    commit(mutationTypes.SET_WINNINGS, 0);
    commit(mutationTypes.SET_PAYLINE, null);
  },

  [actionTypes.FINALIZE]({state, commit}){
    const update = payLine => {
      const winnings = state.payTable.find(p => p.id === payLine).multiplier * state.bet;
      commit(mutationTypes.SET_PAYLINE, payLine);
      commit(mutationTypes.SET_WINNINGS, winnings);
      commit(mutationTypes.SET_CREDITS, state.credits + winnings);
    };

    const suits = state.hand.map(c => c[1]);
    const faces = state.hand.map(c => c[0]);

    // flush
    const hasFlush = suits.every((val, i, arr) => val === arr[0]);

    // straight
    faces.sort((a, b) => a - b);
    let hasStraight = faces.every((val, i, arr) => i === arr.length - 1 || val + 1 === arr[i + 1]);
    if(!hasStraight && !faces[0]){
      let i = 1;
      while(i < 5){
        if(faces[i] !== i + 8){
          break;
        }
        i++;
      }

      hasStraight = i === 5;
    }

    // straight flush
    const hasStraightFlush = hasFlush && hasStraight;

    // royal flush
    const hasRoyalFlush = hasStraightFlush && faces[4] === 12 && faces[0] === 0;
    if(hasRoyalFlush){
      update(payLines.ROYAL_FLUSH);
      return;
    }

    if(hasStraightFlush){
      update(payLines.STRAIGHT_FLUSH);
      return;
    }

    // 4 of a kind
    const hasFourOfAKind = faces[0] === faces[3] || faces[1] === faces[4];
    if(hasFourOfAKind){
      update(payLines.FOUR_OF_A_KIND);
      return;
    }

    // full house
    const hasFullHouse = (faces[0] === faces[1] && faces[2] === faces[4]) || (faces[0] === faces[2] && faces[3] === faces[4]);
    if(hasFullHouse){
      update(payLines.FULL_HOUSE);
      return;
    }

    if(hasFlush){
      update(payLines.FLUSH);
      return;
    }

    if(hasStraight){
      update(payLines.STRAIGHT);
      return;
    }

    // 3 of a kind
    const hasThreeOfAKind = faces[0] === faces[2] || faces[1] === faces[3] || faces[2] === faces[4];
    if(hasThreeOfAKind){
      update(payLines.THREE_OF_A_KIND);
      return;
    }

    // 2 pair
    const hasTwoPair = (faces[0] === faces[1] && faces[2] === faces[3]) || (faces[0] === faces[1] && faces[3] === faces[4]) || (faces[1] === faces[2] && faces[3] === faces[4]);
    if(hasTwoPair){
      update(payLines.TWO_PAIR);
      return;
    }

    // jacks or better
    const hasPair = (arr => {
      for(let i=0; i<arr.length - 1; i++){
        if(arr[i] === arr[i+1] && (arr[i] > 9 || arr[i] === 0)){
          return true;
        }
      }
      return false;
    })(faces);
    if(hasPair){
      update(payLines.PAIR);
    }
  }
};

const mutations = {
  [mutationTypes.SET_HAND](state, hand) {
    state.hand = hand;
  },

  [mutationTypes.SET_DECK](state, deck) {
    state.deck = deck;
  },

  [mutationTypes.SET_DEAD_STACK](state, dead) {
    state.dead = dead;
  },

  [mutationTypes.SET_BET](state, amount){
    state.bet = amount;
  },

  [mutationTypes.SET_CREDITS](state, credits){
    state.credits = credits;
  },

  [mutationTypes.SET_GAMESTATE](state, gameState){
    state.gamestate = gameState;
  },

  [mutationTypes.SET_PAYLINE](state, payLine){
    state.payLine = payLine;
  },

  [mutationTypes.SET_WINNINGS](state, winnings){
    state.winnings = winnings;
  }
};

const state = {
  hand: [],
  deck: [],
  dead: [],
  payTable: [
    { id: payLines.PAIR, name: 'Jacks or Better', multiplier: 1 },
    { id: payLines.TWO_PAIR, name: '2 Pair', multiplier: 2 },
    { id: payLines.THREE_OF_A_KIND, name: '3 of a Kind', multiplier: 3 },
    { id: payLines.STRAIGHT, name: 'Straight', multiplier: 4 },
    { id: payLines.FLUSH, name: 'Flush', multiplier: 5 },
    { id: payLines.FULL_HOUSE, name: 'Full House', multiplier: 8 },
    { id: payLines.FOUR_OF_A_KIND, name: '4 of a Kind', multiplier: 25 },
    { id: payLines.STRAIGHT_FLUSH, name: 'Straight Flush', multiplier: 50 },
    { id: payLines.ROYAL_FLUSH, name: 'Royal Flush', multiplier: 250 }
  ],
  bet: 0,
  credits: 100,
  gamestate: gamestates.READY,
  winnings: 0,
  payLine: null
};

Vue.component('bet', {
  computed: {
    ...Vuex.mapState([
      'bet',
      'gamestate'
    ]),
    canEnableBets() {
      return this.gamestate === gamestates.READY;
    }
  },
  methods: {
    ...Vuex.mapActions([actionTypes.PLACE_BET]),
    placeBet(amount){
      this[actionTypes.PLACE_BET](amount);
    }
  },
  template: `
    <div class="bet">
      <div class="hud-title">Bet</div>
      <div>
        <span class="bet__button"><button type="button" @click="placeBet(-1)" :disabled="!canEnableBets" :class="{'bet__button--disabled': !canEnableBets}">-</button></span>
        <div class="bet__amount">{{bet}}</div>
        <span class="bet__button"><button type="button" @click="placeBet(1)" :disabled="!canEnableBets" :class="{'bet__button--disabled': !canEnableBets}">+</button></span>
      </div>
    </div>`
});

Vue.component('card', {
  props: ['card'],
  template: `
    <div class="card">
      <div class="card__back"></div>
      <div :class="\`card__front card-$\{card[0]\}-$\{card[1]\}\`" rel="preload"></div>
    </div>`
});

Vue.component('controls', {
  computed: {
    ...Vuex.mapState([
      'bet',
      'gamestate'
    ]),
    canDraw(){
      return (this.gamestate === gamestates.READY || this.gamestate === gamestates.SWAP) && this.bet > 0;
    }
  },
  template: `
    <div class="controls">
      <bet></bet>
      <button class="deal-button" type="button" @click="$emit('deal')" :disabled="!canDraw" :class="{ 'deal-button-can-draw': canDraw }">Deal</button>
    </div>`
});

Vue.component('credits', {
  props:[
    'title',
    'value'
  ],
  data() {
    return {
      wide: false
    }
  },
  watch: {
    title: {
      immediate: true,
      handler(newVal) {
        if(newVal.length > 7){
          this.wide = true;
        }
      }
    }
  },
  template: `
    <div :class="['credits', { 'credits--wide': wide }]">
      <div class="hud-title">{{title}}</div>
      <div class="credits__amount">{{value}}</div>
    </div>`
});

Vue.component('deck', {
  computed: {
    ...Vuex.mapState([
      'deck'
    ])
  },
  methods: {
    shouldHide(n){
      return false; //n*4 > Math.ceil(this.deck.length/4)*4;
    }
  },
  template: `
    <div class="deck">
      <template v-for="n in 13">
        <div :class="{ hide: shouldHide(n) }"></div>
      </template>
    </div>`
});

Vue.component('score-table', {
  computed: {
    ...Vuex.mapState([
      'payTable',
      'payLine'
    ])
  },
  template: `
    <div class="score-table">
      <div class="hud-title">Score Table</div>
      <div class="score-table__line">
        <div class="score-table__line__name">Bet</div>
        <div class="score-table__line__pay" v-for="n in 5">{{n}}</div>
      </div>
      <template v-for="line in payTable.slice().reverse()">
        <div class="score-table__line" :class="{'score-table__line--win' : line.id === payLine}">
          <div class="score-table__line__name">{{line.name}}</div>
          <div class="score-table__line__pay" v-for="n in 5">{{line.multiplier*n}}</div>
        </div>
      </template>
      <div></div>
    </div>`
});

const game = Vue.component('game', {
  data() {
    return {
      cards: [],
      loaded: false
    };
  },
  computed: {
    ...Vuex.mapState([
      'hand',
      'deck',
      'dead',
      'gamestate',
      'credits',
      'winnings'
    ])
  },
  created() {
    this[actionTypes.INITIALIZE_DECK]();
  },
  mounted() {
    const cards = new Image();
    cards.onload = () => {
      this.loaded = true;
    }
    cards.src = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/1443237/cards.png';
    const back = new Image();
    back.src = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/1443237/back.png';
  },
  methods: {
    ...Vuex.mapActions([
      actionTypes.INITIALIZE_DECK,
      actionTypes.SHUFFLE_DECK,
      actionTypes.DEAL_CARD,
      actionTypes.REMOVE_FROM_HAND,
      actionTypes.RESET_HAND,
      actionTypes.PLAY_HAND,
      actionTypes.FINALIZE]),
    ...Vuex.mapMutations([mutationTypes.SET_CREDITS, mutationTypes.SET_GAMESTATE]),
    
    async deal(){
      if(this.gamestate === gamestates.READY) {
        this.selected = [];
        this[mutationTypes.SET_GAMESTATE](gamestates.DEALING);
        this[actionTypes.PLAY_HAND]();
        if(this.hand.length) {
          const elems = this.cards.map(card => this.$refs[`${card.card[0]}-${card.card[1]}`]);
          gsap.killTweensOf(elems);
          gsap.to(elems, { scale: 1, duration: 0.2, onComplete: () => this[actionTypes.RESET_HAND]() });
        } else {
          this[actionTypes.DEAL_CARD]();
        }
        return;
      }

      if(this.gamestate === gamestates.SWAP){
        this.swap();
      }
    },
    selectCard(i){
      if(this.gamestate === gamestates.SWAP){
        this.cards[i].selected = !this.cards[i].selected;
      }
    },
    swap(){
      this[mutationTypes.SET_GAMESTATE](gamestates.SWAPPING);
      const remainingCards = this.cards.filter(x => x.selected).map(x => x.card);
      const selectedCards = this.cards.filter(x => !x.selected).map(x => x.card);
      if(!selectedCards.length){
        this.finalizeHand();
      }
      this[actionTypes.REMOVE_FROM_HAND]({ selectedCards, remainingCards });
    },
    finalizeHand(){
      this[actionTypes.FINALIZE]();
      this[mutationTypes.SET_GAMESTATE](gamestates.READY);
    },
    addCardToHand(card, index){
      const elem = this.$refs[`${card[0]}-${card[1]}`];
      if(elem) {
        const end = 200 * index + 20 * index;
        const timeline = new TimelineLite({
          onComplete: () => {
            if(this.cards.length < 5){
              this[actionTypes.DEAL_CARD]();
              return;
            }
            if(this.gamestate === gamestates.DEALING){
              this[mutationTypes.SET_GAMESTATE](gamestates.SWAP);
              return;
            }
            if(this.gamestate === gamestates.SWAPPING){
              this.finalizeHand();
            }
          }
        });
        const startZ = 51;//Math.ceil(this.deck.length/4)*4;
        timeline.set(elem, {x:1180, z:startZ, rotateY: 180, opacity: 1});
        timeline.to(elem, 0.2, {z:startZ + 150}).to(elem, 0.6, {x:end, rotateY: 0, z:0});
      }
    },
    moveCards(){
      const elems = this.cards.map(card => this.$refs[`${card.card[0]}-${card.card[1]}`]);
      let removed =0;
      for(let i=0; i<this.cards.length; i++){
        const timeline = new TimelineLite({ 
          onComplete: () => {
            if(removed === elems.length - 1){
              if(this.cards.length < 5){
                this[actionTypes.DEAL_CARD]();
              }
            } else {
              removed++;
            }
          }
        });
        const end = 200 * i + 20 * i;
        timeline.to(elems[i], 0.6, {x:end});
      }
    },
    removeCardFromHand(removedCards, newCards){
      const elems = removedCards.map(card => this.$refs[`${card[0]}-${card[1]}`]);
      const timeline = new TimelineLite({
        onComplete: () => {
          this.cards = newCards.map(card => ({ card, selected: false }));
          this.$nextTick(() => this.moveCards());
        }
      });
      timeline.to(elems, 0.2, {rotateY: 180}).to(elems, 0.2, {x:1180, delay:0.1});
    },
    removeAll(){
      const elems = this.cards.map(card => this.$refs[`${card.card[0]}-${card.card[1]}`]);
      const timeline = new TimelineLite({
        onComplete: () => {
          this.cards = [];
          if(this.gamestate === gamestates.SWAPPING || this.gamestate === gamestates.DEALING){
            this[actionTypes.DEAL_CARD]();
          }
        }
      });
      timeline.to(elems, 0.2, {rotateY: 180}).to(elems, 0.2, {x:1180, delay:0.1});
    }
  },
  watch: {
    hand(newVal, oldVal){
      if (!newVal.length) {
        this.removeAll();
        return;
      }

      if(newVal.length > oldVal.length) {
        const card = newVal[newVal.length -1];
        this.cards.push({ card, selected: false});
        this.$nextTick(() => {
          this.addCardToHand(card, newVal.length - 1);
        });
        return;
      }
      this.removeCardFromHand(oldVal.filter(oldCard => !newVal.includes(oldCard)), newVal);
    }
  },
  template:`
    <div class="game">
      <div class="game__display">
        <score-table></score-table>
        <div class="hud">
          <div><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1443237/logo.png"/> Slot Poker</div>
          <credits title="Winnings" :value="winnings"></credits>
          <credits title="Credits" :value="credits"></credits>
          <controls v-if="loaded" @deal="deal"></controls>
          <div v-else class="loading">Loading <span class="dots">.</span><span class="dots">.</span></div>
        </div>
      </div>
      <div class="game__main">
        <div class="hand" ref="hand">
          <div v-for="(card, i) in cards" @click="selectCard(i)" 
              :class="['hand__card', { selected: card.selected }]" 
              :key="\`$\{card.card[0]\}-$\{card.card[1]\}\`" :ref="\`$\{card.card[0]\}-$\{card.card[1]\}\`">
            <card :card="card.card" />
          </div>
        </div>
        <deck></deck>
      </div>
    </div>`
});

new Vue({
  el: '#game',
  store: new Vuex.Store({state,actions,mutations}),
  render(h){
    return h(game);
  }
});

              
            
!
999px

Console