Code Monkey home page Code Monkey logo

Comments (3)

olistic avatar olistic commented on May 4, 2024

No, it isn't. May I ask why do you want to obtain your current location? Maybe I can think on other things you can do to get the same results.
About your idea, the comingFrom variable should be a property of the Player object (like this._comingFrom). If not, you won't be able to get it value in the following turn.

from warriorjs.

nylki avatar nylki commented on May 4, 2024

No, it isn't. May I ask why do you want to obtain your current location?

To mark if the current position is a dangerous location when I am moving away from it (more than 2 enemies in feel range). If at any next turn I come back close there, I can check before walking, if it is actually a dangerous location that you might want to avoid. This of course only works, if enemies are not moving (i am at level 4 currently, so not sure if thats gonna happen).

About your idea, the comingFrom variable should be a property of the Player object (like this._comingFrom). If not, you won't be able to get it value in the following turn.

To your second remark: I have been able to store data outside of Player that remains in memory. (defining some variables before using in the beginning).

Here is my current (really messy 😨 ) code: https://gist.github.com/nylki/1f812d079343227397d2
I want to refactor some stuff before I continue to next levels, so it doesn't get more messy.
Also will try out some new ECMA6 features! Arrow functions are already really useful.

from warriorjs.

olistic avatar olistic commented on May 4, 2024

You can store your warrior's position in an array with X and Y, starting at [0, 0], and the locations you found out to be dangerous in another array:

class Player {
  constructor() {
    this._warriorPosition = [0, 0];
    this._dangerousLocations = [];
    // ...
  }

  // ...
}

Then, anytime you consider your position to be dangerous, you can push it to your dangerousLocations array:

if (this.isSurrounded(warrior)) {
  this._dangerousLocations.push(this._warriorPosition);
}

Of course, you'll have to update your current position each time you walk (I recommend creating an auxiliar function that receives the walking direction and returns the new position, relative to the current one).

And about storing data outside the Player class, I recommend not to do so. Depending on the way you are doing it, it can cause you problems in the epic mode, in which each level is played right after the previous one, without interruption.

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.