Question

In: Computer Science

Design a text-based game. The game should involve starting from some point in the universe and...

Design a text-based game. The game should involve starting from some point in the universe and seeking or exploring. For example, you could start at the mouth of a cave and seek gold in the halls and caverns. Write out the logic in English and/or pseudocode. Write several lines of JavaScript code that will start the game going, containing control flow statement(s).

Solutions

Expert Solution

Author: Rishabh jain

Date:07/09/2019

<html>

<body>
<div id="images">
</div>
<div id="text">
</div>

<input id="input" onkeydown='submitPlaceName(this)' placeholder='Type Place Name and Enter to Begin'>
<div id="buttonBox">
</div>
<script>


var images = document.getElementById("images");
var text = document.getElementById("text");
var buttonBox = document.getElementById('buttonBox');
var input = document.getElementById('input');

var place;

//this is how after we type in the character name and hit enter
//we will add the name to the variable, remove the input box and start our first scenario
input.onkeypress = function(event) {
console.log(input.value);
if (event.key == "Enter" || event.keyCode == 13) {
place = input.value;
input.parentNode.removeChild(input)
advanceTo(scenario.two)
}
};


//this changes the text and puts in your characters name
var changeText = function(words) {
text.innerHTML = words.replace("Your Place", place);
};

//this takes the image link and puts it in the proper format, sending it to the html
var changeImage = function(img) {
images.style.backgroundImage = "url(" + img + ")";
};


//this looks at the number of options we have set and creates enough buttons
var changeButtons = function(buttonList) {
buttonBox.innerHTML = "";
for (var i = 0; i < buttonList.length; i++) {
buttonBox.innerHTML += "<button onClick="+buttonList[i][1]+">" + buttonList[i][0] + "</button>";
};
};

//this is what moves the game along
var advanceTo = function(s) {
changeImage(s.image)
changeText(s.text)
changeButtons(s.buttons)
};


//this is the object that holds each scenario, the more you add the more options there are
//scenario = {}
var scenario = {
one: {
image: "https://s9.postimg.org/eceo9mp73/5860028206_d66810105f_b.jpg",
text: "You have finally decided to take a walk. What the your name?\n",
},
two: {
image: "https://s9.postimg.org/9p8m7v1u7/6899639786_d517c4cce3_z.jpg", //house
text: "Your dog yanks at the leash. You see an old abandoned house. Strangely, the door is wide open. What do you want to do?",
buttons: [["Turn and run", "advanceTo(scenario.three)"],["Enter The House", "advanceTo(scenario.four)"]]
},
three: {
image: "https://1.bp.blogspot.com/-83pWE4JxQxM/ViiOd_7nGTI/AAAAAAAADUg/yCJ8iAB-gMY/s1600/postapoc5.jpg",//"https://s4.postimg.org/t1g20apst/261819008_d4316c1bdf_o.jpg",
text: "A wild gang of rabid dogs are gaining on you. Against your better judgement you enter the creepy house for saftey. Your dog is whincing and may be injured.",
buttons: [["continue", "advanceTo(scenario.four)"]]
},
four: {
image: "https://s6.postimg.org/kz5m1cnkh/2919478782_c343d14be6_b.jpg",
text: "Your dog has run, barking loudly, into the basement. You wonder what's down there. The door jammed when you slammed it behind you. You are going to need something to pry it back open",
buttons: [["Follow your Dog Downstairs", "advanceTo(scenario.five)"],["Search the Kitchen for a knife", "advanceTo(scenario.five)"]]
},
five: {
image: "https://s6.postimg.org/kz5m1cnkh/2919478782_c343d14be6_b.jpg",
text: "TO BE CONTINUED...",

},
  
};


//this is the code that starts the game
advanceTo(scenario.one);

</script>
</body>

</html>


Related Solutions

THONNY: This project focusses on dealing with strings of text. The starting point for this is...
THONNY: This project focusses on dealing with strings of text. The starting point for this is a variable, ‘text’, that contains a random collection of words. The aim of this assignment is to iterate over the words and find the length of the longest word. text = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam rhoncus facilisis consequat. " "Nam ultricies quis dolor vitae placerat. Integer in ante sit amet eros egestas porttitor. Phasellus " "semper lectus dapibus volutpat...
Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode)...
Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack.   When the player attacks, it will pick a random number between 0 and up to the maximum damage the player does, and then subtract that...
Q2: A particle is moving in a constant force field starting at rest from some point...
Q2: A particle is moving in a constant force field starting at rest from some point (x1, x1’) to some higher point (x2, x2’). The potential energy is mgx, where g is the acceleration imparted by the force. Find the path that allows the particle to accomplish the transit in the least possible time.  
JAVA 1) You are provided an implementation of a text-based adventure game. Currently the game responds...
JAVA 1) You are provided an implementation of a text-based adventure game. Currently the game responds to directional movements that allow you to move your adventurer around a maze (that is read from a text file). Add the ability to save (and load) the game using object serialization. Write the serialization of the file out to a default filename SavedGame.dat. Make sure that you take care of any exceptions that may occur when reading or writing to a file (for...
Question 2 A text-based adventure game has several types of player. The code for the game...
Question 2 A text-based adventure game has several types of player. The code for the game uses the following class, Character to define all the shared elements for different types of player characters (Warrior, Wizard etc). 1. public class Character { 2. private String name; 3. private int life; 4. protected int hitPoints; 5. public Character(String name, int life, int hitPoints) { 6. this.name = name; 7. this.life = life; 8. this.hitPoints = hitPoints; 9. } 10. public void setHitPoints(int...
Suppose a game piece is initially at the starting point of the board. We repeatedly flip...
Suppose a game piece is initially at the starting point of the board. We repeatedly flip a fair coin and the piece is moved one step left or right on the board depending on whether the coin shows heads or tails. Approximate the probability that after 400 flips the piece is no more than 10 steps away from the starting position. Assume the board is infiniteso you don’t need to worry about hitting the edge. The answer of Probability equal...
Design a second experiment to test the thin lens equation. It should involve a distinctly different...
Design a second experiment to test the thin lens equation. It should involve a distinctly different situation. Describe the outcome.
Write a short text based game using C++ were you can chose the gender of the...
Write a short text based game using C++ were you can chose the gender of the character, than choose between two location, desert or forest. If either location is chosen than you can choose to either stay at your spot or travel to find help. If player chose desert, than choosing either to stay or travel can be led to death by heat exhaustion or saved randomized, or if forest is chosen, than it can be either death of starvation...
1) based on the text  What does the text imply is the positive return from "investing" in...
1) based on the text  What does the text imply is the positive return from "investing" in accounts receivables? As is true of other current assets, accounts receivable should be thought of as an investment. The level of accounts receivable should not be judged too high or too low based on historical standards of industry norms, but rather the test should be whether the level of return we are able to earn from this asset equals or exceeds the potential gain...
Q2. Consider a game of tennis from deuce onward. Starting at the state of deuce, if...
Q2. Consider a game of tennis from deuce onward. Starting at the state of deuce, if the server wins, the score is ad-in. If the server then loses the next point, the game is back to deuce. However, if the server wins two points in a row, he wins the game. Similarly, starting at the state of deuce, if the returner wins, the score is ad-out. If the returner then loses the next point, the game is back to deuce....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT