Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- <style>
- @font-face {
- font-family: czcionka;
- src: url(fonts/PressStart2P.ttf);
- }
- font {
- color: rgb(165, 162, 178);
- }
- * {
- font-family: czcionka;
- /* background-color: rgb(57, 57, 57); */
- background-color: black;
- color: lightgrey;
- }
- p {
- color: lightgrey;
- }
- #plansza {
- height: 160px;
- width: 256px;
- background-repeat: no-repeat;
- background-size: cover;
- border: 2px outset white;
- }
- button {
- color: white;
- }
- #inter {
- width: 800px;
- position: relative;
- }
- #divInfo {}
- input[type=text] {
- color: white;
- border: none;
- }
- #kompas {
- position: absolute;
- left: 350px;
- top: 60px;
- height: 160px;
- width: 256px;
- background-size: 100%;
- background-image: url('img/kompass.bmp');
- background-repeat: no-repeat;
- }
- #S {
- position: absolute;
- bottom: 20px;
- left: 120px;
- }
- #W {
- position: absolute;
- top: 25px;
- left: -10px;
- }
- #N {
- position: absolute;
- left: 115px;
- top: -22px;
- }
- #E {
- position: absolute;
- right: -10px;
- top: 25px;
- }
- /* .location{
- border:solid 1px;
- width: 50px;
- height:50px;
- margin: 5px;
- float:left;
- }
- .location:nth-child(2n+1){
- clear:both;
- } */
- </style>
- <script>
- function _It(id, przedmiot, flaga, nazwa) {
- this.id = id;
- this.przedmiot = przedmiot;
- this.flaga = flaga;
- this.nazwa = nazwa;
- }
- function _Location(miejsce, grafika, tlo, moze, przedmiot) {
- this.miejsce = miejsce;
- this.grafika = grafika;
- this.tlo = tlo
- this.moze = moze
- this.element = null;
- this.item = []
- this.przedmiot = przedmiot;
- // this.init = function () {
- // var div = document.createElement("div");
- // div.className = "location";
- // this.element = div;
- // document.getElementById("plansza").appendChild(div);
- // }
- // this.init();
- }
- var zmien = 0
- var strona
- var c = []
- var kierunki = ["S", "W", "N", "E"]
- var czy = false
- document.addEventListener("DOMContentLoaded", function (event) {
- var ekwipunek = []
- var kompas = document.createElement("div")
- kompas.setAttribute("id", "kompas")
- document.body.appendChild(kompas)
- for (var i = 0; i < 4; i++) {
- var pe = document.createElement("p")
- pe.setAttribute("id", kierunki[i])
- kompas.append(pe)
- }
- function ustawKompas(kierunek) {
- for (var i = 0; i < 4; i++) {
- document.getElementById(kierunki[i]).innerHTML = ""
- }
- setTimeout(function () {
- document.getElementById(kierunek).innerHTML = kierunek
- }, 0);
- }
- przedmioty = {
- przedmiot: {
- "10": ["10", "a KEY", 1, "KEY"],
- "11": ["11", "an AXE", 1, "AXE"],
- "12": ["12", "STICKS", 1, "STICKS"],
- "13": ["13", "sheeplegs", 0, "sheeplegs"],
- "14": ["14", "MUSHROOMS", 1, "MUSHROOMS"],
- "15": ["15", "MONEY", 1, "MONEY"],
- "16": ["16", "a BARREL", 1, "BARREL"],
- "17": ["17", "a sheeptrunk", 0, "sheeptrunk"],
- "18": ["18", "BERRIES", 1, "BERRIES"],
- "19": ["19", "WOOL", 1, "WOOL"],
- "20": ["20", "a sheepskin", 0, "sheepskin"],
- "21": ["21", "a BAG", 1, "BAG"],
- "22": ["22", "a RAG", 1, "RAG"],
- "23": ["23", "a sheephead", 0, "sheephead"],
- "24": ["24", "a SPADE", 1, "SPADE"],
- "25": ["25", "SULPHUR", 1, "SULPHUR"],
- "26": ["26", "a solid poison", 0, "solid poison"],
- "27": ["27", "a BUCKET", 1, "BUCKET"],
- "28": ["28", "TAR", 1, "TAR"],
- "29": ["29", "a liquid poison", 0, "liquid poison"],
- "30": ["30", "a dead dragon", 0, "dead dragon"],
- "31": ["31", "a STONE", 1, "STONE"],
- "32": ["32", "a FISH", 1, "FISH"],
- "33": ["33", "a KNIFE", 1, "KNIFE"],
- "34": ["34", "a DRAGONSKIN", 1, "DRAGONSKIN"],
- "35": ["35", "a dragonskin SHOES", 1, "SHOES"],
- "36": ["36", "a PRIZE", 1, "PRIZE"]
- },
- }
- game = {
- board: [
- [
- new _Location("You are inside a brimstone mine", "img/11.gif", "rgb(235,211,64)", [right = 1, left = 0, up = 0, down = 0]),
- new _Location("You are at the entrance to the mine", "img/12.gif", "rgb(89,93,87)", [right = 1, left = 1, up = 0, down = 0]),
- new _Location("A hill", "img/13.gif", "rgb(117,237,243)", [right = 1, left = 1, up = 0, down = 1], [przedmioty.przedmiot["31"]]),
- new _Location("Some bushes", "img/14.gif", "rgb(202,230,51)", [right = 1, left = 1, up = 0, down = 0]),
- new _Location("An old deserted hut", "img/15.gif", "rgb(220,204,61)", [right = 1, left = 1, up = 0, down = 0], [przedmioty.przedmiot["27"]]),
- new _Location("The edge of a forest", "img/16.gif", "rgb(167,245,63)", [right = 1, left = 1, up = 0, down = 0]),
- new _Location("A dark forest", "img/17.gif", "rgb(140,253,99)", [right = 0, left = 1, up = 0, down = 1], [przedmioty.przedmiot["31"]]),
- ],
- [
- new _Location("A man nearby making tar", "img/21.gif", "rgb(255,190,99)", [right = 1, left = 0, up = 0, down = 1]),
- new _Location("A timber yard", "img/22.gif", "rgb(255,190,99)", [right = 1, left = 1, up = 0, down = 1]),
- new _Location("You are by a roadside shrine", "img/23.gif", "rgb(167,245,63)", [right = 1, left = 1, up = 1, down = 1], [przedmioty.przedmiot["10"]]),
- new _Location("You are by a small chapel", "img/24.gif", "rgb(212,229,36)", [right = 1, left = 1, up = 0, down = 0]),
- new _Location("You are on a road leading to a wood", "img/25.gif", "rgb(167,245,63)", [right = 1, left = 1, up = 0, down = 1]),
- new _Location("You are in a forest", "img/26 i 65.gif", "rgb(167,245,63)", [right = 1, left = 1, up = 0, down = 0]),
- new _Location("You are in a deep forest", "img/27 i 67.gif", "rgb(140,253,99)", [right = 0, left = 1, up = 1, down = 0], [przedmioty.przedmiot["18"]])
- ],
- [
- new _Location("You are by the Vistula River", "img/31.gif", "rgb(122,232,252)", [right = 1, left = 0, up = 1, down = 0]),
- new _Location("You are by the Vistula River", "img/32.gif", "rgb(140,214,255)", [right = 0, left = 1, up = 1, down = 0], [przedmioty.przedmiot["32"]]),
- new _Location("You are on a bridge over river", "img/33.gif", "rgb(108,181,242)", [right = 0, left = 0, up = 1, down = 1]),
- new _Location("You are by the old tavern", "img/34.gif", "rgb(255,189,117)", [right = 1, left = 0, up = 0, down = 0]),
- new _Location("You are at the town's end", "img/35.gif", "rgb(255,190,99)", [right = 0, left = 1, up = 1, down = 1]),
- new _Location("You are in a butcher's shop", "img/36.gif", "rgb(255,188,102)", [right = 0, left = 0, up = 0, down = 1]),
- new _Location("You are in a cooper's house", "img/37.gif", "rgb(255,188,102)", [right = 0, left = 0, up = 0, down = 1])
- ],
- [
- new _Location("You are in the Wawel Castle", "img/41.gif", "rgb(255,176,141)", [right = 1, left = 0, up = 0, down = 0]),
- new _Location("You are inside a dragon's cave", "img/42.gif", "rgb(198,205,193)", [right = 1, left = 0, up = 1, down = 0]),
- new _Location("A perfect place to set a trap", "img/43.gif", "rgb(255,176,141)", [right = 0, left = 1, up = 1, down = 0]),
- new _Location("You are by the water mill", "img/44.gif", "rgb(255,190,99)", [right = 1, left = 0, up = 0, down = 0], [przedmioty.przedmiot["21"]]),
- new _Location("You are at a main crossroad", "img/45.gif", "rgb(255,190,99)", [right = 1, left = 1, up = 1, down = 1]),
- new _Location("You are on a town street", "img/46.gif", " rgb(255,190,99)", [right = 1, left = 1, up = 1, down = 0]),
- new _Location("You are in a frontyard of your house", "img/47.gif", "rgb(255,190,99)", [right = 0, left = 1, up = 1, down = 1])
- ],
- [
- null, null, null,
- new _Location("You are by a swift stream", "img/54.gif", "rgb(108,181,242)", [right = 1, left = 0, up = 0, down = 0]),
- new _Location("You are on a street leading forest", "img/55.gif", "rgb(255,190,99)", [right = 0, left = 1, up = 1, down = 1], [przedmioty.przedmiot["33"]]),
- new _Location("You are in a woodcutter's backyard", "img/56.gif", "rgb(255,190,99)", [right = 0, left = 0, up = 0, down = 1]),
- new _Location("You are in a shoemaker's house", "img/57.gif", " rgb(254,194,97)", [right = 0, left = 0, up = 1, down = 0])
- ],
- [
- null, null, null,
- new _Location("You are in a bleak funeral house", "img/64.gif", "rgb(254,194,97)", [right = 1, left = 0, up = 0, down = 0], [przedmioty.przedmiot["24"]]),
- new _Location("You are on a path leading to the wood", "img/26 i 65.gif", "rgb(167,245,63)", [right = 1, left = 1, up = 1, down = 0]),
- new _Location("You are at the edge of a forest", "img/66.gif", "rgb(167,245,63)", [right = 1, left = 1, up = 1, down = 0]),
- new _Location("You are in a deep forest", "img/27 i 67.gif", "rgb(140,253,99)", [right = 0, left = 1, up = 0, down = 0]),
- ]
- ],
- player: {
- pos_x: 6, //6
- pos_y: 1, //3
- sprawdzGdzie: function () {
- c = []
- strona = []
- var tab = [right = 1, left = 1, up = 1, down = 1]
- var person = game.board[this.pos_y][this.pos_x]
- person.moze.forEach(function (s, i) {
- c.push(person.moze[i] == tab[i])
- })
- if (c[0] == true) {
- strona.push("EAST")
- ustawKompas("E")
- }
- if (c[1] == true) {
- strona.push("WEST")
- ustawKompas("W")
- }
- if (c[2] == true) {
- strona.push("NORTH")
- ustawKompas("N")
- }
- if (c[3] == true) {
- strona.push("SOUTH")
- ustawKompas("S")
- }
- // console.log(strona)
- document.getElementById("pierwszy").innerHTML = "You can go " + strona
- return strona
- },
- ekwipunek: {
- },
- report: function (p) {
- // console.log(p.przedmiot[1])
- // console.log("x: " + this.pos_x)
- // console.log("y: " + this.pos_y)
- },
- ustaw: function (p) {
- document.getElementById("plansza").style.backgroundImage = "url('" + p.grafika + "')";
- document.getElementById("plansza").style.backgroundColor = p.tlo
- document.getElementById("glownyText").innerHTML = p.miejsce
- },
- go: function (direction) {
- c = []
- strona = []
- // console.log(game.board)
- //console.log(game.board[this.pos_y][this.pos_x].moze)
- var tab = [right = 1, left = 1, up = 1, down = 1]
- var person = game.board[this.pos_y][this.pos_x]
- person.moze.forEach(function (s, i) {
- c.push(person.moze[i] == tab[i])
- })
- if (c[0] == true) {
- if (direction == "right" && this.pos_x < 6) {
- this.pos_x++;
- }
- }
- if (c[1] == true) {
- if (direction == "left" && this.pos_x > 0) {
- this.pos_x--;
- }
- }
- if (c[2] == true) {
- if (direction == "up" && this.pos_y > 0) {
- this.pos_y--;
- }
- }
- if (c[3] == true) {
- if (direction == "down" && this.pos_y < 6) {
- this.pos_y++;
- }
- }
- this.highlight();
- },
- highlight: function () {
- var person = game.board[this.pos_y][this.pos_x];
- this.ustaw(person)
- game.player.sprawdzPrzedmiot();
- game.player.sprawdzGdzie();
- game.player.report(person)
- },
- podnies: function (rzecz) {
- var person = game.board[this.pos_y][this.pos_x]
- var rzecz = rzecz
- console.log(rzecz)
- if (person.przedmiot == undefined) {
- // console.log("cojekurwa")
- // console.log(ekwipunek.length)
- } else if (person.przedmiot != undefined) {
- person.przedmiot.forEach(function (to, ito) {
- // console.log(to)
- person.przedmiot[ito].forEach(function (to2, ito2) {
- if (to2 == rzecz) {
- ekwipunek.push(person.przedmiot[ito])
- person.przedmiot.pop()
- if (person.przedmiot.length == 0) {
- document.getElementById("drugi").innerHTML = "You see nothing"
- } else if (ekwipunek.length >= 1) {
- document.getElementById("label").innerHTML = "Masz już cos"
- setTimeout(function () {
- document.getElementById("label").innerHTML = "What now?"
- document.getElementById("pole").value = ""
- document.getElementById("pole").disabled = false;
- }, 1000);
- }
- }
- })
- })
- document.getElementById("trzecie").innerHTML = "You are carrying " + ekwipunek[0][1]
- }
- },
- wyrzuc: function (rzecz) {
- var person = game.board[this.pos_y][this.pos_x]
- var rzecz = rzecz
- if (ekwipunek.length > 0) {
- if (person.przedmiot != undefined) {
- person.przedmiot.push(ekwipunek[0])
- }
- }
- if (person.przedmiot == undefined) {
- person.przedmiot = [ekwipunek[0]]
- document.getElementById("drugi").innerHTML = person.przedmiot[0]
- }
- if (person.przedmiot.length > 1) {
- document.getElementById("drugi").innerHTML = "You see "
- for (var i = 0; i < person.przedmiot.length; i++) {
- document.getElementById("drugi").innerHTML += person.przedmiot[i][1] + ","
- document.getElementById("trzecie").innerHTML = "You are carrying nothing"
- }
- ekwipunek = []
- } else {
- // console.log(person)
- document.getElementById("drugi").innerHTML = "You see " + person.przedmiot[0][1]
- document.getElementById("trzecie").innerHTML = "You are carrying nothing"
- ekwipunek = []
- }
- },
- sprawdzPrzedmiot: function () {
- var person = game.board[this.pos_y][this.pos_x]
- if (person.przedmiot != undefined) {
- person.przedmiot.forEach(function (to, ito) {
- person.przedmiot[ito].forEach(function (to2, ito2) {
- document.getElementById("drugi").innerHTML = "You see " + person.przedmiot[ito][1]
- })
- })
- if (person.przedmiot.length > 1) {
- document.getElementById("drugi").innerHTML = "You see "
- for (var i = 0; i < person.przedmiot.length; i++) {
- if (i > 0) {
- document.getElementById("drugi").innerHTML += "," + person.przedmiot[i][1] + " "
- document.getElementById("trzecie").innerHTML = "You are carrying nothing"
- } else {
- document.getElementById("drugi").innerHTML += person.przedmiot[i][1]
- document.getElementById("trzecie").innerHTML = "You are carrying nothing"
- }
- }
- }
- } else {
- document.getElementById("drugi").innerHTML = "You see nothing"
- }
- },
- comam: function () {
- // console.log(ekwipunek[0][1])
- var person = game.board[this.pos_y][this.pos_x]
- // console.log(person)
- }
- }
- }
- game.player.highlight();
- document.getElementById("pierwszy").innerHTML = "You can go " + strona
- });
- function polecenia(co) {
- var co = co
- // if (co == "VOCABULARY" || co == "V") {
- // clearInterval(myVar)
- // czy = true
- // document.getElementById("info").innerHTML = ""
- // var tekst = ["NORTH or N, SOUTH or S",
- // "WEST or W, EAST or E",
- // "TAKE (object) or T (object)",
- // "DROP (object) or D (object)",
- // "USE (object) or U (object)",
- // "GOSSIPS or G, VOCABULARY or V",
- // "Press any key"]
- // // document.getElementById("info").innerHTML = ""
- // console.log(tmp)
- // // document.getElementById("label").innerHTML = ""
- // for (var i = 0; i < tekst.length; i++) {
- // document.getElementById("inter").innerHTML = ""
- // var p = document.createElement("p")
- // p.innerHTML = tekst[i]
- // document.getElementById("info").append(p)
- // var szybko = setInterval(aktywnosc, 0)
- // }
- // function aktywnosc() {
- // document.getElementById("info").focus()
- // }
- // document.getElementById("info").addEventListener('keydown', function (e) {
- // console.log(e.key)
- // if (e.key) {
- // clearInterval(szybko)
- // document.getElementById("info").innerHTML = ""
- // }
- // czy = false
- // })
- // }
- // console.log(co)
- if (co.indexOf("TAKE") == 0) {
- console.log(co.substr(5, co.length))
- game.player.podnies(co.substr(5, co.length))
- }
- if (co.indexOf("DROP") == 0) {
- console.log(co.substr(5, co.length))
- game.player.wyrzuc(co.substr(5, co.length))
- }
- }
- var myVar = setInterval(ffff, 0);
- function ffff() {
- document.getElementById("pole").focus()
- }
- function cos(d) {
- var litera = d.value.toString().toUpperCase()
- var zapis = litera
- var x = event.charCode || event.keyCode;
- if (x == 13) {
- polecenia(litera)
- if (litera.substr(0, 4) != 'D' && litera.substr(0, 4) != 'DROP' && litera.indexOf("VALUE") != 0 && litera.substr(0, 4) != 'TAKE' && litera.substr(0, 4) != "take" && litera.substr(0, 4) != "t" && litera.substr(0, 4) != "T" && litera.substr(0, 5) != "E" && litera.substr(0, 5) != "e" && litera.substr(0, 5) != "EAST" && litera.substr(0, 5) != "W" && litera.substr(0, 5) != "w" && litera.substr(0, 5) != "WEST" && litera.substr(0, 5) != "N" && litera.substr(0, 5) != "n" && litera.substr(0, 5) != "NORTH" && litera.substr(0, 5) != "S" && litera.substr(0, 5) != "s" && litera.substr(0, 5) != "SOUTH") {
- document.getElementById("label").innerHTML = "Zły krok"
- }
- document.getElementById("pole").disabled = true;
- document.getElementById("pole").value = ""
- setTimeout(function () {
- document.getElementById("label").innerHTML = "What now?"
- document.getElementById("pole").value = ""
- document.getElementById("pole").disabled = false;
- }, 100);
- return litera
- }
- }
- function sprawdz(kl) {
- var x = cos(event.target)
- // var klawisze = [
- // right = 69,
- // left = 87,
- // up = 78,
- // down = 83]
- // var x = event.which || event.keyCode;
- // console.log(strona)
- var direction
- strona.forEach(function (z) {
- if ("EAST" == z) {
- if (x == "E" || x == "e" || x == "EAST") {
- direction = 'right'
- document.getElementById("label").innerHTML = "You are going east..."
- }
- }
- if ("WEST" == z) {
- if (x == "W" || x == "w" || x == "WEST") {
- direction = 'left'
- document.getElementById("label").innerHTML = "You are going west..."
- }
- }
- if ("NORTH" == z) {
- if (x == "N" || x == "n" || x == "NORTH") {
- direction = 'up'
- document.getElementById("label").innerHTML = "You are going north..."
- }
- }
- if ("SOUTH" == z) {
- if (x == "S" || x == "s" || x == "SOUTH") {
- direction = 'down'
- document.getElementById("label").innerHTML = "You are going south..."
- }
- }
- })
- return game.player.go(direction)
- }
- function tab(el) {
- // console.log(document.getElementById("pole").value = el.value.toUpperCase())
- if (event.which == 9) {
- event.preventDefault();
- }
- // if (event.which == 20) {
- // document.getElementById("pole").value = el.value.toLowerCase()
- // }
- // else if (event.which == 16) {
- // document.getElementById("pole").value = el.value.toLowerCase()
- // }
- }
- </script>
- </head>
- <body>
- <p id="glownyText">Cos tu bedzie</p>
- <div id="plansza"></div>
- <div id="info" tabindex="0">
- <p id="pierwszy">You can go </p>
- <p id="drugi">You see nothing </p>
- <p id="trzecie">You are carrying nothing </p>
- <!-- <p id="czwarte"> </p> -->
- </div>
- <div id="inter">
- <label id="label">What now?</label><input type="text" id="pole" autofocus onblur="cos(this)"
- onkeypress="sprawdz(this)" onkeydown="tab(this)">
- <!--
- <input type="text" id="pole" autofocus onblur="cos(this)"
- onkeypress="sprawdz(this)" onkeydown="tab(this)"> -->
- </div>
- <!-- <button onclick="game.player.go('left')">LEFT</button>
- <button onclick="game.player.go('up')">UP</button>
- <button onclick="game.player.go('down')">DOWN</button>
- <button onclick="game.player.go('right')">RIGHT</button> -->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement