Text-Based Game

Okay, so I finally got most of this figured out. One problem. When I'm in the webpage, pressing the buttons, and I come to the choice between red and blue, both buttons are aligned slightly to the right? I have not coded the red button yet, but the blue button otherwise works fine!

Here is the code:

HTML:
Code:
<html>
<head>
	<title> Lines of Story </title>
	<link rel="stylesheet" type="text/css" href="style.css">
	<script src="script.js"></script>
</head>

<body onload="buttonReady()">
	<p id="main">Lines of Story <br> Presented by Cameron Palmer</p>
	
	<p id="button">
	<button id="submit" align="middle" onclick="change()"> Press </button>
	</p>
	
	<div id="buttonDiv"class="buttonDiv"> </div>

	





</body>
</html>

CSS:
Code:
#main{text-align: center;}
#button{text-align: center;}
div.buttonDiv{text-align: center;}


JavaScript:
Code:
/HOUSEKEEPING (onload function)/

function buttonReady(){
	var button= document.getElementById("submit");
	var para= document.getElementById("main");
	var div= document.getElementById("buttonDiv");
	button.style.height="30px";
	button.style.width="60px";

	var bluesubmit = document.createElement("BUTTON");
	var bluesubmitext = document.createTextNode("Press");

	bluesubmit.appendChild(bluesubmitext);
	div.appendChild(bluesubmit);
	bluesubmit.style.color="blue";
	bluesubmit.style.width="60px";
	bluesubmit.style.height="30px";
	bluesubmit.style.visibility="hidden";
	bluesubmit.id="bsub";
}

/ THE MAIN FUNCTION /

function change() {
	var button= document.getElementById("submit");
	var para= document.getElementById("main");
	var div= document.getElementById("buttonDiv");

	switch(para.innerHTML)	{

		default:
			para.innerHTML="You broke the game, stupid!";
			break;

		case "Lines of Story <br> Presented by Cameron Palmer":
			para.innerHTML="This is a text-based game.";
			break;

		case "This is a text-based game.":
			para.innerHTML="It will be very boring.";
			break;

		case "It will be very boring.":
			para.innerHTML="It's made for old people and nerds.";
			break;

		case "It's made for old people and nerds.":
			para.innerHTML="Ahh... text based games.";
			break;

		case "Ahh... text based games.":
			para.innerHTML="Chapter 1<br>Which color do you like more?";
			var redbtn = document.createElement("BUTTON");
			var redtext = document.createTextNode("Red");
			redbtn.appendChild(redtext);
			div.appendChild(redbtn);
			redbtn.style.color="red";
			redbtn.className="redbtn";

			var bluebtn = document.createElement("BUTTON");
			var bluetext = document.createTextNode("Blue");
			bluebtn.appendChild(bluetext);
			div.appendChild(bluebtn);
			bluebtn.style.color="blue";
			bluebtn.className="bluebtn";

			button.style.display="none";

			redbtn.style.width="60px";
			redbtn.style.height="30px";

			bluebtn.style.width="60px";
			bluebtn.style.height="30px";

			bluebtn.onclick= blueFunction;
			redbtn.onclick= redFunction;

		
			break;


/THE BLUE TRACK FUNCTION/

		function blueFunction() {

			var button= document.getElementById("submit");
			var para= document.getElementById("main");
			var div= document.getElementById("buttonDiv");
			var bsub=document.getElementById("bsub");

			bsub.style.display="show";
			bsub.onclick=blueFunction;
			bsub.style.visibility="visible";
			bluebtn.style.display="none";
			redbtn.style.display="none";
			

			switch(para.innerHTML){
				case "Chapter 1<br>Which color do you like more?":
				para.innerHTML="So... blue?";
				break;

				case "So... blue?":
				para.innerHTML="I always hated blue.";
				break;

				case "I always hated blue.":
				para.innerHTML="(Sniffle) <br> It..it makes me sad.";
				break;

			}

		}

/THE RED TRACK FUNCTION/

		function redFunction() {
			var button= document.getElementById("submit");
			var para= document.getElementById("main");
			var div= document.getElementById("buttonDiv");
			var redsubmit = document.createElement("BUTTON");
			var redsubmitext = document.createTextNode("Press");

			bluebtn.style.display="none";
			redbtn.style.display="none";

			
			redsubmit.appendChild(redsubmitext);
			div.appendChild(redsubmit);
			redsubmit.style.color="red";
			redsubmit.style.width="60px";
			redsubmit.style.height="30px";

			switch(para.innerHTML) {
				case "Chapter 1<br>Which color do you like more?":
				para.innerHTML="Red...ah...red";
				break;

				case "Red...ah...red":
				para.innerHTML="Christmas";
				break;


			}

		}
	}
}


Thanks
 
Okay, when the .style.visibillity="hidden"; is set to a button, does it still take up space?
The link answers that question as well.

Okay, so I finally got most of this figured out. One problem. When I'm in the webpage, pressing the buttons, and I come to the choice between red and blue, both buttons are aligned slightly to the right? I have not coded the red button yet, but the blue button otherwise works fine!

Post a screenshot as to what you mean; check it in different browsers as well to see if it behaves the same across all browsers (some will have differences in how things get laid out).
 
Also, when I click the red button, it goes to the first piece of text, but the new "press" button is now slightly to the right.
Here is a screenshot of the red button:
red.png

And of them both:
both.png
 
Check the alignment of the wrapper div you're adding the buttons to.

Center the div by adding the following CSS to the buttonDiv class:

Code:
width: 100%;
margin-left: auto;
margin-right: auto;
 
Check the alignment of the wrapper div you're adding the buttons to.

Center the div by adding the following CSS to the buttonDiv class:

Code:
width: 100%;
margin-left: auto;
margin-right: auto;

This did not work... it almost seems that there is another invisible button there...
 
Okay, I was right about the invisible button. I set a button to "visibility='hidden'", instead of "display='none'".
 
Last edited:
Okay, new problem.

I added a new decision on the blue track.

So, I get to the Red-Blue choice and I click blue, and I keep going along that until I get to the decision, but the right button is raised slightly higher than the other button?

Code:


HTML:
Code:
<DOCTYPE html>
<html>
<head>
	<title> Lines of Story </title>
	<link rel="stylesheet" type="text/css" href="style.css">
	<script src="script.js"></script>
	
</head>

<body onload="buttonReady()">
	<p id="main">Lines of Story <br> Presented by Cameron Palmer</p>
	
	<p id="button">
	<button id="submit" align="middle" onclick="change()"> Press </button>
	</p>
	
	<div id="buttonDiv"class="buttonDiv"> </div>

</body>
</html>

CSS:
Code:
#main{text-align: center;}
#button{text-align: center;}
div.buttonDiv{text-align: center; width:100%; margin-left: auto; margin-right: auto;}
#bsub{margin-left: auto; margin-right: auto;}
#rsub{margin-left: auto; margin-right: auto;}

All JavaScript:
Code:
/HOUSEKEEPING (onload function)/

function buttonReady(){
	
	/First button and paragraphs/
	var button= document.getElementById("submit");
	var para= document.getElementById("main");
	var div= document.getElementById("buttonDiv");

	/Button Styles/
	button.style.height="30px";
	button.style.width="60px";


	/Blue Button Declaration, Styles/

	
	var bluesubmit = document.createElement("BUTTON");
	var bluesubmitext = document.createTextNode("Press");

	/Blue Submit Button Style/
	bluesubmit.appendChild(bluesubmitext);
	div.appendChild(bluesubmit);
	bluesubmit.style.color="blue";
	bluesubmit.style.width="60px";
	bluesubmit.style.height="30px";
	bluesubmit.style.display="none";
	bluesubmit.id="bsub";

	/Red Button Declaration, Styles/

	
	var redsubmit = document.createElement("BUTTON");
	var redsubmitext = document.createTextNode("Press");

	/Red Submit Button Style/
	redsubmit.appendChild(redsubmitext);
	div.appendChild(redsubmit);
	redsubmit.style.color="red";
	redsubmit.style.width="60px";
	redsubmit.style.height="30px";
	redsubmit.style.display="none";
	redsubmit.id="rsub";
}

/ THE MAIN FUNCTION /

function change() {
	var button= document.getElementById("submit");
	var para= document.getElementById("main");
	var div= document.getElementById("buttonDiv");

	switch(para.innerHTML)	{

		default:
			para.innerHTML="You broke the game, stupid!";
			break;

		case "Lines of Story <br> Presented by Cameron Palmer":
			para.innerHTML="This is a text-based game.";
			break;

		case "This is a text-based game.":
			para.innerHTML="It will be very boring.";
			break;

		case "It will be very boring.":
			para.innerHTML="It's made for old people and nerds.";
			break;

		case "It's made for old people and nerds.":
			para.innerHTML="Ahh... text based games.";
			break;

		case "Ahh... text based games.":
			para.innerHTML="Chapter 1<br>Which color do you like more?";
			var redbtn = document.createElement("BUTTON");
			var redtext = document.createTextNode("Red");
			redbtn.appendChild(redtext);
			div.appendChild(redbtn);
			redbtn.style.color="red";
			redbtn.className="redbtn";

			var bluebtn = document.createElement("BUTTON");
			var bluetext = document.createTextNode("Blue");
			bluebtn.appendChild(bluetext);
			div.appendChild(bluebtn);
			bluebtn.style.color="blue";
			bluebtn.className="bluebtn";

			button.style.display="none";

			redbtn.style.width="60px";
			redbtn.style.height="30px";

			bluebtn.style.width="60px";
			bluebtn.style.height="30px";

			bluebtn.onclick= blueFunction;
			redbtn.onclick= redFunction;

		
			break;


/THE BLUE TRACK FUNCTION, SNUFFLEDUFFLE/

		function blueFunction() {

			var button= document.getElementById("submit");
			var para= document.getElementById("main");
			var div= document.getElementById("buttonDiv");
			var bsub=document.getElementById("bsub");

			bsub.onclick=blueFunction;
			bsub.style.display="block";

			bluebtn.style.display="none";
			redbtn.style.display="none";
			

			switch(para.innerHTML){
				case "Chapter 1<br>Which color do you like more?":
				para.innerHTML="So... blue?";
				break;

				case "So... blue?":
				para.innerHTML="I always hated blue.";
				break;

				case "I always hated blue.":
				para.innerHTML="(Sniffle) <br> It..it makes me sad.";
				break;

				case "(Sniffle) <br> It..it makes me sad.":
				para.innerHTML="*Rain pours down upon you*";
				break;

				case "*Rain pours down upon you*":
				para.innerHTML="I AM GOD!";
				break;

				case "I AM GOD!":
				para.innerHTML="I AM....... SNUFFLEDUFFLE!";
				break;

				case "I AM....... SNUFFLEDUFFLE!":
				para.innerHTML="Now, don't laugh here...";
				break;

				case "Now, don't laugh here...":
				para.innerHTML="I am the god of...";
				break;

				case "I am the god of...":
				para.innerHTML="CUDDLYNESS AND SOFT THINGS!";
				break;

				case "CUDDLYNESS AND SOFT THINGS!":
				para.innerHTML="AND I WILL DESTROY YOU IN A PILLOW FIGHT!";
				break;

				case "AND I WILL DESTROY YOU IN A PILLOW FIGHT!":
				para.innerHTML="No... I'm sorry... did I scare you?";
				break;

				case "No... I'm sorry... did I scare you?":
				para.innerHTML="Chapter 2 <br> Tutorial";
				break;

				case "Chapter 2 <br> Tutorial":
				para.innerHTML="Ahh... totorials...";
				break;

				case "Ahh... totorials...":
				para.innerHTML="Just keep clickin and you'll be fine";
				break;

				case "Just keep clickin and you'll be fine":
				para.innerHTML="NO! NOT THERE!";
				break;

				case "NO! NOT THERE!":
				para.innerHTML="There <br> | <br> v";
				break;

				case "There <br> | <br> v":
				para.innerHTML="Thank you";
				break;

				case "Thank you":
				para.innerHTML="Now, back to the totorial";
				break;

				case "Now, back to the totorial":
				para.innerHTML="What's that? It's not a totori- ohhh.... it's a tutorial";
				break;

				case "What's that? It's not a totori- ohhh.... it's a tutorial":
				para.innerHTML="DO NOT CORRECT ME";
				break;

				case "DO NOT CORRECT ME":
				para.style.display="none";
				var correctbtn = document.createElement("BUTTON");
				var correcttext = document.createTextNode("Correct");
				correctbtn.appendChild(correcttext);
				div.appendChild(correctbtn);
				correctbtn.style.color="Green";
				correctbtn.className="correctbtn";

				var donotcorrectbtn = document.createElement("BUTTON");
				var donotcorrecttext = document.createTextNode("Do Not Correct");
				donotcorrectbtn.appendChild(donotcorrecttext);
				div.appendChild(donotcorrectbtn);
				donotcorrectbtn.style.color="Red";
				donotcorrectbtn.className="donotcorrectbtn";

				bsub.style.display="none";

				donotcorrectbtn.style.width="60px";
				donotcorrectbtn.style.height="30px";

				correctbtn.style.width="60px";
				correctbtn.style.height="30px";

				correctbtn.onclick= correctFunction;
				donotcorrectbtn.onclick= donotcorrectFunction;

		
				break;


			}

		}

/THE RED TRACK FUNCTION, AWKDOKPORKGUY/

		function redFunction() {
			var button= document.getElementById("submit");
			var para= document.getElementById("main");
			var div= document.getElementById("buttonDiv");
			

			bluebtn.style.display="none";
			redbtn.style.display="none";

			rsub.style.display="block";
			rsub.onclick=redFunction;
			
			

			switch(para.innerHTML) {
				case "Chapter 1<br>Which color do you like more?":
				para.innerHTML="Red...ah...red";
				break;

				case "Red...ah...red":
				para.innerHTML="Christmas";
				break;

				case "Christmas":
				para.innerHTML="Red convertables...";
				break;

				case "Red convertables...":
				para.innerHTML="Red objects...";
				break;

				case "Red objects...":
				para.innerHTML="I HATE RED";
				break;

				case "I HATE RED":
				para.innerHTML="Who am I, you ask?";
				break;

				case "Who am I, you ask?":
				para.innerHTML="Why...I am...";
				break;

				case "Why...I am...":
				para.innerHTML="YOUR MOTHER!";
				break;

				case "YOUR MOTHER!":
				para.innerHTML="I'm just pulling your leg";
				break;

				case "I'm just pulling your leg":
				para.innerHTML="But seriously though, I am...";
				break;

				case "But seriously though, I am...":
				para.innerHTML="AWKDOKPORKGUY, the god of pork, guys, docks, and the noise awk!";
				break;

				case "AWKDOKPORKGUY, the god of pork, guys, docks, and the noise awk!":
				para.innerHTML="Chapter 2 <br> Tutorial";
				break;

				case "Chapter 2 <br> Tutorial":
				para.innerHTML="This part is basically a tutorial, so do what I tell you or I will slap you with slabs of pork!";
				break;

				case "This part is basically a tutorial, so do what I tell you or I will slap you with slabs of pork!":
				para.innerHTML="What do you mean, there are no tutorials in a text based game?";
				break;

				case "What do you mean, there are no tutorials in a text based game?":
				para.innerHTML="What do you mean, you just click on stuff? Text based games are much more than that. MUCH more than that";
				break;

				case "What do you mean, you just click on stuff? Text based games are much more than that. MUCH more than that":
				para.innerHTML="So let's do this tutorial! Tutorial prepared to get owned! And then slapped repeatedly in the face with slabs of pork!";
				break;

				case "So let's do this tutorial! Tutorial prepared to get owned! And then slapped repeatedly in the face with slabs of pork!":
				para.innerHTML="Alright here are the basic controls:";
				break;

				case "Alright here are the basic controls:":
				para.innerHTML="Left click: <br> Selects an option or skips to the next section of text";
				break;

				case "Left click: <br> Selects an option or skips to the next section of text":
				para.innerHTML="Right click: <br> Shoots Awkdokporkguy in the face and gets you bonus points";
				break;

				case "Right click: <br> Shoots Awkdokporkguy in the face and gets you bonus points":
				para.innerHTML="I'm just pulling your leg, there's no right click";
				break;

				case "I'm just pulling your leg, there's no right click":
				para.innerHTML="Wait, did you-";
				break;

				case "Wait, did you-":
				para.innerHTML="I can't believe you actually tried to shoot me in the face!";
				break;



				








			}

		}
	}
}

The Decision JavaScript:
Code:
case "DO NOT CORRECT ME":
				para.style.display="none";
				var correctbtn = document.createElement("BUTTON");
				var correcttext = document.createTextNode("Correct");
				correctbtn.appendChild(correcttext);
				div.appendChild(correctbtn);
				correctbtn.style.color="Green";
				correctbtn.className="correctbtn";

				var donotcorrectbtn = document.createElement("BUTTON");
				var donotcorrecttext = document.createTextNode("Do Not Correct");
				donotcorrectbtn.appendChild(donotcorrecttext);
				div.appendChild(donotcorrectbtn);
				donotcorrectbtn.style.color="Red";
				donotcorrectbtn.className="donotcorrectbtn";

				bsub.style.display="none";

				donotcorrectbtn.style.width="60px";
				donotcorrectbtn.style.height="30px";

				correctbtn.style.width="60px";
				correctbtn.style.height="30px";

				correctbtn.onclick= correctFunction;
				donotcorrectbtn.onclick= donotcorrectFunction;

		
				break;



Thanks
 
Back
Top Bottom