Improve Your JavaScript Skills by Playing This Game - WarriorJs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

WarriorJS is a fun way to practice and improve your software development skills. Write Javascript to instruct the warrior to battle enemies, rescue captives and make it to the stairs alive.

Legend tells of a legendary sword, forgotten to the ruins of an abandoned tower. Thousands of warriors have set off on a quest for the sword, whose bearer would become enlightened in the JavaScript language.

In this video we complete the first 6 levels of WarriorJS.

👍︎︎ 3 👤︎︎ u/CodingWithAdam 📅︎︎ Dec 06 2021 🗫︎ replies
Captions
you are a warrior climbing a tall tower on each floor you need to write javascript to instruct the warrior to battle enemies rescue captives and reach the stairs alive are you ready for the challenge this is coding with adam and let's get to the code if you enjoy my videos please subscribe like and share this is warrior js a fun way to practice and improve your software development skills legend tells of a legendary sword forgotten to the ruins of an abandoned tower thousands of warriors have set off on a quest for the sword whose bearer would become enlightened in the javascript language are you that legendary warrior well first let's find out if it's me so let's give this game a quick try let's start by clicking that play for free button we'll start with beginner baby steps for players new to warrior js i'll go ahead and enter my name over here and click venture forth you see yourself before a long hallway with stairs at the end there's nothing in the way on the left hand side is where we write our code and click run on the right hand side it shows us what the level looks like and gives us some instructions about what we can do with our warrior so over here this is the level this little at symbol over here is our warrior adam with 20 health points and we have to get to the stairs at the end so there's some stairs here now for every turn that we do we can only do one action the only action that we have right now is walk this is really simple they give us this code over here which has a player and the player has a method called play turn which takes in the warrior and this is our warrior over here so to get started all we have to do is take our warrior and we can walk let's get our warrior to walk forward by default the warrior will walk forward or we can specify forward inside of our method over here let's go ahead and walk now as we walk you can see turns go by and for each turn we do one action which is walking forward we walk to the end of the hallway and go up the stairs for the level we get a total score based on our warrior score time bonus and clear bonus next we can go ahead and just click dismiss over here to get rid of that and then go to the next level what's also kind of cool too is you can replay your actions by hovering over the turns let's go to that next level as we enter level 2 it's too dark to see anything but you smell sludge nearby we're introduced to our first enemy and we have a new ability warrior.attack and now we can attack our enemies taking a look at the level over here we can see our players starting on the far left as we move forward we're going to counter our first enemy sludge the game also provides us with a tip our warrior has a method called feel with the feel method we can determine what's in the space in front of us or behind us and one of the methods on feel is is empty we can determine whether or not the space is empty if the space isn't empty we're going to go ahead and start attacking whatever's in front of us the first thing we're going to do is we're going to ask our warrior to feel in front of them and see whether or not the space is empty if the space is empty then we're going to go ahead and move forward if the space isn't empty we're gonna go ahead and start attacking we'll click that run button to run the game and then we're gonna speed it up over here to four times and you can see we're starting to attack we've defeated our enemies and we got to the stairs as we enter the third level the air feels thicker than before there must be a horde of sludge in this level we have multiple enemies to defeat let's go ahead and run our current code just to see what would happen as our warrior starts to attack this sludge as you can see our health decreases as the sludge attacks the warrior then we move on to the next sludge which will reduce our health even more and if we just speed that up we'll see that eventually we're going to have so little health left that we're going to be defeated by one of the sludge we get to the last sludge with two health points remaining and ultimately are defeated it looks like brute force isn't gonna work so we can't just go forward attacking we're gonna have to rest and heal the game shows us how to do this in the readme over here it explains that we have health and we can access the warrior's health by checking the health method there's also a max health which tells us what our health would be if it were full in addition to that we can also rest whenever we rest we gain 10 percent of our max health back we start with 20 hit points and 10 would be 2. we're going to use a simple strategy whenever the square in front of us is empty we're going to stop and rest if our health is less than our max health the way we're going to do this is inside the is empty over here we're going to put an if statement and we're going to say warrior.health and if our health is less than our max health then we're going to go ahead and rest we just call warrior.rest like that and then inside the else if our health is at our max we're going to go ahead and walk forward let's go ahead and try that now as we're fighting this sludge over here we're going to lose a bunch of health so we got down to 14 over there and you can see our health is now increasing because we're resting and we'll let the game continue and then as the game continues over here you see we're fighting this sludge over here then as soon as we defeat this sludge there's an empty space then we start to rest so it says adam rests receives two health up to 18 get back up to 20 then we go on and attack the next sludge and then we'll do the very same thing over here for this sludge and we'll do the same thing for this one at the end and then we'll go up the stairs as you enter level 4 you can hear bow strings being stretched we've encountered a new enemy an archer i have a feeling that our current strategy won't work let's go ahead and click the run button and see what happens we're going to attack that first sludge and defeat it and this sludge is actually bigger than the other ones that we encountered before this one is called thick sludge after we defeat this sludge you're gonna see our health is gonna be pretty low so we're gonna start healing and as we start to heal the archer starts to shoot at us and our current logic doesn't say move forward while we're being attacked so slowly the archer kills us as we heal we can only heal two health points while the archer takes three damage out of us with their arrows so eventually we succumb to death and it's game over the strategy that we're going to use is an aggressive one our health is being reduced while we're trying to heal we're going to go ahead and move forward and attack in order to do this we're going to track our warriors health and then between turns we're going to check if it's changing if it's decreasing that means we should move forward and try to attack whatever is hurting us let's start by tracking our health one quick thing we're going to do is at the very end of the playturn function over here is we're going to say this.health is equal to our warrior.health the other thing to keep in mind is that this.health will be null on our first turn we'll say if this.health is equal to null then we're going to go ahead and set this dot health equal to our warrior dot health now the part that we're going to modify is when we sense that the space in front of us is empty when that space is empty and our health is decreasing rather than increasing so it means our resting isn't working quite well then we want to do is we want to move forward and attack so what we're going to do over here is we're going to check our rest and before we're allowed to rest we're going to call a method we're going to say is and this is a method that we're going to create and we're going to say is it the same or greater than last turn very long method name over here and inside this method we're also going to pass in our warrior so you can see this new method that we've created is the health the same or greater than the last turn and we're gonna do is below over here below the play turn we'll go ahead and implement that new method it takes in the warrior and then what we're gonna do inside here is we're just gonna say return and we're going to say warrior dot health is greater than or equal to this dot health i'm just splitting this out just so it's a little bit easier to read and use our other option would be to take this code that we have over here and put it inside the if statement however fine with this function name over here it really gives you the intent of what we're trying to achieve let's go ahead and run that code first thing we're going to do is attack that thick sludge once we've defeated the thick sludge we're going to try and heal now we go ahead and we try and heal we notice our health goes from ten to seven so we move forward attack the archer and we're going to be left with one health now our warrior can go ahead and heal to max health once our warrior is healed up we can go ahead and finish off that last enemy and ascend up those stairs as we enter the fifth level you hear cries for help captives must need rescuing looking at the level diagram over here we can see that we have this new type of character we have a captive now our captives are pretty weak they only have one health and if we were to hit them well they would die but we need to rescue our captives in our code normally if we notice that it's not empty but this first if statement over here says feel is empty we go ahead and we walk or we rest otherwise we go ahead and just attack anything in this situation we don't want to just attack anything we want to go ahead and rescue our captives so how do we do that well our warrior can go ahead deal get the type of unit so it's either be an enemy or a captive the captive is defined by is bound so this means that they're tied up and if they're tied up that means we need to rescue them and our warrior can go ahead and say warrior.rescue let's modify our code to do that so over here where we're doing our attack we're now going to decide to either attack or rescue somebody the way we're going to do that is our warrior is going to say warrior.feel and we're going to figure out which unit is in front of us which is either an enemy or a captive and a captive will be defined by is bound and if someone is bound that means the warrior will then rescue them we'll just call rescue and then if it's not somebody we're rescuing well we're just gonna go ahead and assume it's an enemy and attack let's go ahead and try this code so go ahead and run it we can see that we've released the captive from their bonds we're going ahead and we're attacking the archers and then we have a second archer over here we're gonna move forward attack that archer and you can see we've killed that archer now we're going to heal back up go for that last thick sludge over there and then rescue the captive there you go we go up the stairs to the next level as we enter level 6 we realize that the wall behind us feels a bit further away in this room and we hear more cries for help for this room we're gonna need to address two issues one is we're gonna have to go backwards and get the captive two we're gonna have to move forward and attack these enemies which will be a unique challenge of their own but we'll get to that in a second let's start by moving backwards we'll go ahead and we'll start with the code over here before our check for empty in front of us we're going to go ahead and do an if statement this if statement is going to have a new variable called has effect wall and has checked wall over here we'll just put parentheses and we'll put an else over here so the first thing we're going to do is has checked wall then inside here we're going to instruct our warrior to feel behind them and check if it's a wall this way they know whether or not they've checked the wall so what we do for this is we just do feel with a backward and then if we look at the documentation it doesn't tell you on here but if we look at the documentation there is a method called is wall we can go ahead and figure out whether or not it's a wall behind us if it is a wall behind us then what we're going to do is we're going to say this dot has checked wall is equal to true then we can also tell our warrior to go ahead and just walk forward we can either tell it to walk forward like that or just call walk which will automatically walk forward then once it's checked and there's a wall behind it it'll just continue to execute the rest of the code as normal moving forward however in our situation over here there is no wall behind us this code would work in the other levels but not in this level so next inside the code over here we'll do another else do an else if and we're going to ask our warrior to feel behind them and is it empty is what we're going to ask but once again we have to do backward and then is empty if it is empty we're going to go ahead and we're going to walk backwards if it's not empty we'll do another lcf over here and our warrior can go ahead and get our bound unit we'll do a feel or backward and then we'll do a get unit and we're going to ask if that unit is bound if that unit is bound then we can go ahead and rescue our captives so we'll go ahead and do a rescue and for rescue we also have to do the direction so we'll do backwards and for one extra little check over here just to make sure that something does exist is we can copy the get unit put that there and just double check that it's not null so by default this will do a not null or you can do a does not equal null like that if you wanted to but javascript is pretty nice so that will automatically check whether or not it's null let's go ahead and test our code so our warrior will move backwards rescue the captive hit the wall then start moving forward then we're going to go ahead and attack the thick sludge now remember the thick sludge will cause quite a bit of damage to us because the thick sludge has 24 hp then we're gonna go try and attack the archers but we don't have enough health to solve this problem we actually need to move backwards heal back up then move forward and attack those archers let's go ahead and implement that code here's the code that we're going to be implementing now when we defeat the thick sludge over here there's an empty space in front of us when there's an empty space we check our health and if we can we try and heal otherwise we assume that we're being attacked we move forward and we attack those archers this is where we change the code over here we're going to go ahead and add an if statement we're going to check our warriors health we're going to make the assumption that if our health is less than 10 we should probably move backwards because we don't have enough health to face the enemies ahead of us i'll go ahead here and i'm just going to move this over here actually i'll leave that there and we're going to walk backward then in our else statement over here what we'll do is we'll then walk forward because at this point we're assuming that we've healed up beyond 10 and we should start moving forward to attack our enemies let's go ahead and try this code out i'm going to click run we're going to walk backwards rescue our captive hit the wall then we're going to go forward again attack that sludge so i'm going to speed that up over there now after we defeat the sludge and archer should hit us then we're going to move back go back up to 20 move forward attack of the archers then go up those stairs and win and there you have it we've beat the first six levels of warrior js one thing to note is that this is one interpretation of how to write the code i'm sure that you can come up with different ways to beat these levels if you enjoyed this video please subscribe like and share
Info
Channel: Coding With Adam
Views: 526
Rating: undefined out of 5
Keywords: WarriorJs, Playing WarriorJS, Level 1, level 2, level 3, level 4, level 5, how to beat level 4, level 4 warriorJS, level 4 warrior JS, level 4 solution, level 6 warriorJS, level 6 warriorJS solution, how to beat level 6, how to beat level 6 warriorJS, javascript game learn, learn javascript by playing warriorjs, warrior js, improve at js, javascript tutorial, be better at javascript, learn javascript, fun javascript learning game, learning game, learn js with gamejs war
Id: f1AQMOJu90s
Channel Id: undefined
Length: 15min 29sec (929 seconds)
Published: Mon Dec 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.