Dragon Slayer: Extended


#1

So I thought about how I could make the game better and I thought about using the rock paper scissors games computer decion making to also make the dragon attack you. Do I have the neccessary skills to do so or is there something I would have to learn before doing this?


#2

Yes, you should have the skills. Think careful, write the steps of your program on a piece of paper before started coding so you know how the program will roughly look.

Just curious, what exactly is your plan?

Anyway, you might find yourself stuck, if you do, break it down in small steps, add console.log statements to so where things go wrong, take a part of the code if there is a problem, and try to fix it before implanting it in your program


#3

Well in the rock paper scissors game the computer could also choose one of the three options. I didn't have a plan while writing this just an idea. I thought I could somehow implent that in here and make some kind of fight happen between the player and the dragon.


#4

You surely can make that happen :slightly_smiling:


#5

I will get to work right now. Thank you for answering.


#6

that sounds like fun! i want to try that, too.

if you get something, perhaps we can compare our tactics?

regardless, please post your solution. would love to see it.


#7

I got something, but one part of it doesn't work. I added more endings and a little bit complexer (Is that a word?) fighting system. I will post my solution when I get on PC. Comparing seems fun, I would like to see your solution too.


#8

So, this here is my code and the part that doesn't work is this part: else{
console.log("You run away as hard as you can.");
}
I haven't been able to get the computer to rad this piece of code. Even if my answer is different, it always read the if statement.

var compare = function(dragon, player) {
if(dragon === player) {
return "After hours of fighting it seems you are equal at strenght. This fight could go on forever.";
}
else if(dragon > player) {
return "You kick the dragon in it's knee, with that anger he burns you.";
}else{
return "The dragon is defeated! Incredible!";
}
};
var dragon = Math.floor(Math.random()*8 + 1);
var player = Math.floor(Math.random()*5 +1);

var dragonDamage = Math.random();
var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damageThisRound = Math.floor(Math.random()*8 + 1);
var totalDamage = 0;
while(slaying) {
slaying = false;
if(youHit = 1) {
console.log("You dealed " + damageThisRound + " damage to the dragon!" );
totalDamage += damageThisRound;
if(totalDamage >=7) {
console.log("You slew the dragon. You are a dragon slayer!");
slaying = false;
}
else{
if(0 < dragonDamage < 0.33) {
console.log("The dragon burninates you. You are toasted!");
}
else if(0.34 < dragonDamage < 0.66) {
var userAnswer = prompt("Your left arm is torn off by the dragon, do you ran away or continue fighting?");
if(userAnswer = "Its just a flesh wound") {
console.log("You decide to stay and fight.");
compare(dragon,player);
}else{
console.log("You run away as hard as you can.");
}
}else{
console.log("You dodge the dragons attack by a second.");
compare(dragon,player);
}
}
}
else{
console.log("The dragon burninates you. You are toasted.");
}
}


#9

Do i need to check it? Or where you going to do this thing together?


#10

let me have a hack away at this dragon problem first and once i've worked myself into a corner, please feel free to step in and nudge me in the right direction?

oh, this is fun!!

now i need to step up my game and produce one, too.


#11

...but of course, if @lord_wrath wants your immediate input, i'll just be quiet and go to my corner.


#12

if this exercise was a movie, right here is the fight sequence/choreography part of it. using the structure of Rock/Paper/Scissors to plan out the moves that the Dragon and the Slayer would make and the riposte. tested and it seems to work with no problems that I can see.

next up is figuring out how to incorporate into our original DragonSlayer exercise and utilize Math.floor(Math.random) to do that.

it's a different approach from what you are doing @lord_wrath but guess that's the fun of it!

@stetim94 feel free to interject here if you'd like, particularly where you think my terminology is incorrect. still trying to get that down so that when I make notes about coding to myself in the future, i'll know what i'm talking about. or so others will know what i was attempting.

    // prompt to input slayer value from specific parameters
    var slayer = prompt("Parry, thrust, or dodge?");
        if (slayer==="parry") {
            console.log("Deflection!");         // to test
        }
        else if (slayer==="thrust") {
            console.log("On point!");           // to test
        }
        else if (slayer==="dodge") {
            console.log("Back up!");            // to test
        }
        else {
            console.log("Delay and you fail."); // to test for misprints
        }

    // random math to set conditional properties for dragon maneuvers
    var Jabberwocky = Math.random();
        if (Jabberwocky < 0.34) {
            Jabberwocky = "slash";
        } 
        else if(Jabberwocky > 0.67) {
            Jabberwocky = "back";
        } 
        else {
            Jabberwocky = "flambe";
        }
    console.log("Jabberwocky " + Jabberwocky);  // to test

    // FIGHT!
    var compare = function(choice1, choice2) {
        if (choice1 === "thrust") {
            if (choice2 === "flambe") {
                return "Burnt to a crisp.";  // end
            }
            else if (choice2 === "slash") {
                return "Flash of talons and sword.";
                //hit = Math.floor(Math.random() * 2);
            }
            else { //thrust back
                return "A hit!"; // add more damage value?
                //hit = Math.floor(Math.random() * 2);  
            }
        }
        else if (choice1 === "dodge") {
            if (choice2 === "back") {
                return "Circlling around the prey.";
                //hit = Math.floor(Math.random() * 2);
            }
            
            else if(choice2 === "flambe") {
                return "Just missed that one.";
                //hit = Math.floor(Math.random() * 2);
            }
            else { // dodge slash
                return "Live to fight again.";
                //hit = Math.floor(Math.random() * 2);
            }
        }
        else if (choice1 === "parry") {
            if (choice2 === "slash") {
                return "A draw!";
                //hit = Math.floor(Math.random() * 2);
            }
            else if (choice2 === "back") {
                return "Confusion amuck.";
                //hit = Math.floor(Math.random() * 2);
            }
            else {  // parry flambe
                return "Singed Slayer eyebrow.";
                //hit = Math.floor(Math.random() * 2);
            }    
        }
        else {                // returns for mistypes from slayer variable input 
            return "Planning another strategy.";
            //hit = Math.floor(Math.random() * 2);
        }
    };
    console.log(compare(slayer,Jabberwocky));

#13

Looks good, you happy with what you coded?


#14

From what I can understand you are trying to add some way for the dragon and the slayer to fight each other until one of their health reaches zero. Correct me if I'm wrong. I like your approach as well. I will also try to improve my code to go further. Let's show each other our code again when we are finished.


#15

I am happy with what I've coded but at the same time I think there is still room left for improvement. As I progress more in the course I can add new things to the game.


#16

Very good, there is almost always room for improvement, i am sure if progress you can upgrade the game


#17

thanks @lord_wrath @stetim94 . this is fun. yeah, i''ve got some more tweaking to do. will post when i get closer to something or until i start banging my head against the wall.

pleased with the action-response interplay I was able to control. so every time slayer input is "thrust" and the random math passes "slash", the return will be "Flash of talons and sword."; if random math passes "flambe", however, "Burnt to a crisp." is the return. the ability for user to select their action and then to have the random response for the dragon is exactly what I was looking for.

next up is making the script more recursive. from what i'm able to make out, the "return" ends the execution of the function, so there is only action==>response==>end of code. would like for it to loop back in as was done with the dragonslayer exercise.

    var slay = true;                                
    var hit = Math.floor(Math.random() * 2);
    var damage = Math.floor(Math.random() * 5 + 1);
    var damageTotal = 0;                            

    while (slay) {                                    
        console.log("Twas brillig, and the slithy toves...");
      if (hit) {
        damageTotal += damage;    
        console.log("One, two, one, two, with " + damageTotal + " and through!");
            if (damageTotal >= 4) {
                console.log("O frabjous day! Callooh! Callay!");
                slay = false; 
            } else {
                hit = Math.floor(Math.random() * 2);            // <== replace this here w/ console.log(compare(slayer,Jabberwocky));
            }
      } else {
        console.log("The manxome foe prevails.");
        slay = false;
      }
    }

what i can make out is that hit = Math.floor(Math.random() * 2); plays a role in that somehow and will do more experiments to see how that can be done within the Fight coding.

replacing the hit math function with console.log(compare(slayer,Jabberwocky)); and adding math function to the return statements in Fight coding does activate recursion but in funny ways.

it will repeat "Burnt to a crisp." over and over instead of different return statements. plus, after you're "Burnt to a crisp." you shouldn't be resurrected over and over again to eventually slay the dragon. so trying to figure out how to end sensibly. for Burnt return statement and the last else, i didn't add the hit math code at all to, so recursing somehow.

back to the drawing board.