复古像素风游戏设计之:代码规范
#Vulcan团队代码规范
>author: yoccio
>version: 0.1
>date: 2016/10/25
一、注释
1.0 为避免由于初学产生的歧义,注释语言请使用中文
1.1 文件编码格式 UTF-8
1.2 类注释:
/** className: Example
* author: 小红
* version: 0.1
* date: 2016/10/25
* brief: 示例类注释
* change: 第一次提交
*
**/
public class Example{
;
}
1.3 类内注释:
- 成员:
private int score_; //当前玩家得分
- 属性:
public int score{
get{ return score_;} //获取当前玩家分数
private set{ score_ = value;} //私有,设置分数
}
- 方法:
/** methodName:
* date:
* brief:
* in: Type name [usage]
* out: Type name [usage]
* change:
*
**/
void setTime(out int hr, out int min)
{
;
}
1.4 全局变量注释:
/* 一个全局变量 */
int g_something;
二、 变量命名
2.0 所有代码应在namespaces Vulcan
内
2.1 类:Pascal
class ContralSystem
2.2 方法:Camel
void setValue(void)
{
;
}
2.3 全局变量:g_
int g_something;
2.4 临时变量: t_
int t_count;
2.5 成员: Camel_
private int score_;
2.6 属性: Camel
public int score{
;
}
2.7 静态: s_
public static int s_year;
2.8 枚举: 大写字母 + 下划线
enum SQURE{
A_ENUM_VALUE,
ANOTHER_ENUM_VALUE
}
2.9 常量: 大写字母 + 下划线
const int g_FIVE;
三、缩进
3.0 请将编辑器中Tab设置为四个空格,对齐代码请使用Tab
3.1 大括号应单独占一行
3.2 任意操作数之间留有一个字符空格
for(int i=1;i<10;i++) //不正确的空格
for(int i = 1; i < 10; i++) //正确的空格
3.3 复杂for循环格式:
for(someLongLongArg initialization; //
anotheLongLongArg condition; //
lastLongLongArg increment) //
{
//statements
}
3.4 每一行只写一个语句
int a;int b; //不正确的格式
int a; //正确的格式
int b;
3.5 代码与行注释间应留有一个字符的空格
四、控制结构
4.1 if
语句
- 即使只有单行语句,也应使用写大括号
else
应与括号不同行
if(exp1)
{
;if body
}
else if(exp2)
{
;else of body
}
else{
;else body
}