사용자:Jinhoftyu/백괴던전.js: 두 판 사이의 차이
편집 요약 없음 |
편집 요약 없음 |
||
23번째 줄: | 23번째 줄: | ||
var item = []; | var item = []; | ||
var log = ""; | var log = ""; | ||
var console = document.getElementById("console"); | |||
function refLog() { | function refLog() { | ||
var size = 0; | var size = 0; | ||
34번째 줄: | 35번째 줄: | ||
log.delete(0, index); | log.delete(0, index); | ||
} | } | ||
console.innerHTML = log; | |||
} | } | ||
var map = document.getElementById("map"); | var map = document.getElementById("map"); | ||
70번째 줄: | 72번째 줄: | ||
document.addEventListener('keydown', function(event) { | document.addEventListener('keydown', function(event) { | ||
if (event.code === 'KeyL' && plx < mapX - 2) { | if (event.code === 'KeyL' && plx < mapX - 2) { | ||
move(0, 1); | |||
plx++; | plx++; | ||
} | } | ||
83번째 줄: | 86번째 줄: | ||
refreshMap(); | refreshMap(); | ||
}); | }); | ||
function move(dx, dy) { | |||
if (base[ply + dy][plx + dx] != '#') { | |||
turn(); | |||
plx += dx; | |||
ply += dy; | |||
var floor = base[y][x]; | |||
if (floor != '.' && floor != '\0') { | |||
log += "You are standing in " + floorDes(floor) + ".\n"; | |||
} | |||
} | |||
} | |||
function turn() { | |||
time++; | |||
} | |||
function floorDes(c) { | |||
var s; | |||
switch (c) { | |||
case "<": | |||
s = "staircase leading upward"; | |||
break; | |||
case "<": | |||
s = "staircase leading downward"; | |||
break; | |||
default: | |||
s = "nothing"; | |||
} | |||
return s; | |||
} | |||
mapGen(); | mapGen(); | ||
refreshMap(); | refreshMap(); | ||
refLog(); |
2023년 10월 25일 (수) 14:42 판
var mapX = 40;
var mapY = 10;
var base = new Array(mapY);
for (var i = 0; i < base.length; i++) {
base[i] = new Array(mapX);
}
function mapGen() {
for (var y = 0; y < mapY; y++) {
for (var x = 0; x < mapX; x++) {
if (y == 0 || y == mapY - 1 || x == 0 || x == mapX - 1) {
base[y][x] = "#";
} else if (x == 1 && y == 1) {
base[y][x] = "<";
} else if (x == mapX - 2 && y == mapY - 2) {
base[y][x] = ">";
} else {
base[y][x] = ".";
}
}
}
}
var entity = [];
var item = [];
var log = "";
var console = document.getElementById("console");
function refLog() {
var size = 0;
for (var i = 0; i < log.length; i++) {
if (log.charAt(i) == "\n") {
size++;
}
}
if (size > 3) {
var index = log.indexOf("\n") + 1;
log.delete(0, index);
}
console.innerHTML = log;
}
var map = document.getElementById("map");
var plx = 1;
var ply = 1;
function refreshMap() {
var temp = "";
for (var y = 0; y < mapY; y++) {
for (var x = 0; x < mapX; x++) {
var floor = base[y][x];
var s = " ";
if (floor != "\0") {
s = floor;
}
if (plx == x && ply == y) {
s = "@";
}
temp += s;
}
temp += "<br />";
}
map.innerHTML = temp;
}
var stats = document.getElementById("stats");
var name = "Jinhoftyu";
var role = "Wizard";
var time = 0;
var level = 1;
var xl = 1;
var hp = 15;
var maxhp = 15;
var pw = 10;
var maxpw = 10;
var temp2 = name + " the " + role + " t:" + time + "\nDlvl:" + level + " Lv:" + xl + " HP:" + hp + "/" + maxhp + " Pw:" + pw + "/" + maxpw;
stats.innerHTML = temp2;
document.addEventListener('keydown', function(event) {
if (event.code === 'KeyL' && plx < mapX - 2) {
move(0, 1);
plx++;
}
if (event.code === 'KeyH' && plx > 1) {
plx--;
}
if (event.code === 'KeyK' && ply < mapY - 2) {
ply++;
}
if (event.code === 'KeyJ' && ply > 1) {
ply--;
}
refreshMap();
});
function move(dx, dy) {
if (base[ply + dy][plx + dx] != '#') {
turn();
plx += dx;
ply += dy;
var floor = base[y][x];
if (floor != '.' && floor != '\0') {
log += "You are standing in " + floorDes(floor) + ".\n";
}
}
}
function turn() {
time++;
}
function floorDes(c) {
var s;
switch (c) {
case "<":
s = "staircase leading upward";
break;
case "<":
s = "staircase leading downward";
break;
default:
s = "nothing";
}
return s;
}
mapGen();
refreshMap();
refLog();