HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="寶可夢對戰.css">
</head>
<br>
<body>
<script src="對戰成功檔1.js"></script>
<div class= "wid" align= "center">
<br>
<div class="monster">
<img id =" " class ="img" width="450" height="450"></a>
<div class="blood"><span id="currentHP">?</span></div>
<div class="monstermp" id="hempz">?</div>
</div>
<br>
<div class = "about" id ="hedata">
<emhp>血量:?</emhp>
<emmp>魔力:?</emmp>
<ematk>攻擊:?</ematk>
<emspd>速度:?</emspd>
<emdef>防禦:?</emdef>
</div >
</div>
<div class="data">
<br>
<div class="about" id ="usdata">
<p id="ushp">血量:?</p>
<p id="usmp">魔力:?</p>
<p id="usatk">攻擊:?</P>
<p id="usspd">速度:?</P>
<p id="usdef">防禦:?</P>
</div>
<div class="summary">
<button class ="myhero" onclick="start()">
<img class = "img" src="" width="100" height="100"></button>
<br><br><br>
<button id="damageButton">直接攻擊</button>
<button id="fireball">爆裂火球</button>
<button id="damageButton">龍息爆氣</button>
<button id="damageButton">龍之亂抓</button>
<button id="damageButton">祭龍血咒</button>
</div>
<div class="HP"><span id="playerHP">?</span></div>
<div class="MP" id="usmpz">?</div>
<div id="log" class="scrollen"></div>
</div>
</body>
</html>
body {
background-color:rgb(250, 251, 249);
width: 100%;
height:100%;
display: flex;
}
.wid{
width: 80%;
height: 50%;
background-color: rgb(255, 255, 254);
border: 3px solid rgb(168, 160, 160);
border-radius: 15px 15px 15px 15px;
margin-left: 1%;
}
button{
color:aliceblue;
background-color:rgb(26, 57, 119);
border:3px solid rgb(130, 128, 128);
color:white;
padding:10px 20px 10px 20px;
border-radius:10px 10px 10px 10px;
margin: 3px;
}
button:active{
color:aliceblue;
background-color:rgb(108, 135, 189);
border:3px solid rgb(130, 128, 128);
color:white;
padding:10px 20px 10px 20px;
display: inline-flex;
text-align:center;
border-radius:10px 10px 10px 10px;
}
.summary{
font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
height: 150%;
height: 150px;
display: flexbox;
margin-top: 30px;
}
.HP{
color: #f7f5f4;
border: 10px rgb(215, 205, 205) solid;
border-radius: 30px;
background-color: red;
width: 20%;
text-align: center;
margin-left: 2%;
}
.MP{
color: #fcfdfd;
border: 10px rgb(215, 205, 205) solid;
border-radius: 30px;
background-color: rgb(59, 132, 227);
width: 20%;
margin-left: 2%;
}
.monster{
.blood{
height: 20px;
background-color: #FF0000;
width: 70%;
border-radius: 200px;
border: rgb(192, 185, 176) 5px solid;
color: white;
}
}
.monstermp{
height: 20px;
background-color: #255e97;
width: 70%;
border-radius: 200px;
border: rgb(192, 185, 176) 5px solid;
color: white;
}
img
{
border: rebeccapurple 5px solid;
border-radius: 30px;
}
.uspic
{
width: 90px;
height:90px;
}
.myhero{
float: left;
margin-left: 3%;
}
.scrollen{
overflow: scroll;
}
.data{
width: 100%;
height: 100%;
height: 600px;
background-color: rgb(255, 255, 254);
border: 3px solid rgb(168, 160, 160);
border-radius: 15px 15px 15px 15px;
margin-left: 1%;
margin-right: 3%;
overflow: scroll;
text-align: center;
}
flex{
display: flex;
flex-direction: column;
}
.about{
background-color:gray;
color: white;
}
window.addEventListener('DOMContentLoaded', () => {
console.log = (...e) => {
for (var i = 0; i < e.length; i++) {
log.innerHTML += (typeof(e[i]) == "object" ? JSON.stringify(e[i]) : e[i]) + "<br/>";
}
};
// Check if both Pikachu and Charmander have HP greater than 0
var hero = [
pikachu = {
hp: [190, 190], // HP(血量): 現在剩餘/總量
mp: [200, 200], // MP(法力): 現在剩餘/總量
def: 20, // 防禦力,決定被攻擊後會損多少血
atk: 30,
Moves: [ // 角色會的招式
{
MoveName: "直接攻擊",
Cost: 10 // 招式所消耗法力
},
{
MoveName: "爆裂火球",
Cost: 100
}
]
},
light = {
hp: [300, 300],
mp: [130, 130],
def: 20,
atk: 10,
Moves: [
{
MoveName: "御劍術",
Cost: 10
}
]
}
];
var mo_me = 0;
var mo_he = 1;
var playerHP = hero[mo_me].hp[1];
var currentHP = hero[mo_he].hp[1];
var theusmp = hero[mo_me].mp[1];
var thehemp = hero[mo_he].mp[1];
var ushper= document.getElementById("playerHP");
function ushpnow(){
ushper.textContent = playerHP;
}
var currentHPElement = document.getElementById("currentHP");
function updateHPDisplay() {
currentHPElement.textContent = currentHP;
}
var usmper= document.getElementById("usmpz");
function usmpnow(){
usmper.textContent = theusmp;
}
var hemper= document.getElementById("hempz");
function hempnow(){
hemper.textContent = thehemp;
}
const damageButton = document.getElementById("damageButton");
var heelement = document.getElementById("hedata");
// 宣告多個非字串參數
var hehp = hero[mo_he].hp[0];
var hemp= hero[mo_he].mp[0];
var hedef = hero[mo_he].def;
var heatk = hero[mo_he].atk;
// 使用拼接文本將多個值並排顯示在元素中
heelement.textContent = "血量:("+hehp + " )魔力:(" + hemp + ")防禦力:("+hedef +")攻擊力:(" + heatk+")";
var uselement = document.getElementById("usdata");
// 宣告多個非字串參數
var ushp = hero[mo_me].hp[0];
var usmp= hero[mo_me].mp[0];
var usdef = hero[mo_me].def;
var usatk = hero[mo_me].atk;
// 使用拼接文本將多個值並排顯示在元素中
uselement.textContent = "血量:("+ushp + " )魔力:(" + usmp + ")防禦力:("+usdef +")攻擊力:(" + usatk+")";
document.getElementById("damageButton").addEventListener("click", function(){
takeDamage();
enemyAttack();
turn();
function takeDamage() {
if (currentHP > 0 && theusmp >= 100) {
currentHP -= hero[mo_me].atk;
theusmp -= 10;
console.log("<hr>敵方受到"+hero[mo_me].atk+"傷害,血量剩餘"+currentHP)
if (theusmp < 10){
damageButton.disabled=true;
}
if (currentHP <= 0) {
currentHP = 0;
console.log("<hr>我方獲勝")
damageButton.disabled = true; // 停用攻擊按鈕
}
updateHPDisplay();
usmpnow();
}
}
function enemyAttack() {
if (playerHP > 0 && thehemp >= 10){
playerHP -= hero[mo_he].atk;
thehemp -= 10;
console.log("我方受到"+hero[mo_he].atk+"傷害,血量剩餘"+playerHP)
if (thehemp < 10){
damageButton.disabled=true;
}
if (playerHP <= 0) {
playerHP = 0;
console.log("<hr>敵方獲勝")
damageButton.disabled = true;
}
hempnow()
ushpnow();
}
}
function turn() {
if (theusmp <= 0) {
theusmp += 30;
} else if (theusmp > hero[mo_me].mp[0]) {
theusmp = hero[mo_me].mp[0];
}
if (thehemp <= 0) {
thehemp += 30;
} else if (thehemp > hero[mo_he].mp[0]) {
thehemp = hero[mo_he].mp[0];
}
hempnow()
usmpnow()
}
})});
Also see: Tab Triggers