Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Source by 51L3N7 */
- // Como o objeto 'document' é usado muitas vezes no código, achei bom usar um with, para evitar mtas repetições
- // Assim, ao invés de ter que ficar colocando "document.metodo()" é só colocar "metodo()"
- with ( document ) {
- //* Função usada para verificar qual a resposta dada pelo jogador (Mais a frente) *//
- function getReply( setReply ) {
- //O switch verifica o valor do parametro setReply, e exibe na tela a resposta adequada
- switch ( setReply ) {
- case 1: showText.innerHTML = 'Então o homem diz: Há um quartinho próximo a aquela casa abandonada que alugam para turistas em épocas como esta.'
- + ' Você pode ir até lá e pedir informações. '
- + 'Mas fique em alerta pois, há algum tempo pessoas estão morrendo de forma mistériosa na cidade';
- break;
- case 2: showText.innerHTML = 'O homem logo o repreende dizendo: Se acalme meu jovem. Entendo tua apreensão pela fama'
- + 'que esta cidade tem afora. Mas não sou o que aparento ser. As pessoas mais antigas desta cidade costumam voltar dos bares tarde da noite';
- break;
- case 3: showText.innerHTML = 'Rapidamente o estranho homem arremessa sua faca da qual atinge em cheio a sua testa. '
- + 'Você morre e a história acaba<br /><br />' + '<div style="font-size:50px;text-align:center;color:red;margin-left:200px;margin-top:150px">Game over.</div>'.bold();
- break;
- } // Fim do switch
- //* Adiciona a página o elemento "reticence" e remove os elementos "showQuestion" e etc, que são as perguntas
- getElementById( 'showText' ).appendChild( reticence );
- getElementsByTagName( 'body' )[0].removeChild( showQuestion );
- getElementsByTagName( 'body' )[0].removeChild( showQuestion2 );
- getElementsByTagName( 'body' )[0].removeChild( showQuestion3 );
- } // Fim da função
- //Título da página
- title = 'Solo RPG Adventure 2011';
- //Background da página
- body.style.backgroundImage = "url('http://img824.imageshack.us/img824/9176/unled2kt.png')";
- //* Cria os elementos HTML para serem usados mais abaixo *//
- var getChar = createElement( 'input' ),
- setChar = createElement( 'input' ),
- Continue = createElement( 'input' ),
- Continue2 = createElement( 'input' ),
- description = createElement( 'span' ),
- reticence = createElement( 'span' ),
- showName = createElement( 'div' ),
- showText = createElement( 'div' ),
- showQuestion = createElement( 'a' ),
- showQuestion2 = createElement( 'a' ),
- showQuestion3 = createElement( 'a' );
- //* input text *//
- getChar.setAttribute( 'type', 'text' ); //Define o que o input é de texto
- getChar.setAttribute( 'id', 'getCharName' ); //Define uma id ao input (Que serve pra pegar o nome do jogador)
- getChar.style.left = '450px'; //Usado pra centralizar o input
- getChar.style.top = '250px'; //Idem
- getChar.style.position = 'absolute'; //Idem
- getChar.style.fontFamily = 'Courier New'; //Muda o tipo da família da fonte do digitado no input
- //* input button *//
- setChar.setAttribute( 'type', 'button' ); //Define que o input é um butão
- setChar.setAttribute( 'value', 'Começar!' ); //Dá um nome ao botão
- setChar.style.left = '482px'; //Serve pra centralizar o botão
- setChar.style.top = '275px'; //Idem
- setChar.style.position = 'absolute'; //Idem
- setChar.style.padding = '10px'; //Acrescenta mais 10px de altura/largura ao redor do botão
- setChar.style.color = 'white'; //Muda a cor do nome do botão
- setChar.style.fontSize = '18px'; //Altera o tamanho da fonte
- setChar.style.cursor = 'pointer'; //Altera o tipo do cursor quando o mesmo for passado pelo botão
- setChar.style.background = '#069'; //Altera o fundo
- setChar.style.border = '0px'; //Deixa sem borda
- setChar.style.fontWeight = 'bold'; //Deixa a fonte como negrito
- //* span *//
- description.style.left = '350px'; //Serve para centralizar o texto
- description.style.top = '230px'; //Idem
- description.style.position = 'absolute'; //Idem
- description.style.fontFamily = 'Courier New'; //Muda a família da fonte
- description.innerHTML = 'Digite um nome para o seu personagem:'; //Adiciona o texto
- //* Nome *//
- showName.style.color = '#FFF'; //Altera a cor do texto
- showName.style.left = '250px';//Serve para centralizar
- showName.style.position = 'absolute'; //Idem
- showName.style.fontSize = '50px'; //Idem
- showName.style.fontFamily = 'Comic Sans MS'; //Altera a família da fonte
- showName.innerHTML = 'Solo RPG Adventure 2011'; //Adiciona o texto
- //* Adiciona ao corpo da página os elementos criados acima *//
- getElementsByTagName( 'body' )[0].appendChild( showName );
- getElementsByTagName( 'body' )[0].appendChild( getChar );
- getElementsByTagName( 'body' )[0].appendChild( setChar );
- getElementsByTagName( 'body' )[0].appendChild( description );
- //* Esse evento ocorre quando o botão é clicado *//
- setChar.onclick = function() {
- //Verifica se o jogador digitou o nome do personagem
- //Se não digitou..
- if ( getElementById( 'getCharName' ).value == '' ) alert( 'Digite o nome do seu personagem.' );
- //Se digitou..
- else {
- showText.setAttribute( 'id', 'showText' ); //Define um id
- getCharName = getElementById( 'getCharName' ).value; //Pega o nome do personagem
- //Exibe o texto na tela. O metodo bold() serve para deixar o nome do personagem em negrito
- showText.innerHTML = getCharName.bold() + ' estava viajando em busca de aventuras até chegar a uma cidade temida'
- + 'por muitos como a mais violenta da região e por este motivo, '
- + 'era comum cidadãos andarem armados';
- showText.style.color = 'gold'; //Mudar a cor do texto
- showText.style.top = '100px'; //Deixa o texto abaixo do nome do jogo
- showText.style.position = 'absolute'; //Idem
- showText.style.fontFamily = 'Tahoma'; //Muda a família da fonte
- //Adiciona ao corpo da página o texto
- getElementsByTagName( 'body' )[0].appendChild( showText );
- reticence.setAttribute( 'id', 'addReticence' ); //Define um id
- getElementById( 'showText' ).appendChild( reticence ); //Adiciona ao id "showText" o elemento "reticence"
- //* Serve para acrescentar 3 pontos de cada texto na página
- //Ex: . .. ... --> . .. ... e assim por diante
- add = '';
- function counter() {
- add += '.'; //Adiciona a variavel add um ponto ( . )
- setTimeout( counter, 1000 ); //Chama a função a cada mil milissegundos (1 segundo)
- getElementById( 'addReticence' ).innerHTML = add; //Adiciona ao id "addReticence" a variavel add
- if ( add.length == 3 ) add = ''; //Verifica se o add tem 3 pontos. Se tiver, zera a variavel.
- }
- counter(); //Chama a função
- //* Remove os elementos getChar, setChar e description do corpo da página *//
- getElementsByTagName( 'body' )[0].removeChild( getChar );
- getElementsByTagName( 'body' )[0].removeChild( setChar );
- getElementsByTagName( 'body' )[0].removeChild( description );
- Continue.setAttribute( 'type', 'button' ); //Define o input com um botão
- Continue.value = "Continuar..."; //Nome do botão
- Continue.style.top = '150px'; //Adiciona o botão abaixo do texo (showText)
- Continue.style.position = 'absolute'; //Idem
- getElementsByTagName( 'body' )[0].appendChild( Continue ); //Adiciona o botão ao corpo da página
- //Quando o botão for clicado:
- Continue.onclick = function() {
- //Remove o primeiro botão
- getElementsByTagName( 'body' )[0].removeChild( Continue );
- //Muda o texto
- showText.innerHTML = 'Ao chegar na cidade as 2:45 da madrugada logo percebeu-se que a rua estava deserta'
- + 'não havia ninguém pois, provavelmente todos estavam dormindo naquele horario.'
- + 'Então, ' + getCharName.bold() + ' resolve procurar um lugar para se hospedar. Quando de repente, sente que alguém estava lhe seguindo.'
- + 'Instintivamente, ' + getCharName.bold() + ' olha para trás e ver um vulto de alguém que aparentemente se escondera.'
- + ' Desconfiado(a), então resolve apressar o passo em direção a uma esquina mais iluminada';
- Continue.style.top = '185px'; //Abaixa um pouco mais o botão
- getElementById( 'showText' ).appendChild( reticence ); //Adiciona ao id "showText" o elemento "reticence"
- Continue2.setAttribute( 'type', 'button' ); //Define como um botão
- Continue2.value = "Continuar..."; //Nome do botão
- Continue2.style.top = '190px'; //Define a posição do botão
- Continue2.style.position = 'absolute'; //Idem
- getElementsByTagName( 'body' )[0].appendChild( Continue2 ); //Adiciona o botão ao corpo da página
- //Quando o botão for clicado:
- Continue2.onclick = function() {
- //Remove-se então o segundo botão
- getElementsByTagName( 'body' )[0].removeChild( Continue2 );
- //Troca o texto da página
- showText.innerHTML = 'De repente, o que parecia um vulto, se mostra em forma de um homem em meia luz da esquina com um capuz'
- + ' cobrindo seu rosto e o aborda perguntando: ' + 'O que faz aquí a esta hora da noite jovem?'.bold();
- getElementById( 'showText' ).appendChild( reticence ); //Adiciona o elemento "Reticence" a id "showText"
- //* Primeira pergunta *//
- showQuestion.setAttribute( 'href', 'javascript:getReply(1)' ); //Chama a função getReply() com o parametro definido com 1
- //Texto da pergunta
- showQuestion.innerHTML = '1 – Responder ao homem: Sou de fora e estou perdido nesta cidade. Pode me informar um lugar bom para hospedar-me??'
- showQuestion.style.top = '150px'; //Posição da pergunta
- showQuestion.style.position = 'absolute'; //Idem
- //* Segunda pergunta *//
- showQuestion2.setAttribute( 'href', 'javascript:getReply(2)' ); //Chama a função getReply() com o parametro definido com 2
- //Texto da pergunta
- showQuestion2.innerHTML = '2 – Responder ao homem: Porque você quer saber? Por acaso pedi a tua ajuda?';
- showQuestion2.style.top = '200px'; //Posição da pergunta
- showQuestion2.style.position = 'absolute';//Idem
- //* Terceira pergunta *//
- showQuestion3.setAttribute( 'href', 'javascript:getReply(3)' ); //Chama a função getReply() com o parametro definido com 3
- //Texto da pergunta
- showQuestion3.innerHTML = '3 – Agir contra o homem: Nome saca a arma que tem pendurada '
- + 'no cinto e o ameaça dizendo: Vá embora antes que eu atire.';
- showQuestion3.style.top = '235px'; //Posição da pergunta
- showQuestion3.style.position = 'absolute'; //Idem
- //Adiciona ao corpo da página as perguntas
- getElementsByTagName( 'body' )[0].appendChild( showQuestion );
- getElementsByTagName( 'body' )[0].appendChild( showQuestion2 );
- getElementsByTagName( 'body' )[0].appendChild( showQuestion3 );
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement