打开处理不断给我错误消息

问题描述 投票:0回答:1

错误信息如下:

未捕获类型错误:无法使用“in”运算符在 5Show 堆栈中搜索“$overloads”

该应用程序适用于处理4,但无法打开处理画板或任何其他在线主机

这是代码链接https://github.com/SkyWing3G/STA2.0

问题似乎出现在需要从其他地方输入的 void 方法中,例如:

无效gainMaxHp(int增益){maxHp + =增益;curHp = maxHp;}

java typeerror processing
1个回答
0
投票

OpenProcessing 不再接受处理 java 小程序:草图现在需要移植到 p5.js 才能运行。你的代码仍在处理java。

您可以尝试使用像 processing-p5-convert 这样的工具(或 pde2js 等)来帮助移植代码,但是几乎不可能顺利地自动转换大量代码。

就我个人而言,我会手动移植并首先清理当前的处理java代码(例如,删除冗余代码,将可重用代码进一步封装到当前的函数/类中)。

出于说明目的,您的代码经过稍微调整后运行的processing-p5-convert:

//functional
let stagecount = 0,
  error = 0,
  score = 0; //can click on enemy or not
let clickOnEnemy = false; //can click on bottom continer or not
let clickOnBottom = true; //can user click on heal
let clickOnHeal = true; //is the loot open or not
let lootOpen = false; //can open chest or not
let canOpenLoot = true; //ini player charater
// let player = new Player(); //ini enemies
// let en1 = new Enemy(1);
// let en2 = new Enemy(2);
// let en3 = new Enemy(3); //how many enemies to spawn
// let er = new EnemyTracker(); //generate a random number between 1 to 100
// let random100 = new Random100(); //plaers turn
let player;
let en1, en2, en3;
let er;
let random100;
let urTurn = true; //enemys turn
let en1Turn = false;
let en2Turn = false;
let en3Turn = false; //what text to display
let displayText; //display hit/get hit/heal effect
//boolean effectTime = false;
//what color to display
let effectColor = 1;

function setup() {
  createCanvas(800, 600);
  stroke(20);
  frameRate(10);

  player = new Player(); //ini enemies
  en1 = new Enemy(1);
  en2 = new Enemy(2);
  en3 = new Enemy(3); //how many enemies to spawn
  er = new EnemyTracker(); //generate a random number between 1 to 100
  random100 = new Random100(); //plaers turn
}

function draw() {
  background(255); //fill(255);
  //rect(250,450,300,80,10);
  //fill(0);
  //textSize(50);
  //text("LOAD",340,505);
  switch (
    stagecount //Main Menu
  ) {
    case 0:
      textSize(80);
      fill(0);
      text("STICKMAN", 230, 100);
      text("TURN-BASED", 180, 180);
      text("ADVENTURE", 200, 260); //start button
      if (
        mouseX > 250 &&
        mouseX < 550 &&
        mouseY > 350 &&
        mouseY < 430 &&
        urTurn
      ) {
        fill(140);
        rect(250, 350, 300, 80, 10);
        fill(0);
        textSize(50);
        text("START", 330, 405); //click to enter battle
        if (mouseIsPressed) {
          stagecount = 2;
        }
      } else {
        fill(0);
        textSize(50);
        text("START", 330, 405);
      }
      break; //load
    case 1:
      break; //**battle sceen**
    case 2: //functional
      //*draw maincharacter*
      player.drawPlayer(); //bottom container
      fill(255);
      stroke(0);
      rect(20, 400, 760, 180, 10); //**Attack Heal Void button**
      //*attack button*
      if (
        mouseX > 40 &&
        mouseX < 260 &&
        mouseY > 420 &&
        mouseY < 560 &&
        clickOnBottom
      ) {
        //draw the hovered button
        fill(255, 100, 100);
        rect(40, 420, 220, 140, 10); //text color if allow to click turn black
        if (clickOnBottom) {
          fill(255);
          textSize(50);
          text("Attack", 85, 505);
        } else {
          fill(200);
          textSize(50);
          text("Attack", 85, 505);
        } //allow user to click on enemy
        if (mouseIsPressed) {
          clickOnEnemy = true;
        }
      } else {
        //text color if allow to click turn red
        if (clickOnBottom) {
          fill(255);
          stroke(0);
          rect(40, 420, 220, 140, 10);
          fill(255, 100, 100);
          textSize(50);
          text("Attack", 85, 505);
        } else {
          fill(255);
          stroke(200);
          rect(40, 420, 220, 140, 10);
          fill(200);
          textSize(50);
          text("Attack", 85, 505);
        }
      } //*heal button*
      if (
        mouseX > 290 &&
        mouseX < 420 &&
        mouseY > 420 &&
        mouseY < 560 &&
        urTurn &&
        clickOnBottom &&
        player.healthCheck()
      ) {
        //draw the hovered button
        fill(100, 200, 100);
        rect(290, 420, 220, 140, 10); //text color if allow to click turn black
        if (clickOnBottom) {
          fill(255);
          textSize(50);
          text("Heal", 355, 505);
        } else {
          fill(200);
          textSize(50);
          text("Heal", 355, 505);
        } //allow user to click on enemy
        if (mouseIsPressed) {
          player.gainHp();
          drawEffect(1);
          urTurn = false;
          en1Turn = true;
          en2Turn = true;
          en3Turn = true;
          clickOnEnemy = false;
          clickOnBottom = true;
        }
      } else {
        //text color if allow to click turn green
        if (clickOnBottom && player.healthCheck()) {
          fill(255);
          stroke(0);
          rect(290, 420, 220, 140, 10);
          fill(100, 200, 100);
          textSize(50);
          text("Heal", 355, 505);
        } else {
          fill(255);
          stroke(200);
          rect(290, 420, 220, 140, 10);
          fill(200);
          textSize(50);
          text("Heal", 355, 505);
        }
      } //*void button small chance to loss enemy*
      if (
        mouseX > 540 &&
        mouseX < 660 &&
        mouseY > 420 &&
        mouseY < 560 &&
        urTurn &&
        clickOnBottom
      ) {
        //draw the hovered button
        fill(100, 100, 200);
        rect(540, 420, 220, 140, 10); //text color if allow to click turn black
        if (clickOnBottom) {
          fill(255);
          textSize(50);
          text("Void", 605, 505);
        } else {
          fill(200);
          textSize(50);
          text("Void", 605, 505);
        } //allow user to click on enemy
        if (mouseIsPressed) {
          if (random(1, 100) > 75) {
            er.reduceEnAlive();
          }
          urTurn = false;
          en1Turn = true;
          en2Turn = true;
          en3Turn = true;
          clickOnEnemy = false;
          clickOnBottom = true;
        }
      } else {
        //text color if allow to click turn green
        if (clickOnBottom) {
          fill(255);
          stroke(0);
          rect(540, 420, 220, 140, 10);
          fill(100, 100, 200);
          textSize(50);
          text("Void", 605, 505);
        } else {
          fill(255);
          stroke(200);
          rect(540, 420, 220, 140, 10);
          fill(200);
          textSize(50);
          text("Void", 605, 505);
        }
      } //**spawn enemies**
      //**draw the right foe**
      if (er.loadEnAlive() >= 1 && en1.enHp() > 0) {
        en1.drawFoe(en1.enHp()); //*players movement*
        if (urTurn && clickOnEnemy) {
          //disable bottom click
          clickOnBottom = false; //allow click on enemy
          en1.clickEnemy(); //user attack on their turn
          if (en1.clickEnemy() && urTurn) {
            en1.lowerHp(player.attack());
            drawEffect(3);
            urTurn = false;
            en1Turn = true;
            en2Turn = true;
            en3Turn = true;
            clickOnEnemy = false;
            clickOnBottom = true;
          }
        } //**enemys movement**
        if (en1Turn && en1.enHp() > 0) {
          player.beenHit(en1.enAttack());
          drawEffect(0); //check if the player is alive
          if (!player.isAlive()) {
            //if dead end game
            en1Turn = false;
            en2Turn = false;
            en3Turn = false;
            stagecount = 12;
          } else {
            //if not keep play
            en1Turn = false;
            urTurn = true;
          }
        } else if (en1Turn && en1.enHp() <= 0) {
          //if enemy health = 0 go to next stage
          er.reduceEnAlive();
          score += 50;
        }
      } //**draw the middle foe**
      if (er.loadEnAlive() >= 2 && en2.enHp() > 0) {
        en2.drawFoe(en2.enHp()); //*players movement*
        if (urTurn && clickOnEnemy) {
          //disable bottom click
          clickOnBottom = false; //allow click on enemy
          en2.clickEnemy(); //user attack on their turn
          if (en2.clickEnemy() && urTurn) {
            en2.lowerHp(player.attack());
            drawEffect(3);
            urTurn = false;
            en1Turn = true;
            en2Turn = true;
            en3Turn = true;
            clickOnEnemy = false;
            clickOnBottom = true;
          }
        } //**enemys movement**
        if (en2Turn && en2.enHp() > 0) {
          player.beenHit(en2.enAttack());
          drawEffect(0); //check if the player is alive
          if (!player.isAlive()) {
            //if dead end game
            en1Turn = false;
            en2Turn = false;
            en3Turn = false;
            stagecount = 12;
          } else {
            //if not keep play
            en2Turn = false; //urTurn = true;
          }
        } else if (en2Turn && en2.enHp() <= 0) {
          //if enemy health = 0 go to next stage
          er.reduceEnAlive();
          score += 50;
        }
      } //**draw the left foe**
      if (er.loadEnAlive() == 3 && en3.enHp() > 0) {
        en3.drawFoe(en3.enHp()); //*players movement*
        if (urTurn && clickOnEnemy) {
          //disable bottom click
          clickOnBottom = false; //allow click on enemy
          en3.clickEnemy(); //user attack on their turn
          if (en3.clickEnemy() && urTurn) {
            en3.lowerHp(player.attack());
            drawEffect(3);
            urTurn = false;
            en1Turn = true;
            en2Turn = true;
            en3Turn = true;
            clickOnEnemy = false;
            clickOnBottom = true;
          }
        } //**enemys movement**
        if (en3Turn && en3.enHp() > 0) {
          player.beenHit(en3.enAttack());
          drawEffect(0); //check if the player is alive
          if (!player.isAlive()) {
            //if dead end game
            en1Turn = false;
            en2Turn = false;
            en3Turn = false;
            stagecount = 12;
          } else {
            //if not keep play
            en3Turn = false; //urTurn = true;
          }
        } else if (en3Turn && en3.enHp() <= 0) {
          //if enemy health = 0 go to next stage
          er.reduceEnAlive();
          score += 50;
        }
      } //if no enemy left move to next stage
      if (er.loadEnAlive() <= 0) {
        stagecount = 3;
        er.reset();
      }
      break; //loot menu
    case 3: //*draw maincharacter*
      player.drawPlayer(); //bottom container
      fill(255);
      stroke(0);
      rect(20, 400, 760, 180, 10); //draw village
      //drawVillage();
      //draw open button
      if (
        mouseX > 40 &&
        mouseX < 260 &&
        mouseY > 420 &&
        mouseY < 560 &&
        canOpenLoot
      ) {
        fill(255, 225, 0);
        noStroke();
        rect(40, 420, 220, 140, 10);
        fill(255);
        textSize(50);
        text("Open", 90, 505); //check if mouse clicked or not
        if (mouseIsPressed) {
          lootOpen = !lootOpen;
          canOpenLoot = false; //random loot
          if (random100.loadRandom() > 95) {
            player.gainMaxHp(random(1, 10));
            displayText = "You gain max health";
            score += 100;
            random100.reset();
          } else if (random100.loadRandom() > 65) {
            player.gainHeal(random(1, 5));
            displayText = "You gain more heal power";
            score += 5;
            random100.reset();
          } else if (random100.loadRandom() > 15) {
            player.gainAttack(random(1, 5));
            displayText = "You gain more attack";
            score += 1;
            random100.reset();
          } else {
            displayText = "You found nothing";
            random100.reset();
            score += 1;
          }
        }
      } else {
        //disabled button color grey else black
        if (canOpenLoot) {
          fill(255);
          stroke(0);
          rect(40, 420, 220, 140, 10);
          fill(0);
        } else {
          fill(255);
          stroke(150);
          rect(40, 420, 220, 140, 10);
          fill(150);
        }
        textSize(50);
        text("Open", 90, 505);
      } //draw display text
      //if chest can be opened display default text
      if (canOpenLoot) {
        displayText = "You found some loot";
      }
      textSize(20);
      text(displayText, 320, 460, 200, 100); //move on button
      if (mouseX > 540 && mouseX < 660 && mouseY > 420 && mouseY < 560) {
        fill(150);
        noStroke();
        rect(540, 420, 220, 140, 10);
        fill(255);
        textSize(50);
        text("Moveon", 570, 505); //check if mouse clicked or not
        if (mouseIsPressed) {
          if (random(100) > 75) {
            lootOpen = false;
            stagecount = 4;
          } else {
            lootOpen = false;
            er.reset();
            en1.restEn();
            en2.restEn();
            en3.restEn();
            en1Turn = false;
            en2Turn = false;
            en3Turn = false;
            urTurn = true;
            stagecount = 2;
          }
          canOpenLoot = true;
        }
      } else {
        fill(255);
        stroke(150);
        rect(540, 420, 220, 140, 10);
        fill(0);
        textSize(50);
        text("Moveon", 570, 505);
      } //draw chest
      stroke(0);
      if (lootOpen) {
        fill(155);
        rect(500, 70, 150, 80);
      } else {
        fill(255);
        rect(500, 100, 150, 50);
      }
      fill(255);
      rect(500, 150, 150, 100);
      rect(560, 150, 30, 20);
      break; //village healing boost MaxHp
    case 4: //draw village
      drawVillage(); //*draw maincharacter*
      player.drawPlayer(); //bottom container
      fill(255);
      stroke(0);
      rect(20, 400, 760, 180, 10); //rest button
      if (
        mouseX > 40 &&
        mouseX < 260 &&
        mouseY > 420 &&
        mouseY < 560 &&
        canOpenLoot
      ) {
        fill(100, 200, 100);
        noStroke();
        rect(40, 420, 220, 140, 10);
        fill(255);
        textSize(50);
        text("Rest", 90, 505); //check if mouse clicked or not
        if (mouseIsPressed) {
          lootOpen = !lootOpen;
          canOpenLoot = false;
          player.gainMaxHp(0);
          displayText = "You are fully healed";
        }
      } else {
        //disabled button color grey else black
        if (canOpenLoot) {
          fill(255);
          stroke(0);
          rect(40, 420, 220, 140, 10);
          fill(0);
        } else {
          fill(255);
          stroke(150);
          rect(40, 420, 220, 140, 10);
          fill(150);
        }
        textSize(50);
        text("Rest", 90, 505);
      } //draw display text
      //if chest can be opened display default text
      if (canOpenLoot) {
        displayText = "You found a safe house";
      }
      fill(0);
      textSize(20);
      text(displayText, 320, 460, 200, 100); //move on button
      if (mouseX > 540 && mouseX < 660 && mouseY > 420 && mouseY < 560) {
        fill(150);
        noStroke();
        rect(540, 420, 220, 140, 10);
        fill(255);
        textSize(50);
        text("Moveon", 570, 505); //check if mouse clicked or not
        if (mouseIsPressed) {
          if (random(100) > 50) {
            lootOpen = false;
            stagecount = 3;
          } else {
            lootOpen = false;
            er.reset();
            en1.restEn();
            en2.restEn();
            en3.restEn();
            en1Turn = false;
            en2Turn = false;
            en3Turn = false;
            urTurn = true;
            stagecount = 2;
          }
          canOpenLoot = true;
        }
      } else {
        fill(255);
        stroke(150);
        rect(540, 420, 220, 140, 10);
        fill(0);
        textSize(50);
        text("Moveon", 570, 505);
      }
      break; //End Screen
    case 12:
      fill(0);
      textSize(80);
      text("Game Over", 225, 200);
      textSize(50);
      text("Score : " + score, 230, 270); //quit
      if (mouseX > 250 && mouseX < 550 && mouseY > 450 && mouseY < 530) {
        fill(140);
        rect(250, 450, 300, 80, 10);
        fill(0);
        textSize(50);
        text("Quit", 350, 505); //click to enter battle
        if (mouseIsPressed) {
          exit();
        }
      } else {
        fill(0);
        textSize(50);
        text("Quit", 350, 505);
      }
      break;
  }
} //save random numbers
class EnemyTracker {
  enAlive;
  constructor() {
    this.enAlive = random(1, 3);
  } //reduce enemies
  reduceEnAlive() {
    if (this.enAlive >= 1) {
      this.enAlive -= 1;
    } else {
      this.enAlive = 0;
    }
  } //return saved value
  loadEnAlive() {
    return this.enAlive;
  } //refreash the saved random number
  reset() {
    this.enAlive = random(1, 3);
  }
} //save random number
class Random100 {
  randNum;
  constructor() {
    this.randNum = random(1, 100);
  } //return saved value
  loadRandom() {
    return this.randNum;
  } //refreash the saved random number
  reset() {
    this.randNum = random(1, 100);
  }
} //create enemy class bandit
class Enemy {
  constructor(e) {
    //location
    this.xpos = 0;
    this.ypos = 0; //status
    
    this.maxHp = 10;
    this.curHp = 10;
    this.attack = 5;
    this.heal = 0;
    if (e == 1) {
      this.xpos = 650;
      this.ypos = 130;
    } else if (e == 2) {
      this.xpos = 500;
      this.ypos = 130;
    } else if (e == 3) {
      this.xpos = 350;
      this.ypos = 130;
    }
  } //return attack
  enAttack() {
    return this.attack;
  } //return the current hp
  enHp() {
    return this.curHp;
  } //draw enemy and their status
  drawFoe(hpDisplay) {
    //Statues
    fill(255, 100, 100);
    textSize(20);
    text("HP: " + hpDisplay, this.xpos - 30, this.ypos - 70);
    fill(120);
    text("Attack: " + this.attack, this.xpos - 40, this.ypos - 45);
    fill(255);
    stroke(0); //head
    ellipse(this.xpos, this.ypos, 50, 50); //body?
    line(this.xpos, this.ypos + 25, this.xpos, this.ypos + 100); //leftarm
    line(this.xpos, this.ypos + 25, this.xpos - 30, this.ypos + 80); //rightarm
    line(this.xpos, this.ypos + 25, this.xpos + 30, this.ypos + 80); //leftleg
    line(this.xpos, this.ypos + 100, this.xpos - 30, this.ypos + 150); //rightleg
    line(this.xpos, this.ypos + 100, this.xpos + 30, this.ypos + 150);
  } //control click on enemy
  //int mainCharaAttack
  clickEnemy() {
    let clicked = false;
    noStroke();
    if (
      mouseX > this.xpos - 50 &&
      mouseX < this.xpos + 50 &&
      mouseY > this.ypos - 100 &&
      mouseY < this.ypos + 160
    ) {
      //onclick hit enemy
      if (mouseIsPressed) {
        fill(155);
        textSize(100);
        text("Hit", this.xpos - 50, this.ypos);
        clicked = true;
      } //on hover change color
      fill(50, 50, 50, 50);
    } else {
      noFill();
      clicked = false;
    }
    rect(this.xpos - 50, this.ypos - 100, 100, 260, 10);
    stroke(20);
    return clicked;
  } //after enemy get hit reduce their current hp
  lowerHp(damage) {
    if (this.curHp - damage > 0) {
      this.curHp -= damage;
    } else {
      this.curHp = 0;
    }
  } //reset enemy status
  restEn() {
    this.maxHp = 10;
    this.curHp = 10;
    this.attack = 5;
    this.heal = 0;
  }
} //draw effect or not
function drawEffect(effectColor) {
  noStroke();
  if (effectColor == 0) {
    //enemy attack red
    fill(255, 100, 100, 155);
  } else if (effectColor == 1) {
    //heal green
    fill(100, 255, 100, 155);
  } else if (effectColor == 2) {
    //chest gold
    fill(255, 225, 0, 155);
  } else {
    //default player hit enemy grey
    fill(80, 80, 80, 155);
  } //left&right
  rect(0, 0, 100, 600);
  rect(700, 0, 100, 600); //up&down
  rect(100, 0, 600, 100);
  rect(100, 500, 600, 100);
  stroke(20);
} //Main character class tracking hp a/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Player {
  drawPlayer() {
    this.xpos = 200;
    this.ypos = 230;
    fill(255);
    stroke(0); //head
    ellipse(this.xpos, this.ypos, 100, 100); //body?
    line(this.xpos, this.ypos + 50, this.xpos - 20, this.ypos + 200); //leftarm
    line(this.xpos, this.ypos + 50, this.xpos - 70, this.ypos + 120); //rightarm
    line(this.xpos, this.ypos + 50, this.xpos + 50, this.ypos + 120); //status
    fill(30, 200, 30);
    textSize(30);
    text("HP: " + this.curHp, 260, 390);
    fill(120);
    text("Attack: " + this.attack, 400, 390);
    fill(255, 150, 150);
    text("Heal: " + this.heal, 560, 390);
  }
  healthCheck() {
    let temp = true; //if maxhp reached return false
    if (this.curHp == this.maxHp) {
      temp = false;
    }
    return temp;
  } //gain more heal
  gainHeal(gain) {
    this.heal += gain;
  } //gain more attack
  gainAttack(gain) {
    this.attack += gain;
  } //gain more Max Hp
  gainMaxHp(gain) {
    this.maxHp += gain;
    this.curHp = this.maxHp;
  } //gain more Current Hp
  gainHp() {
    if (this.curHp + this.heal < this.maxHp) {
      this.curHp += this.heal;
    } else {
      this.curHp = this.maxHp;
    }
  } //loose hp
  beenHit(enAttack) {
    if (this.curHp - enAttack <= 0) {
      this.curHp = 0;
      this.alive = false;
    } else {
      this.curHp -= enAttack;
    }
  } //check if the player is still alive
  isAlive() {
    return this.alive;
  } //return attack
  attack() {
    return this.attack;
  }
}
function drawVillage() {
  let xpos = 350,
    ypos = 50;
  fill(255);
  stroke(20); //roof
  triangle(xpos + 100, ypos, xpos, ypos + 100, xpos + 200, ypos + 100);
  line(xpos + 100, ypos, xpos + 300, ypos);
  line(xpos + 300, ypos, xpos + 400, ypos + 100);
  line(xpos + 400, ypos + 100, xpos + 200, ypos + 100);
  rect(xpos + 230, ypos - 30, 50, 30); //body
  rect(xpos + 30, ypos + 100, 340, 150);
  line(xpos + 170, ypos + 100, xpos + 170, ypos + 250);
  rect(xpos + 100, ypos + 130, 50, 120);
  rect(xpos + 200, ypos + 130, 30, 30);
  rect(xpos + 230, ypos + 130, 30, 30);
  rect(xpos + 200, ypos + 160, 30, 30);
  rect(xpos + 230, ypos + 160, 30, 30);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/p5.min.js"></script>

请注意,它尚未清理/封装/修复错误,但它说明了在线获取草图的过程(在 OpenProcessing 或其他网站上)。

© www.soinside.com 2019 - 2024. All rights reserved.