在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
题目: 了解神话故事盘古开天辟地或者女娲开世造物,通过typescript程序模拟出天地的变化过程或者万物的衍生过程
参考博客园大神: https://www.cnblogs.com/tansm/p/TypeScript_Handbook.html https://www.runoob.com/w3cnote/getting-started-with-typescript.html 不知道这个题目是要做什么的,我瞎想了下面的程序: class Pangu { static welcome01 = "开天辟地了"; welcome02: string; welcome03() { if (this.welcome02) { return "Hello, " + this.welcome02; } else { return Pangu.welcome01; } } } var welcome04: Pangu; welcome04 = new Pangu(); alert(welcome04.welcome03()); var welcome05: typeof Pangu = Pangu; welcome05.welcome01 = "盘古的呼吸变成了天"; var welcome06:Pangu = new welcome05(); alert(welcome06.welcome03()); var welcome07: typeof Pangu = Pangu; welcome07.welcome01 = "盘古的声音变成了大地"; var welcome08:Pangu = new welcome05(); alert(welcome08.welcome03()); var welcome09: typeof Pangu = Pangu; welcome09.welcome01 = "盘古的眼睛变成了云"; var welcome10:Pangu = new welcome05(); alert(welcome10.welcome03()); var welcome11: typeof Pangu = Pangu; welcome11.welcome01 = "盘古的四肢变成了雷声"; var welcome12:Pangu = new welcome05(); alert(welcome12.welcome03()); var welcome13: typeof Pangu = Pangu; welcome13.welcome01 = "盘古的肌肤变成了太阳和月亮"; var welcome14:Pangu = new welcome05(); alert(welcome14.welcome03()); var welcome15: typeof Pangu = Pangu; welcome15.welcome01 = "盘古的血液变成了江河"; var welcome16:Pangu = new welcome05(); alert(welcome16.welcome03());
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>TypeScipt作业</title> <script type="text/javascript" src="homework.js"></script> </head> </html>
编译之后的js var Pangu = /** @class */ (function () { function Pangu() { } Pangu.prototype.welcome03 = function () { if (this.welcome02) { return "Hello, " + this.welcome02; } else { return Pangu.welcome01; } }; Pangu.welcome01 = "开天辟地了"; return Pangu; }()); var welcome04; welcome04 = new Pangu(); alert(welcome04.welcome03()); var welcome05 = Pangu; welcome05.welcome01 = "盘古的呼吸变成了天"; var welcome06 = new welcome05(); alert(welcome06.welcome03()); var welcome07 = Pangu; welcome07.welcome01 = "盘古的声音变成了大地"; var welcome08 = new welcome05(); alert(welcome08.welcome03()); var welcome09 = Pangu; welcome09.welcome01 = "盘古的眼睛变成了云"; var welcome10 = new welcome05(); alert(welcome10.welcome03()); var welcome11 = Pangu; welcome11.welcome01 = "盘古的四肢变成了雷声"; var welcome12 = new welcome05(); alert(welcome12.welcome03()); var welcome13 = Pangu; welcome13.welcome01 = "盘古的肌肤变成了太阳和月亮"; var welcome14 = new welcome05(); alert(welcome14.welcome03()); var welcome15 = Pangu; welcome15.welcome01 = "盘古的血液变成了江河"; var welcome16 = new welcome05(); alert(welcome16.welcome03()); class Name { name : string; constructor(name) { this.name = name; } } class EarthSkyItem extends Name { private bodyItem : BodyItem; private sky : Sky; private earth : Earth; constructor(name:string, bodyItem : BodyItem, sky : Sky, earth : Earth) { super(name); this.bodyItem = bodyItem; this.sky = sky; this.earth = earth; } } class Wind extends EarthSkyItem { constructor(bodyItem : BodyItem, sky : Sky) { super('四季的风', bodyItem, sky, null); console.log(`他${bodyItem.name},变成了${this.name};`); } } class Cloud extends EarthSkyItem { constructor(bodyItem : BodyItem, sky : Sky) { super('飘动的云', bodyItem, sky, null); console.log(`他${bodyItem.name},变成了${this.name};`); } } class Thunder extends EarthSkyItem { constructor(bodyItem : BodyItem, sky : Sky) { super('隆隆的雷声', bodyItem, sky, null); console.log(`他${bodyItem.name},变成了${this.name};`); } } class Sun extends EarthSkyItem { constructor(bodyItem : BodyItem, sky : Sky) { super('太阳', bodyItem, sky, null); console.log(`他${bodyItem.name},变成了${this.name};`); } } class Moon extends EarthSkyItem { constructor(bodyItem : BodyItem, sky : Sky) { super('月亮', bodyItem, sky, null); console.log(`他${bodyItem.name},变成了${this.name};`); } } class FourPole extends EarthSkyItem { constructor(bodyItem : BodyItem, earth : Earth) { super('大地上的东、西、南、北四极', bodyItem, null, earth); console.log(`他${bodyItem.name},变成了${this.name};`); } } class Ground extends EarthSkyItem { constructor(bodyItem : BodyItem, earth : Earth) { super('辽阔的大地', bodyItem, null, earth); console.log(`他${bodyItem.name},变成了${this.name};`); } } class Reiver extends EarthSkyItem { constructor(bodyItem : BodyItem, earth : Earth) { super('奔流不息的江河', bodyItem, null, earth); console.log(`他${bodyItem.name},变成了${this.name};`); } } class Rain extends EarthSkyItem { constructor(bodyItem : BodyItem, earth : Earth) { super('滋润万物的雨露', bodyItem, null, earth); console.log(`他${bodyItem.name},变成了${this.name};`); } } class BodyItem extends Name { constructor(name:string) { super(name); } } class Pangu extends Name{ constructor() { super('盘古'); this.live(); } private sky : Sky; private earth : Earth; private height : number = 2; private qixi = new BodyItem('呼出的气息'); private shengyin = new BodyItem('发出的声音'); private leftEye = new BodyItem('的左眼'); private rightEye = new BodyItem('的右眼'); private sizhi = new BodyItem('四肢'); private skin = new BodyItem('肌肤'); private blood = new BodyItem('血液'); private sweat = new BodyItem('汗'); live() : void { console.log('有个叫盘古的巨人,出生在这混沌之中。'); this.sleeping(); this.wakeup(); } sleeping() : void { console.log('他一直睡了一万八千年。'); } wakeup() : void { console.log('有一天,盘古突然醒了。'); } kaitian(world:World) : void { console.log('他见周围一片漆黑,就抡起大斧头,朝眼前的黑暗猛劈过去。'); let skyEarch : [Sky, Earth] = world.died(); this.sky = skyEarch[0]; this.earth = skyEarch[1]; this.grow(); } grow() : void { console.log('天和地分开以后,盘古怕它们还会合在一起,就头顶着天,用脚使劲蹬着地。天每天升高一丈,盘古也随着越长越高。'); this.height += 20000; this.died(); } died() : void { console.log('这样不知过多少年,天和地逐渐成形了,盘古也累得倒了下去。'); this.transform(); } transform() : void { let wind : Wind = new Wind(this.qixi, this.sky); let cloud : Cloud = new Cloud(this.qixi, this.sky); let thunder : Thunder = new Thunder(this.shengyin, this.sky); let sun : Sun = new Sun(this.leftEye, this.sky); let moon : Moon = new Moon(this.rightEye, this.sky); let fourPole : FourPole = new FourPole(this.sizhi, this.earth); let ground : Ground = new Ground(this.skin, this.earth); let reiver : Reiver = new Reiver(this.blood, this.earth); let rain : Rain = new Rain(this.sweat, this.earth); //... } } class World extends Name{ private status : string = '混沌'; constructor() { super('混沌世界'); console.log('很久很久以前,天和地还没有分开,宇宙混沌一片。'); } died() : [Sky, Earth] { console.log('只听一声巨响,混沌一片的东西渐渐分开了。'); this.status = '消失'; let skyEarch : [Sky, Earth] = [new Sky(), new Earth()]; return skyEarch; } } class Sky extends Name{ constructor() { super('天'); console.log('轻而清的东西,缓缓上升,变成了天;'); } } class Earth extends Name{ constructor() { super('地'); console.log('重而浊的东西,慢慢下降,变成了地。'); } } let world = new World(); let pangu = new Pangu(); pangu.kaitian(world);
|
请发表评论