RPG game

Task 1

  • Реализовать классы Hero и Monster
  • дать возможность создавать героев
    new Hero(name, heroClass)
  • дать возможность создавать монстров
    new Monster(monsterClass)
  • и герои и монстры могут быть только определенных классов, см спецификацию. В случае создания персонажа несуществующего класса - вернуть исключение "Incorrect character class provided" 
  • свойства и методы героев и монстров так же указыны в спецификации

Task 2 Advanced

  • Реализовать класс Game, согласно спецификации
  • Реализовать удобный механизм наполнение игры героями и монстрами
  • Реалтзовать управление состоянием игры, и переходы между состояниями

Game data

heroClasses = {
	warrior: {
		charClass: "Warrior",
		life: 30,
		damage: 4
	},
	rogue: {
		charClass: "Rogue",
		life: 25,
		damage: 3
	},
	sorcerer: {
		charClass: "Sorcerer",
		life: 20,
		damage: 5
	}
}
monsterClasses = {
	zombie: {
		charClass: "Zombie",
		life: 8,
		damage: 4
	},
	skeleton: {
		charClass: "Skeleton",
		life: 10,
		damage: 6
	},
	holem: {
		charClass: "Holem",
		life: 15,
		damage: 6
	}
}
statuses = {
	idle      : "Idle",
	progress  : "In progress",
	finished  : "Finished"
}
maxMonsters = 2

Hero                                Monster

Game object

game = {
    status // string, current game status, "Idle" is the initial one
    hero // object - hero object that is in game
    monsters // array of monsters in game, max = maxMonsters
}

Game requirements

// Change game status from "Idle" to "In progress", should be possible only if hero and monsters are defined
// returns:
//     "Your journey has started, fight monsters" - if ok
// throw new Error(
//     "Cannot start journey, populate the world with hero and monsters first") - if smth went wrong
beginJourney()


// Change game status from "In progress" to "Finished", possible only if hero or both monsters are dead(their life equals 0)
// retures:
//        "The Game is finished. Monstrs are dead. Congratulations" - if both monsters are dead
//        "The Game is finished. Hero is dead :(" - if hero is dead
//        "Don`t stop. Some monsters are still alive. Kill`em all" - if its not time yet
finishJourney() 

// set game.hero to hero instance
// accepts: instance of Hero class
// throw:    
//        "Only one hero can exist" - if hero is already defined
//        "Only hero instance can be hero" - if not hero was passed to function
// returns: 
//        "Hero created, welcome HERO_NAME" - if ok
addHero()

// adds monster to game.monsters array
// accepts: instance of Monster class
// throw:
//        "Only 2 monsters can exist" - if there are already 2 monsters defined
//        "Only monster Instances can become monsters" - if not monster was passed to function
// returns: 
//        "Monster Created, MONSTER_CHARACTER_CLASS appeared in the world" - if ok
addMonster()


// Initiate a battle between hero and monster, one after another, they should attack each other, starting from hero,
// and until someone life is not 0
// returns string 'Hero win' or 'Monster win', depending on who has life points left
fight()

Hero and Monster

// instance of hero should have

.name // string
.charClass // sting  
.life	// number
.damage	// number
.getName() // function returning name
.getCharClass() // function returning character class

// accepts - target - instance of Monster
// returns:
//         "I will attack only monsters" - in not monster was passed as target
//         "Hero attacked, " + GENERAL_ATTACK_MESSAGE
.attack(target) //
		
// instance of Monster should have

.charClass // sting  
.life	// number
.damage	// number
.getName() // function returning "I am MONSTER_CHARACTER_CLASS I don`t have name"
.getCharClass() // function returning character class

// accepts - target - instance of Hero
// returns:
//         "I will attack only Hero" - in not hero was passed as target
//         "Monster attacked, " + GENERAL_ATTACK_MESSAGE
.attack(target) //
		
// attack logic
// decrease amount of target life on the value of attackers damage
// accepts - target - instance of Monster or Hero
// returns GENERAL_ATACK_MESSAGE:
//         "CHARACTER_CLASS killed" - this action will kill target
//         "done AMOUNT_OF_DAMAGE damage to CHARACTER_CLASS";
.attack(target) 
		

General attack

// decrease amount of target life on the value of attackers damage
// accepts - target - instance of Monster or Hero
// returns:
//         "CHARACTER_CLASS killed" - this action will kill target
//         "done AMOUNT_OF_DAMAGE damage to CHARACTER_CLASS";
.attack(target) 
		

Game object

Should have properties

  • status // String, representing current game status 
  • hero // Object, representing hero  
  • monsters // Array of Objects, representing monsters

 

Should have methods

  • beginJourney // Change game status to "In Progress". It should be impossible to begin journey if game misses heroe and 2 monsters
  • addHero // To add hero to game
  • addMoster // To add monster to the game

 

OOP in JavaScript Practice

By Viktor Shevchenko

OOP in JavaScript Practice

  • 1,629