// demo.ts

"use strict";

interface Opponent {
  alias: string;
  health: number;
}

class ComicBookCharacter {
  // by default all class properties have public access
  alias: string;
  health: number;
  strength: number;
  secretIdentity: string;

  attackFunc(opponent: Opponent, attackWith: number) {
    opponent.health -= attackWith;

    console.log(`${this.alias} attacked ${opponent.alias}, who's health = ${opponent.health}`);

    return opponent.health;
  }
}

let storm = new ComicBookCharacter();
storm.alias = "Storm";
storm.health = 100;
storm.strength = 100;
storm.secretIdentity = "Ororo Munroe";

let theBlob = new ComicBookCharacter();
theBlob.alias = "The Blob";
theBlob.health = 1000;
theBlob.strength = 5000;
theBlob.secretIdentity = "Fred J. Dukes";

storm.attackFunc(theBlob, storm.strength);

// demo.ts

"use strict";

interface Opponent {
  alias: string;
  health: number;
}

class ComicBookCharacter {
  // by default all class properties have public access

  constructor(
    // without access level we will get wrong behavior
    public alias: string,
    public health: number,
    public strength: number,
    private secretIdentity: string
  ) {}

  attackFunc(opponent: Opponent, attackWith: number) {
    opponent.health -= attackWith;

    console.log(`${this.alias} attacked ${opponent.alias}, who's health = ${opponent.health}`);

    return opponent.health;
  }

  getSecretIdentity() {
    console.log(`${this.alias} is ${this.secretIdentity}`);
  }
}

let storm = new ComicBookCharacter("Storm", 100, 100, "Ororo Munroe");

let theBlob = new ComicBookCharacter("The Blob", 1000, 5000, "Fred J. Dukes");

storm.attackFunc(theBlob, storm.strength);
storm.getSecretIdentity();

Replace class properties to constructor. Add getSecretIdentity method
Replace class properties to constructor. Add getSecretIdentity method
