Write a constructor Ghost, that takes a color argument, and the x and y coordina
ID: 3808629 • Letter: W
Question
Write a constructor Ghost, that takes a color argument, and the x and y coordinates. The constructed object should store the ghost color, and the x and y coordinates. The x and y coordinates are on a 16 times 16 plane, with wrap around. Define four methods, up/down/left/right, using the prototype mechanism for Ghost. Also define a toString method, using the prototype mechanism for Ghost. Test your ghosts. For this exercise, you are allowed to use any resource you wish as long as you give the source. (for example, stack overflow) Hand in you listing, and at least 3 tests. You can use chalk and chrome, just chrome, or node, or any other JavaScript system.Explanation / Answer
I have used javascript to define above problem statements:
using System;
public class Ghost
{
int x = 16;
int y = 16;
color xcolor,ycolor;
Ghost(int x,int y){
this.x=xcolor(255,0,0);//red color
this.y=ycolor(255,255,255);//white color
}
function up(){
this.name='up'
this.set_name=function(name){
this.name=name;
Console.log('name');
}
}
function down(){
this.name='down'
this.set_name=function(name){
this.name=name;
Console.log('name');
}
}
function left(){
this.name='left'
this.set_name=function(name){
this.name=name;
Console.log('name');
}
}
function right(){
this.name='left'
this.set_name=function(name){
this.name=name;
Console.log('name');
}
}
var up = up();
up.toString();
var down = down();
down.toString();
var left = left();
left.toString();
var right=right();
right.toString();
public static void Main()
{
Console.log(up());
Console.log(down());
Console.log(left());
Console.log(right());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.