Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                #app
  .block_area
    .block(v-for="(b,bid) in blocks",
           :class="{circle: b.type==1,cross: b.type==-1}",
           @click="player_go(b)")
      .small_num {{bid+1}}
  ul.debug_list
    li(v-for="wdata in pattern_data") {{wdata.pattern}}: {{wdata.value}}
    
  br
  h1 {{who_win}}
  .block.turn_block(:class="{circle: turn==1,cross: turn==-1}",
         @click="player_go(b)")
  .btn(v-if="who_win.length!=0",
       @click="restart") Restart
  
              
            
!

CSS

              
                $color_blue: #46f
$color_red: #f35
$block_size: 100px

@mixin size($w,$h:$w)
  width: $w
  height: $h
  
html,body,#app
  display: flex
  justify-content: center
  align-items: center
  background-color: #111
  flex-direction: column
  color: white
  +size(100%)

.block_area
  display: flex
  flex-wrap: wrap
  +size($block_size*3)
  
//每一個方塊
.block
  +size($block_size)
  box-sizing: border-box
  padding: 20px
  // border: solid 1px
  position: relative
  cursor: pointer
  border: solid 1px #333
  transition: 0.5s
  
  &:hover
    background-color: rgba(white,0.05)
  
  &.none
    &:before,&:after
      +size(0)

  &:before,&:after
    content: ""
    transition: 0.5s
    transform-origin: center center
    position: absolute
    transform: translate(-50%,-50%)
    left: 50%
    top: 50%
  
  &.circle
    &:before
      +size(90%)
      background-color: $color_red
      border-radius: 50%
    &:after
      +size(60%)
      background-color: #111
      border-radius: 50%

  &.cross
    &:after,&:before
      +size(90%,15%)
      background-color: $color_blue
      border-radius: 0px
    &:before
      transform: translate(-50%,-50%) rotate(135deg)
    &:after
      transform: translate(-50%,-50%) rotate(45deg)
  
.btn
  font-size: 30px
  border-bottom: solid 4px white
  cursor: pointer
  position: fixed
  left: 50%
  bottom: 30px
  transform: translateX(-50%)
  &:hover
    color: #eee
  
.debug_list
  position: absolute
  right: 10px
  top: 10px
  list-style: none
  padding: 0
  opacity: 0.4
  
.small_num 
  opacity: 0.2 
  
.turn_block
  +size(40px)
              
            
!

JS

              
                var vm = new Vue({
  el: "#app",
  data: {
    blocks: [],
    turn: -1
  },
  mounted(){
    this.restart()
  },
  methods: {
    player_go(block){
      // if (block.type==0){
        block.type=this.turn
        this.turn=-this.turn
      // }else{
      //   alert("Block has value!")
      // }
    },
    restart(){
      this.blocks=Array.from({length: 9},()=>({
        type: 0
      }))
    }
  },
  computed:{
    pattern_data(){
      var verify_list = "123,456,789,147,258,369,159,357"
      var results=
        verify_list.split(",")
          .map((vtext)=>{
            var result= this.blocks
            .filter((d,i)=>vtext.indexOf(i+1)!=-1)
            .map(o=>o.type)
            .reduce((a,b)=>(a+b),0)
            return {pattern: vtext,value: result}
          })
          ;
      return results
    },
    who_win(){
      var results= this.pattern_data.filter(o=>Math.abs(o.value)==3)
      if (results.length>0){
        return (results[0].value>0?"O":"X") + " Wins!"
      }else{
        return "Player:"
      }
      
      return results
    }
  }
})
              
            
!
999px

Console