运行JavaScript

时间:2018-03-01 19:44:04

标签: javascript node.js

我很难过。运行此代码时,我没有收到任何错误或未定义的错误只是一个空白的返回,然后是一个新的命令行。我在命令提示符下运行了大约100次,但仍然没有。我想了100次之后应该显示“祝贺信息”。任何人都可以看看我错过了什么?提前谢谢。

//Player Class

function Player(name, weapons) {
    this.playerName = name;
    this.playerHealth = 10;
    this.playerStrength = 2;
    this.playerWeapons = weapons;
}

Player.prototype.applyDamage = function(damage) {
    this.playerHealth = this.playerHealth - damage;
    console.log(this.playerName + " " + "has sustained " + " " + this.playerHealth + " " + "amount of damage.");
}

Player.prototype.isAlive = function() {
    if(this.playerHealth > 0)
    	return true;
    else
    	return false;
}

Player.prototype.attacksWith = function() {
    var random = Math.floor(Math.random() * 8);
    return (this.weapon[random]);
}

//Minion Class

function Minion(minion, health, strength) {
    this.minionName = 'Minion';
    this.minionHealth = 5;
    this.minionStrength = 2;
}

Minion.prototype.applyDamage = function(damage) {
    this.minionHealth = this.minionHealth - damage;
    console.log(this.minionName + " " + "has sustained " + " " + this.minionHealth + " " + "amount of damage.");
}

Minion.prototype.isAlive = function() {
    if(this.minionHealth > 0)
    	return true;
    else
    	return false;
}

Minion.prototype.attack = function(playerName) {
    playerName.applyDamage(this.minionHealth);
}

//Weapons Class
function Weapons(weapon) {
    this.weaponName = weapon;
    this.weapondamage = Math.floor(Math.random() * 5) + 1;
}

var weaponsCache = [];

for (var i = 0; i < 8; i++) {

var axe = new Weapons("skullCracker");
var hxfx = new Weapons("Hexaflexagon");
var blade = new Weapons("Balmung");
var mario = new Weapons("cappy");
var fire = new Weapons("Fire Breath");
var staff = new Weapons("Magic Staff");
var hrp = new Weapons("Harpe");
var CobaltWep = new Weapons("Cobalt Rifle");

var w = new Weapons([i]);
weaponsCache[i] = w;
}

var player = [];
var i = 0;
while (i < 8) {
	
	var m = new Player();
	player[i] = m;
	i++;
}

//Game Class

function Game(players, minions) {
this.players = [];
this.minions = [];
}

 function attack(player, minion) {
    while (playerName.isAlive() && minionName.isAlive()) {
    actualDamage = player.strength * this.damage();
    minion.applyDamage(actualDamage);

    if (minion.isAlive())
		minion.attack(player);
	else
		break;
	}
}

function createMinions() {
    var i = 0;
    while (i > 20) {

        var m = new Minion();
        minion[i] = m;
        i++;
    }
}

 function createPlayers() {
  var player = []; {
    var ph = new Player("Prophetic Hamster", weaponsCache);
    var mm = new Player("Mighty Mathematician", weaponsCache);
    var sieg = new Player ("Siegfried", weaponsCache);
    var bd = new Player ("Blue Dragon", weaponsCache);
    var ip = new Player("Iron Professor", weaponsCache)
 }
 
Game.prototype.play = function() {

console.log("Simulating Battle...");

createMinion();
createPlayer();

var i = 0,
count = 0;

while (i < 20) {
	
	if (minions[i].isAlive())
		count++;
	}

    if (count == 20) {
		
		i = 0;
		var flag = 0;
		
		while (i < 8) {
			
			if (players[i].isAlive())
				
			flag++;
			}
			
			while (count == 20 && flag > 0) {
				
				var randomPlayer, randomMinion;
				
				randomPlayer = Math.floor(Math.random() * 8);
				randomMinion = math.floor(Math.random() * 20);
				weapon = player.attackWith();
				attack(minions);
				attack(players);
				}
				
	count = 0;
	i = 0;
	
	while (i > 20) {
		
		if (minions[i].isAlive())
			count++;
		}
		
	flag = 0;
	i = 0;
	
	while (i < 8) {
		if (players[i].isAlive())
			flag++;
		}

    if (flag > count)
        console.log("Congratulations!! You have defeated Scarlet Byte");
	}
  }
}

0 个答案:

没有答案