Template 1 Javascript Occ Template Structure Template 2 Making Canvas Need Image Included Q43889394
Template 1: Javascript With OCC Template Structure
Template 2: Making a Canvas & How I need the image includedMethod
Using the templates provided above to demonstrate the structureneeded for the program, please do the following program inJavascript using OCC methods (Once again please structure it likethe 1st template above):
F<HTML lang=”en”> <HEAD> <META CHARSET=”UTF-8″> <TITLE>JavaScript ooc</TITLE> <script> //classes are either declared here or imported as files class Main constructor() // Any class variables must have ‘this.’ NOT var. //By default all this.name = “Main” this. Number = 100; //Functions in classes do not have the ‘function’ tag //Function in classes CAN NOT BE USED FOR CALLBACKS! GetMessage() return this.name +”, “+this.Number; ReduceNumber() TO this. Number –; console.log(“The number is now: “+this. Number); //Call backs MUST be global functions that are not part of a class. //Therefore, all controls, buttons, or widgets will have to call back to //a global function – which in turn will use the instance of main we created! function ButtonCallBack () //This will be okay as long as m has been defined //globally before we push the button. m.ReduceNumber(); </script> GetMessage() return this.name +”,”+this.Number; ReduceNumber() this. Number –; console.log(“The number is now: “+this.Number); //Call backs MUST be global functions that are not part of a class. //Therefore, all controls, buttons, or widgets will have to call back to //a global function – which in turn will use the instance of main we created! function ButtonCallBack () //This will be okay as long as m has been defined //globally before we push the button. m.ReduceNumber(); </script> IND </HEAD> <BODY> <HEADER> <H1>JavaScript classes</H1> </HEADER> <button onclick=”ButtonCallBack ()”>Reduce Number </button> <Section ID=”console” style=”border: 2px solid #000;”> LTH </section> <script> //I want to minimize the number of global variables //So I will create ONE instance of the main class //that will hold all of the program variables within it. m = new Main(); console.log (m.GetMessage()); </script> </BODY> </HTML> aa <!DOCTYPE HTML> F<HTML lang=”en”> <HEAD> <Title>”Welcome TO JAVA SCRIPT”</TITLE> </SCRIPT> <!– main class –> <SCRIPT> class Main 1- 1- constructor() 1- this.drawPictures(); drawPictures () //In order to draw the image, you wil need //to make sure hte html image has loaded first! //They will not always appear the first time due to a loading //race condition. var pic = document.getElementById(“slime”); ctx.drawImage (pic,200,0); ctx.drawImage (pic, 400, 75, 100, 100); function onclick() m.drawPictures(); </SCRIPT> </HEAD> <BODY> <HEADERX</HEADER> <H1>Canvas Tutorial</H1> <!–style=”display:none;”–> <IMG src=”img/slime.png” alt=”slime” id=”slime”/> <SECTION id=”Canvas”> <CANVAS width=640 height=480 id=”myCanvas” style=”border: 1px solid black;” onclick=”onclick();”> Your Web-Browser does not support Canvase </CANVAS> </SECTION> <!– call our JavaScript at the end so all html elements are initialized –> <SCRIPT> //This is JavaScript image you woaded first! //In order to draw the image, you wil need //to make sure hte html image has loaded first! //They will not always appear the first time due to a loading //race condition. var pic = document.getElementById(“slime”); ctx.drawImage (pic,200,0); ctx.drawImage (pic, 400,75, 100, 100); function onclick() m.drawPictures(); HILL </SCRIPT> </HEAD> <BODY> <HEADER></HEADER> <H1>Canvas Tutorial</H1> <!–style=”display:none;”–> <IMG src=”img/slime.png” alt=”slime” id=”slime”/> <SECTION id=”Canvas”> <CANVAS width=640 height=480 id=”myCanvas” style=”border: 1px solid black;” onclick=”onclick();”> Your Web-Browser does not support Canvase </CANVAS> </SECTION <!– call our JavaScript at the end so all html elements are initialized –> <SCRIPT> //This is JavaScript //This is a variable pointing at an HTML element… For this class we will allow it. //This is the JavaScript variable pointing at the canvas. var canvas = document.getElementById(“myCanvas”); //This is 2D drawing context for canvas var ctx = canvas.getContext(“20”); m = new Main();//Invoke main to start the program. </SCRIPT> BODY • • • • • • • You will make a simple JavaScript game that will break the canvas up into 64X64 pixel squares (you do not have to visualize this) You will use a 2D array to dynamically draw a simple maze consisting of bricks and trees. o The “bricks” and “trees” will be rendered through Context 2D commands. (Not a picture) There will be one player and at least three different types of monsters. The player and monsters will be (64X64 pixel) images placed on the map. The player will push 1 of four buttons moving their character in that direction one square (You may also use press key call backs if you wish). If the player runs into a monster the player will attack the monster (But not move to the square). After the player has moved all of the monsters will move, if the monster moves on the player it will attack the player (but not move to the square). Monsters and Players cannot move through trees or walls. There will be at least 2 potions on the map that will restore the player’s health if they move on to them. (The potion will then be destroyed after it is collected) If all the monsters have died then print “You Win” on the screen. If the player is killed, then you will print “Game Over”. Both the monsters and the hero will have the following properties: o HP: Health 0 MHP: Max health o ATK: Attack bonus o DEF: Defense bonus O X(X coordinate on the grid, not the pixel value) o Y (Y coordinate on the grid, not the pixel value) O PIC: The variable pointing to the HTML image for the appropriate character. Both the player and the monster will be rendered by images, they will also have a health bar next to them. (You pick the orientation). The images will be rendered on the appropriate grid based on the X and Y value. o Since both the hero and the monster use the same render function you may want to use inheritance. For combat you will follow the equation: Damage = (other, ATK-this.DEF or 1 whichever is higher)”random number 1-6. o Again this could be implemented in a parent class. You will have three monsters with varying difficulty and one hero. o I will let you decide what the attributes should be. The game should be challenging but not impossible. • . • Show transcribed image text F JavaScript ooc //classes are either declared here or imported as files class Main constructor() // Any class variables must have ‘this.’ NOT var. //By default all this.name = “Main” this. Number = 100; //Functions in classes do not have the ‘function’ tag //Function in classes CAN NOT BE USED FOR CALLBACKS! GetMessage() return this.name +”, “+this.Number; ReduceNumber() TO this. Number –; console.log(“The number is now: “+this. Number); //Call backs MUST be global functions that are not part of a class. //Therefore, all controls, buttons, or widgets will have to call back to //a global function – which in turn will use the instance of main we created! function ButtonCallBack () //This will be okay as long as m has been defined //globally before we push the button. m.ReduceNumber();
GetMessage() return this.name +”,”+this.Number; ReduceNumber() this. Number –; console.log(“The number is now: “+this.Number); //Call backs MUST be global functions that are not part of a class. //Therefore, all controls, buttons, or widgets will have to call back to //a global function – which in turn will use the instance of main we created! function ButtonCallBack () //This will be okay as long as m has been defined //globally before we push the button. m.ReduceNumber(); IND JavaScript classes Reduce Number LTH //I want to minimize the number of global variables //So I will create ONE instance of the main class //that will hold all of the program variables within it. m = new Main(); console.log (m.GetMessage());
aa F “Welcome TO JAVA SCRIPT” class Main 1- 1- constructor() 1- this.drawPictures(); drawPictures () //In order to draw the image, you wil need //to make sure hte html image has loaded first! //They will not always appear the first time due to a loading //race condition. var pic = document.getElementById(“slime”); ctx.drawImage (pic,200,0); ctx.drawImage (pic, 400, 75, 100, 100); function onclick() m.drawPictures(); //This is JavaScript
image you woaded first! //In order to draw the image, you wil need //to make sure hte html image has loaded first! //They will not always appear the first time due to a loading //race condition. var pic = document.getElementById(“slime”); ctx.drawImage (pic,200,0); ctx.drawImage (pic, 400,75, 100, 100); function onclick() m.drawPictures(); HILL Canvas Tutorial Your Web-Browser does not support Canvase
Expert Answer
Answer to Template 1: Javascript With OCC Template Structure Template 2: Making a Canvas & How I need the image included Method…
OR