Code Monkey home page Code Monkey logo

Comments (10)

olistic avatar olistic commented on May 4, 2024

Hello, could you please give an example of what you want to achieve, or how you are currently doing it?

from warriorjs.

Kamahl19 avatar Kamahl19 commented on May 4, 2024

Thanks for quick reply.

Well at the beginning of each level, I would like to find out which wall is closer, left or right. I also want to set the _health to 20 so that it does not use the value from previous level. I also want to set if we already hit wall in this level etc..

from warriorjs.

olistic avatar olistic commented on May 4, 2024

I think using a constructor for your warrior will fulfill your needs. Something like this:

class Player {
  constructor() {
    this._health = 20;
    this._hasHitWall = false;
  }

  playTurn(warrior) {
    // Cool code
  }
}

The Player constructor will be executed at the beginning of each level, even in Epic mode.

from warriorjs.

olistic avatar olistic commented on May 4, 2024

And don't use globals! With instance properties you'll be fine :)

from warriorjs.

Kamahl19 avatar Kamahl19 commented on May 4, 2024

Yea I am just replacing the globals :) Ok thanks for the idea. Also can I somehow access warrior in constructor?

from warriorjs.

olistic avatar olistic commented on May 4, 2024

Not directly, but this came to my mind that might solve whatever you want to do with the warrior:

class Player {
  constructor() {
    this._isFirstTurn = true;
  }

  playTurn(warrior) {
    if (this._isFirstTurn) {
      // Do whatever you want with warrior
      this._isFirstTurn = false;
    }
  }
}

It might be ugly but may do the trick ;)

from warriorjs.

Kamahl19 avatar Kamahl19 commented on May 4, 2024

Yea I just did that but wanted a cleaner solution :) Thanks a lot for quick responses

from warriorjs.

Kamahl19 avatar Kamahl19 commented on May 4, 2024

Dont you plan to deploy this online and let users create their AIs in online editors and then submitting them and compeating with each other?

from warriorjs.

Kamahl19 avatar Kamahl19 commented on May 4, 2024

Maybe also let users create new levels to test AIs properly with much more levels. Or generate levels randomly so that AIs cant be created just for known levels but are generally working in whatever level.

from warriorjs.

olistic avatar olistic commented on May 4, 2024

Yes, deploying a web version of the game is in the roadmap. I encourage you to open new issues with ideas. I'll close this to keep it neat.

Thank you for the support!

from warriorjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.