摘要: 1 //singleton 单例模式 2 3 import console; 4 5 import thread; 6 class singleton{ 7 ctor(){}; 8 instance; 9 10 test = function(){ 11 return "对象"; 12 } 13 1 阅读全文
posted @ 2024-05-26 18:40 Axuanup 阅读(3) 评论(0) 推荐(0) 编辑
摘要: //Car 实现封装继承多态 import console //父类 class Car{ ctor(make, model, color, year) {//构造函数,用于初始化对象的属性 this.make = make //制造商 this.model = model //型号 this.co 阅读全文
posted @ 2024-05-26 18:40 Axuanup 阅读(6) 评论(0) 推荐(0) 编辑
摘要: 1 //calculate 简单工厂模式 2 3 //简单工厂模式 4 import console; 5 6 //运算类 7 class operation{ 8 ctor(){}; 9 numberA = 0; 10 numberB = 0; 11 getResult = function(){ 阅读全文
posted @ 2024-05-26 18:39 Axuanup 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 1 //queue队列结构 2 //队列的特点:先进先出 3 import console; 4 class queueEx{ 5 ctor(){ 6 this.items = {} 7 }; 8 //排队 9 入队 = function(element){ 10 ..table.push(this 阅读全文
posted @ 2024-05-26 18:29 Axuanup 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 1 --普通表 2 local tab = {1,2,3} 3 4 --元表 5 local meta = { 6 insert = function(t,v) 7 --监测表增加成员 8 print("增加一个值",v) 9 table.insert(t,v) 10 end, 11 remove 阅读全文
posted @ 2024-05-26 18:18 Axuanup 阅读(1) 评论(0) 推荐(0) 编辑
摘要: print("********如何实现switch-case********") local switch = { [1] = function() print ("case1") end, [2] = function() print ("case2") end, [3] = function() 阅读全文
posted @ 2020-11-24 00:30 Axuanup 阅读(3538) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h> #include<string.h> //使用匿名结构体嵌套 struct person1 { const char* name; char gender[20]; struct { int age; }; }p1; //不使用匿名结构体嵌套 struct pho 阅读全文
posted @ 2020-04-06 20:17 Axuanup 阅读(890) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h> #include<string.h> /* struct 类型名 { 类型 变量名; 类型 变量名; }tpye_name1,tepy_name2; //tpye_name1,tepy_name2为具体变量名,使用时无需再声明结构体了 */ struct Game 阅读全文
posted @ 2020-04-06 18:22 Axuanup 阅读(221) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h> //tpyedef 关键字有什么用,我们每次使用结构体的时候,都要加,struct 这个关键字 //使用tepydef 关键字我们给struct关键字给定义个别名,这样我们定义的时候就不用加struct 这个关键字了 /* 定义方式 typedef struct 阅读全文
posted @ 2020-04-06 18:08 Axuanup 阅读(507) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 3 //结构体关键字struct 4 //定义一个游戏玩家的NPC 5 struct Gamer 6 { 7 char cName[24]; //玩家名称 8 int nHealth; //生命值 9 int nMagic; //魔法 10 int nSk 阅读全文
posted @ 2020-04-06 17:41 Axuanup 阅读(923) 评论(0) 推荐(0) 编辑