사용자:Jinhoftyu/백괴던전.js: 두 판 사이의 차이

리버티게임, 모두가 만들어가는 자유로운 게임
편집 요약 없음
편집 요약 없음
 
(같은 사용자의 중간 판 32개는 보이지 않습니다)
1번째 줄: 1번째 줄:
var mapX = 20;
var mapX = 40;
var mapY = 10;
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) == "<br />") {
            size++;
        }
    }
if (size > 3) {
        log = log.substring(log.indexOf("<br />") + 1);
    }
console.innerHTML = log;
stats.innerHTML = temp2;
}
var map = document.getElementById("map");
var map = document.getElementById("map");
var x = 1;
var plx = 1;
var y = 1;
var ply = 1;
function refreshMap() {
function refreshMap() {
var temp = "";
var temp = "";
for (var i = 0; i < mapY; i++) {
for (var y = 0; y < mapY; y++) {
if (i == 0 || i == mapY - 1) {
        for (var x = 0; x < mapX; x++) {
temp += "#".repeat(mapX) + "<br />";
                var floor = base[y][x];
} else if (i == y) {
                var s = " ";
temp += "#" + ".".repeat(x - 1) + "@" + ".".repeat(mapX - x - 2) + "#<br />";
                if (floor != "\0") {
} else {
                    s = floor;
temp += "#" + ".".repeat(mapX - 2) + "#<br />";
                }
}
                if (plx == x && ply == y) {
temp += x + "," + y;
                    s = "@";
                }
                temp += s;
            }
            temp += "<br />";
        }
map.innerHTML = temp;
map.innerHTML = temp;
}
}
27번째 줄: 68번째 줄:
var pw = 10;
var pw = 10;
var maxpw = 10;
var maxpw = 10;
var temp2 = name + " the " + role + " t:" + time + "\nDlvl:" + level + " Lv:" + xl + " HP:" + hp + "/" + maxhp + " Pw:" + pw + "/" + maxpw;
var temp2 = name + " the " + role + " t:" + time + "<br />Dlvl:" + level + " Lv:" + xl + " HP:" + hp + "/" + maxhp + " Pw:" + pw + "/" + maxpw;
stats.innerHTML = temp2;
stats.innerHTML = temp2;
}
document.addEventListener('keydown', function(event) {
document.addEventListener('keydown', function(event) {
     if (event.code === 'KeyL' && x > mapX - 1) {
     if (event.code === 'KeyD') {
     x++;
     move(1, 0);
     }
     }
     if (event.code === 'KeyH' && x > 1) {
     if (event.code === 'KeyA') {
     x--;
     move(-1, 0);
     }
     }
     if (event.code === 'KeyK' && y < mapY - 1) {
     if (event.code === 'KeyW') {
     y++;
     move(0, -1);
     }
     }
     if (event.code === 'KeyJ' && y > 1) {
     if (event.code === 'KeyS') {
     y--;
     move(0, 1);
     }
     }
});
function move(dx, dy) {
if (base[ply + dy][plx + dx] != '#') {
plx += dx;
ply += dy;
var floor = base[ply][plx];
if (floor != '.' && floor != '\0') {
    log += "You are standing in " + floorDes(floor) + ".<br />";
    }
turn();
}
}
function turn() {
time++;
     refreshMap();
     refreshMap();
});
refLog();
}
 
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();
refreshMap();
refLog();

2023년 10월 26일 (목) 00:23 기준 최신판

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) == "<br />") {
            size++;
        }
    }
	if (size > 3) {
        log = log.substring(log.indexOf("<br />") + 1);
    }
	console.innerHTML = log;
	stats.innerHTML = temp2;
}
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 + "<br />Dlvl:" + level + " Lv:" + xl + " HP:" + hp + "/" + maxhp + " Pw:" + pw + "/" + maxpw;
stats.innerHTML = temp2;
document.addEventListener('keydown', function(event) {
    if (event.code === 'KeyD') {
    	move(1, 0);
    }
    if (event.code === 'KeyA') {
    	move(-1, 0);
    }
    if (event.code === 'KeyW') {
    	move(0, -1);
    }
    if (event.code === 'KeyS') {
    	move(0, 1);
    }
});

function move(dx, dy) {
	if (base[ply + dy][plx + dx] != '#') {
		plx += dx;
		ply += dy;
		var floor = base[ply][plx];
		if (floor != '.' && floor != '\0') {
    		log += "You are standing in " + floorDes(floor) + ".<br />";
    	}
		turn();
	}
}

function turn() {
	time++;
    refreshMap();
	refLog();
}

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();