When I read about github’s WarriorJS project, the project described it as “an exciting programming and ai game.” Ok, I have to confess that AI was attracted to WarriorJS. After playing two levels, I still have no idea what the game has to do with ai. The best part of the game, though, is writing Javascript to break the game’s levels

The game has no cool sound and light effects, no graphics interface, only a text interface (reminiscent of the popular MUDs of old), and you can Code in the VS Code editor, Then run the program in VS Code’s built-in Console to see if your Javascript Code can successfully solve the tasks the game gives you. It sounds like fun, but it’s all text interface and a little confusing at first. Here’s how to start the game and how to play it. Hopefully this game will help you remember how fun it was to learn programming in the first place

Game Background

In WarriorJS, you wear warrior-like armor and climb a tall tower to reach the JavaScript sword at the top. Legend has it that the sword bearer was enlightened by using JavaScript, but be warned: this process is not easy. On each floor, you need to write JavaScript to instruct the warrior to fight the enemy, rescue the prisoner, and walk up the stairs alive.

Whether you’re a novice programmer or a JavaScript master, WarriorJS will put your skills to the test. Are you up to the challenge?

(Above game description translated from github open source project game introduction)

Start installing the game

1. Install using NPM

NPM install - global @ warriorjs/cliCopy the code

2. Build your own warriors

If you want to create warriorjs, click Yes. Then select a name and a level for the warrior to challenge.

The warriorjs program will create a directory for you to use to access the warriorjs directory: Begineer. Use VS Code to open the directory and read readme. md. It’s written in Markdown syntax

The first pass is quite simple as long as walk to the stairs even if the clearance, inside the @ is a soldier you, > represents the stairs, and your health HP = 20, there are soldiers of the ability, the first pass only walk warrior. Walk ()

Start writing the program to complete the first level. Open player.js and type warrior.walk() in the playTurn function

Go to the VS Code terminal and enter the warriorjs command. You will be asked if you want to challenge the warriorjs to the next level. Warriorjs will update the readme.md to give you the next mission statement, like Mission Impossible

Open readme.md, OK the second mission is coming, you will find a new map, in addition to walking ability (Attack ()), but also the ability to feel(), you still walk to the stairs, But there is one obstacle Sludge in the middle, and crossing this obstacle will cost you 12 health and attack() will cost you 5 health

Use feel().isempty () to determine if you have an obstacle in front of you, if so use attack(), if not continue

Open play.js and start designing how your warrior will pass. You can see how the warrior will die without changing the code, but in order not to spend too much time on it, here is my code

class Player {    
   playTurn(warrior) {            
    if(warrior.feel().isEmpty()){                        
       warrior.walk();            
    } else{ warrior.attack(); }}}Copy the code

Attach () and save player.js. Run the warriorjs program. You will see if the warriorjs program runs according to your javascript logic. You’re good again. To continue the challenge, press Y,
The first level is easy, and then it gets harder and harder

Is this game addictive to you? Congratulations, this game will make you love programming, too

Welcome to the Soft & Share website