Programming, Music, Games. Creation.

Dragon Slayer – Simple Java Game

dragonslayer_codeacademy dragonslayer_java

Java


public class game {
 public static void main(String[] args) {
 /* Coded by Bermuda
 imnotbermuda.com */
 boolean slaying = false;
 int round=1;

/*Player variables*/
 int youHit;
 int playerHP = 730;
 int playerMP = 5;
 int playerMagic;
 int playerATT;
 int playerINT;

/*Dragon's variables*/
 int dragonHit;
 int dragonHP = 1150;
 int dragonMP = 2;
 int dragonMagic;
 int dragonATT;
 int dragonINT;

//starts :D
 System.out.println("A wild Dragon has appeared! Face it or die!");
 slaying=true;

while(slaying){

/*Procs and Damage adjusted here! every new loop new variables.*/
 playerATT = (int) Math.floor(Math.random() * 120 + 55.7);
 playerINT = (int) Math.floor(Math.random() * 200 + 150);
 dragonATT = (int) Math.floor(Math.random() * 220 + 35);
 dragonINT = (int) Math.floor(Math.random() * 250 + 200);
 youHit = (int) Math.floor(Math.random()+ 0.43);
 dragonHit = (int) Math.floor(Math.random()+ 0.25);
 playerMagic = (int) Math.floor(Math.random()+ 0.48);
 dragonMagic = (int) Math.floor(Math.random() + .22);

System.out.println("Dragon HP/MP : " + dragonHP + "/" + dragonMP);
 System.out.println("Player HP/MP : " + playerHP + "/" + playerMP);

System.out.println("------Round " + round + "!------");

if(youHit>=0.5){
 System.out.println("You slashed the dragon for " + playerATT + " damage!");
 dragonHP -= playerATT;
 } else {
 System.out.println("Dragon dodged your attack");
 }

if(playerMagic>=0.5 && playerMP>0){
 System.out.println("*");
 System.out.println("Your fiery magic power bursts in fury!");
 double randommagic = Math.random();//Random magic procs here rather than above to avoid computer calculating extra uneccesary variable in certain situations.
 if (randommagic < 0.6){
 System.out.println("Arcane bolt! The dragon took " + playerINT + " arcane damage!");
 dragonHP -= playerINT;
 } else if (randommagic < 0.85){
 System.out.println("Lightening strike! The dragon took " + playerINT*2 + " lightening damage!");
 dragonHP -= playerINT*2;
 } else {
 System.out.println("Meteor strike! The dragon took " + playerINT*3 + " astronomical Damage!");
 dragonHP -= playerINT*3;
 }
 playerMP -= 1;//every magic costs 1 mana
 System.out.println("*");
 }

//dragonHP check is here to avoid dragon attacking the player after it being slain.
 if(dragonHP<=0){
 slaying = false;
 System.out.println("*");
 System.out.println("VICTORIOUS. You have just slayed the dragon and saved the world!!");
 break;
 }

if(dragonHit>=0.5){
 System.out.println("Dragon strikes you for " + dragonATT + " damage!");
 playerHP -= dragonATT;
 } else {
 System.out.println("You've dodged dragon's attack!");
 }

if(dragonMagic>=0.5 &amp;&amp; dragonMP>0){
 System.out.println("*");
 System.out.println("Dragon slowly takes its breath.. You can feel what's coming.");
 System.out.println("FIRE BREATH! The dragon breathes deadly fire at you! You took " + dragonINT + " fire damage!");
 System.out.println("*");
 playerHP -= dragonINT;
 dragonMP -= 1;
 //only one magic for the dragon. It does not shoot stars from its mouth.
 }

if(playerHP<=0){
 slaying = false;
 System.out.println("*");
 System.out.println("Your sight slowly fades away.. You have been slain.");
 break;
 }

round += 1;
 }
 }
}

<span style="line-height: 1.5em;">

Java (in some other version)

/* Coded by Bermuda
imnotbermuda.com */
var slaying = false;
var round=1;

/*Player variables*/
var youHit;
var playerHP = 730;
var playerMP = 5;
var playerMagic;
var playerATT;
var playerINT;

/*Dragon's variables*/
var dragonHit;
var dragonHP = 1150;
var dragonMP = 2;
var dragonMagic;
var dragonATT;
var dragonINT;

/*Prints out the status of the player and the dragon*/
var printStatus = function(){
 console.log("Dragon HP/MP : " + dragonHP + "/" + dragonMP);
 console.log("Player HP/MP : " + playerHP + "/" + playerMP);
}

/*rerollVariables fuction
Damange balancing and proc settings are all done here*/
var rerollVariables = function(){
 playerATT = Math.floor(Math.random() * 120 + 55.7);
 playerINT = Math.floor(Math.random() * 200 + 150);
 dragonATT = Math.floor(Math.random() * 220 + 35);
 dragonINT = Math.floor(Math.random() * 250 + 200);
 youHit = Math.floor(Math.random()+ 0.43);
 dragonHit = Math.floor(Math.random()+ 0.25);
 playerMagic = Math.floor(Math.random()+ 0.48);
 dragonMagic = Math.floor(Math.random() + .22);
}

//starts :D
console.log("A wild Dragon has appeared! Face it or die!");
slaying=true;

while(slaying){

rerollVariables();//get new damage numbers and procs every round
printStatus();

console.log("------Round " + round + "!------");

if(youHit==true){
 console.log("You slashed the dragon for " + playerATT + " damage!");
 dragonHP -= playerATT;
 } else {
 console.log("Dragon dodged your attack");
 }

if(playerMagic==true &amp;&amp; playerMP>0){
 console.log("*");
 console.log("Your fiery magic power bursts in fury!")
 var randommagic = Math.random()//Random magic procs here rather than above to avoid computer calculating extra uneccesary variable in certain situations.
 if (randommagic < 0.6){
 console.log("Arcane bolt! The dragon took " + playerINT + " arcane damage!");
 dragonHP -= playerINT;
 } else if (randommagic < 0.85){
 console.log("Lightening strike! The dragon took " + playerINT*2 + " lightening damage!");
 dragonHP -= playerINT*2;
 } else {
 console.log("Meteor strike! The dragon took " + playerINT*3 + " astronomical Damage!");
 dragonHP -= playerINT*3;
 }
 playerMP -= 1;//every magic costs 1 mana
 console.log("*");
 }

//dragonHP check is here to avoid dragon attacking the player after it being slain.
 if(dragonHP<=0){
 slaying = false;
 console.log("*");
 console.log("VICTORIOUS. You have just slayed the dragon and saved the world!!");
 break;
 }

if(dragonHit==true){
 console.log("Dragon strikes you for " + dragonATT + " damage!");
 playerHP -= dragonATT
 } else {
 console.log("You've dodged dragon's attack!");
 }

if(dragonMagic==true &amp;&amp; dragonMP>0){
 console.log("*");
 console.log("Dragon slowly takes its breath.. You can feel what's coming.")
 console.log("FIRE BREATH! The dragon breathes deadly fire at you! You took " + dragonINT + " fire damage!");
 console.log("*");
 playerHP -= dragonINT;
 dragonMP -= 1;
 //only one magic for the dragon. It does not shoot stars from its mouth.
 }

if(playerHP<=0){
 slaying = false;
 console.log("*");
 console.log("Your sight slowly fades away.. You have been slain.");
 break;
 }

round += 1;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s