Commit be6aca93 authored by Chingiz's avatar Chingiz 💻

gitignore is set

parent c7061e90
**/node_modules/**
\ No newline at end of file
/out
\ No newline at end of file
import * as readline from "readline-sync";
export class Tool {
public toolName: string = "Tool";
public capacity: number = 100;
public action(): void {
this.capacity -= 10;
}
}
export class Saw extends Tool {
public override toolName: string = "Saw";
public override action(): void {
super.action();
if (this.capacity !== 0 || this.capacity > 0) {
console.log("============================================");
console.log("ZZZZZZZZZZZZ", `Capacity: ${this.capacity}`);
console.log("============================================");
}
}
}
export class Axe extends Tool {
public override toolName: string = "Axe";
public override action(): void {
super.action();
if (this.capacity !== 0 || this.capacity > 0) {
console.log("============================================");
console.log("Тук Тук Тук", `Capacity: ${this.capacity}`);
console.log("============================================");
}
}
}
export class Drill extends Tool {
public override toolName: string = "Drill";
public override action(): void {
super.action();
if (this.capacity !== 0 || this.capacity > 0) {
console.log("============================================");
console.log("DDDDRRRRRRRRRRRRRRR", `Capacity: ${this.capacity}`);
console.log("============================================");
}
}
}
export class Hammer extends Tool {
public override toolName: string = "Hammer";
public override action(): void {
super.action();
if (this.capacity !== 0 || this.capacity > 0) {
console.log("============================================");
console.log("Bam Bam Bam", `Capacity: ${this.capacity}`);
console.log("============================================");
}
}
}
export class Screwdriver extends Tool {
public override toolName: string = "Screwdriver";
public override action(): void {
super.action();
if (this.capacity !== 0 || this.capacity > 0) {
console.log("============================================");
console.log("Scrrrrrrrrrrr", `Capacity: ${this.capacity}`);
console.log("============================================");
} else {
}
}
}
export class Robot {
public tool: Tool | null;
public name: string;
constructor(name: string = "D2R") {
this.tool = null;
this.name = name;
}
setup_tool(tool: Tool) {
this.tool = tool;
}
drop_tool() {
this.tool = null;
console.log("============================================");
console.log("Tool has been droped!");
console.log("============================================");
}
action() {
if (!this.tool) {
console.log("============================================");
console.log("I don't have any of tools! :(");
console.log("============================================");
} else if (this.tool?.capacity && this.tool.capacity > 0) {
this.tool.action();
} else {
console.log("============================================");
console.log(
"Your tool is broken and it does not work properly!\nPlease, drop this tool and get enother one."
);
console.log("============================================");
}
}
}
type TRobotTools = {
saw: Tool;
hammer: Tool;
screwdriver: Tool;
axe: Tool;
drill: Tool;
};
export class Control {
public robot: Robot;
public tools: TRobotTools = {
saw: new Saw(),
hammer: new Hammer(),
screwdriver: new Screwdriver(),
axe: new Axe(),
drill: new Drill(),
};
constructor() {
this.robot = new Robot();
}
start() {
let out: boolean = true;
while (out) {
const answerFromUser: string | null = readline.question(
"Choose one of the commands: \n1) See my tool\n2) Use my tool\n3) Drop my tool\n4) Choose one of the tools\n5) Exit:\n "
);
switch (answerFromUser) {
case "1":
console.log("============================================");
console.log("I am using ", this.robot.tool?.toolName || "Nothing");
console.log("============================================");
break;
case "2":
this.robot.action();
break;
case "3":
this.robot.drop_tool();
break;
case "4":
const answer = readline.question(
"Please, choose one of the tool: \n1) Saw\n2) Hammer\n3) screwdriver\n4) Axe\n5) Drill\n"
);
switch (answer) {
case "1":
this.robot.setup_tool(this.tools.saw);
break;
case "2":
this.robot.setup_tool(this.tools.hammer);
break;
case "3":
this.robot.setup_tool(this.tools.screwdriver);
break;
case "4":
this.robot.setup_tool(this.tools.axe);
break;
case "5":
this.robot.setup_tool(this.tools.drill);
break;
default:
console.log("============================================");
console.log("Please, choose correct option");
console.log("============================================");
break;
}
break;
case "5":
out = false;
default:
console.log("============================================");
console.log("Please, choose correct command");
console.log("============================================");
break;
}
}
}
}
import { Control } from "./classes";
const startControl = new Control();
startControl.start();
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment