再次返回,需要帮助修复JS游戏
Back again, need help fixing JS game
需要明确的是,这是一个独立的JavaScript游戏,可以帮助我更多地参与语法。
目前,我正在尝试找出一种方法来添加一个list
函数来列出该会话中数组中添加的所有内容(我仍在学习如何实现它以与 cookie 和 HTML 一起使用)。
//We name the functions.
function Person(name, personAge) {
this.name = name;
this.personAge = personAge;
}
function Animal(animalName, species, breed) {
this.animalName = animalName;
this.species = species;
this.breed = breed;
}
function CreateYourOwn(creativeName, species2, power, customAge) {
this.creativeName = creativeName;
this.species2 = name;
this.power = power;
this.customAge = customAge;
}
//We list the arrays.
var Persons = [
];
var Animals = [
];
var Customs = [
];
function creator() {
//I start the prompt to ask the user which one.
var personPrompt = prompt("Welcome to virtual reality! Put in 'person' for person creator, 'animal' for animal creator, and 'custom' for custom creator! Or, if you want to list your creations, type in 'list'! NOTE: All creations will be deleted upon reload.").toLowerCase();
//And this is where I am right now.
switch (personPrompt) {
case 'person':
var name = prompt("Name:").replace(/['"]/g, '');
var age = prompt("Age:").replace(/['"]/g, '');
var person = new Person(name, age);
Persons.push(person);
break;
case 'animal':
var animalName = prompt("What is the name of your animal?");
var species = prompt("What species is it?");
var breed = prompt("What breed is it?");
var animal = new Animal(animalName, species, breed);
Animals.push(animal);
break;
case 'custom':
var creativeName = prompt("What do you call this thing?");
var species2 = prompt("What do you describe as the species as a whole?");
var power = prompt("What can this thing do?(ex. shoot lasers, change eye color, etc)");
var customAge = prompt("How old is this thing?");
var custom = new CreateYourOwn(creativeName, species2, power, customAge);
break;
case 'list':
var list_var = prompt("Which list would you like to view?").capitalize;
switch (list_var) {
case 'Persons':
for (var i = 0; i < Persons.length; i++) {
console.log(Persons[i]);
}
break;
case 'Animals':
for (var m = 0; i < Animals.length; i++) {
console.log(Animals[i]);
}
break;
case 'Customs':
for (var j = 0; i < Customs.length; i++) {
console.log(Customs[i]);
}
}
}
}
while (confirm("Would you like to make another creature ? (If you haven 't already, just click OK.)") === true) {
creator();
}
问题是你的"数组"实际上是对象。
//We list the arrays.
var Persons = {
};
对象没有属于 Array.prototype 的 .push
方法。如果要使用 push,则需要使数组成为实际数组。
var Persons = [];
相关文章:
- 构建HTML5 Canvas/JS游戏
- HTML5 Canvas+js游戏|死亡时重置游戏更改游戏速度
- JS游戏和HTML5画布游戏有什么区别
- 如何为PHP/JS游戏制作倒计时/定时器
- JS游戏中的画布渲染光学错觉(短暂复制的图形)-修复
- 再次返回,需要帮助修复JS游戏
- 独立 JS 游戏帮助:如何将用户输入转换为对象
- 节点.js游戏开发,客户端-服务器数据交换逻辑
- 使用 requestAnimationFrame 的 JS 游戏循环 - 对象函数只调用一次
- 如何将javascript/angular.js游戏板连接到firebase数据库
- 更改每个级别的背景颜色(js游戏)
- 如何制作基于数组的Simon Js游戏
- 拥有一个简单的浏览器内JS游戏,需要它与后端'Ruby脚本一起工作
- JS游戏编程-使用键盘事件蓝牙键盘/iCade与iPad浏览器
- 如何在运行的JS函数中执行函数-修改JS游戏
- 在three.js游戏引擎中拆分javascript文件
- 在three.js游戏中使用cannon.js进行碰撞检测
- HTML5 JS游戏,适用于任何分辨率
- 建议一个好的免费&开源HTML5+JS游戏框架/引擎
- Node.js游戏服务器同时运行多个游戏