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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <div id="app">
    <section class="row">
        <div class="small-6 columns">
            <h1 class="text-center">YOU</h1>
            <div class="healthbar">
                <div class="healthbar text-center" style="background-color: green; margin: 0; color: white;" :style="{width: youHealth + '%'}">
{{youHealth}}
                </div>
            </div>
        </div>
        <div class="small-6 columns">
            <h1 class="text-center">MONSTER</h1>
            <div class="healthbar">
                <div class="healthbar text-center" style="background-color: green; margin: 0; color: white;" :style="{width: monsterHealth + '%'}">
{{monsterHealth}}</div>
            </div>
        </div>
    </section>
    <section class="row controls" v-show="!started">
        <div class="small-12 columns">
            <button id="start-game" @click="started = !started">START NEW GAME</button>
        </div>
    </section>
    <section class="row controls" v-show="started">
        <div class="small-12 columns">
            <button id="attack" @click="attack">ATTACK</button>
            <button id="special-attack" @click="specialAttack">SPECIAL ATTACK</button>
            <button id="heal" @click="heal">HEAL</button>
            <button id="give-up" @click="reset">GIVE UP</button>
        </div>
    </section>
    <section class="row log" v-show="attackLogs.length > 0">
        <div class="small-12 columns">
            <ul>
                <li 
					v-for="log in attackLogs"
					:class="[{'player-turn': log.isPlayer}, {'monster-turn': !log.isPlayer}]">
					{{ log.text }}					
                </li>
            </ul>
        </div>
    </section>
</div>
              
            
!

CSS

              
                .text-center {
    text-align: center;
}

.healthbar {
    width: 80%;
    height: 40px;
    background-color: #eee;
    margin: auto;
    transition: width 500ms;
}

.controls, .log {
    margin-top: 30px;
    text-align: center;
    padding: 10px;
    border: 1px solid #ccc;
    box-shadow: 0px 3px 6px #ccc;
}

.turn {
    margin-top: 20px;
    margin-bottom: 20px;
    font-weight: bold;
    font-size: 22px;
}

.log ul {
    list-style: none;
    font-weight: bold;
    text-transform: uppercase;
}

.log ul li {
    margin: 5px;
}

.log ul .player-turn {
    color: blue;
    background-color: #e4e8ff;
}

.log ul .monster-turn {
    color: red;
    background-color: #ffc0c1;
}

button {
    font-size: 20px;
    background-color: #eee;
    padding: 12px;
    box-shadow: 0 1px 1px black;
    margin: 10px;
}

#start-game {
    background-color: #aaffb0;
}

#start-game:hover {
    background-color: #76ff7e;
}

#attack {
    background-color: #ff7367;
}

#attack:hover {
    background-color: #ff3f43;
}

#special-attack {
    background-color: #ffaf4f;
}

#special-attack:hover {
    background-color: #ff9a2b;
}

#heal {
    background-color: #aaffb0;
}

#heal:hover {
    background-color: #76ff7e;
}

#give-up {
    background-color: #ffffff;
}

#give-up:hover {
    background-color: #c7c7c7;
}
              
            
!

JS

              
                new Vue({
	el: '#app',
	data: {
		started: false,
		youHealth: 100,
		monsterHealth: 100,
		attackLogs: []
	},
	watch: {
		monsterHealth: function(value){
			if (value <= 0) {
				this.reset();	
				if (confirm('You won! Start again?')) {
					this.started = true
				}
			}
		},
		youHealth: function(value){
			if (value <= 0) {
				this.reset();	
				if (confirm('You are dead, start again?')) {
					this.started = true
				}
			}
		}	
	},
	methods: {
		reset: function() {
			this.youHealth = 100;
			this.monsterHealth = 100;
			this.started = false;
			this.attackLogs = [];
		},
		numberRand: function(min, max) {
			return Math.floor(Math.random() * max) + min
		},
		monsterAttack: function() {
			var dmg = this.numberRand(0, 15)
			this.youHealth -= dmg
			var log = dmg > 0 ? 'The Monster dealt ' + dmg + ' damage!' : 'The Monster missed! 0 damage!'
			this.attackLogs.unshift({
				isPlayer: false,
				text: log
			})
		},
		attack: function() {
			var dmg = this.numberRand(0, 10)
			this.monsterHealth -= dmg
			var log = dmg > 0 ? 'You dealt ' + dmg + ' damage!' : 'Miss! 0 damage!'
			this.attackLogs.unshift({
				isPlayer: true,
				text: log
			})
			this.monsterAttack()
		},
		heal: function() {
			var dmg = 20
			var health = this.youHealth
			if (health == 100) {
				var log = 'You\'re at full health!'
				this.attackLogs.unshift({
					isPlayer: true,
					text: log
				})
			}
			else {
				if (health >= 80) {
					dmg = 100 - health
				}
				this.youHealth += dmg
				var log = dmg > 0 ? 'You healed ' + dmg + ' points' : this.heal()
				this.attackLogs.unshift({
					isPlayer: true,
					text: log
				})
				this.monsterAttack()
			}
		},
		specialAttack: function() {
			var dmg = this.numberRand(0, 25)
			this.monsterHealth -= dmg
			var log = dmg > 0 ? 'Your special attack dealt ' + dmg + ' damage!' : 'Miss! 0 damage!'
			this.attackLogs.unshift({
				isPlayer: true,
				text: log
			})
			this.monsterAttack()
		}
	}
})
              
            
!
999px

Console