SAWA(Simple Aircraft War on Android,简易 Android 飞机大战游戏)是一款 Java 开发的 Android 平台的「飞机大战」主题小游戏。 支持单人游戏、多人同屏游戏两种游戏模式。
SAWA 是哈尔滨工业大学(深圳)的《面向对象的软件构造实践》课程项目的一部分。
SAWA 是一个以 Gradle 为包管理器的,使用 Android Studio 开发的 Java Android 应用。 其目录结构为 Android Studio 默认的结构,使用 Android Studio 打开整个文件夹就能正常使用。
SAWA 是 SAWS 的前端,与 SAWS 以一致的通信方式通信。
协议栈:WebSocket,信息载体:JSON
{
"type": "user_query",
"username": "<用户名>",
"password": "<密码>"
}
如果 uid 为 -1 表示失败。
{
"type": "user_query_response",
"uid": -1
}
{
"type": "room_info"
}
返回:(如果没有可用房间,rooms
数组就是空的)
{
"type": "room_info_response",
"rooms": [
{
"room_id": 1,
"difficulty": 0
},
{
"room_id": 3,
"difficulty": 2
}
]
}
{
"type": "create_room",
"difficulty": 2
}
返回创建成功的房间号:
{
"type": "create_room_response",
"room_id": 4
}
{
"type": "join_room",
"room_id": 4
}
{
"type": "join_room_response",
"success": true
}
{
"type": "join_room_response",
"success": false
}
{
"type": "room_ready"
}
{
"type": "resolution",
"width": 1080,
"height": 1920
}
返回双方协商后的尺寸信息和难度,双方接到这条消息时开始游戏:
{
"type": "game_start",
"ratio": 1.6
}
只能由房主上传。
{
"type": "npc_upload",
"mob": 0,
"id": 14,
"location_x": 134,
"location_y": 476,
"speed_x": 0,
"speed_y": 3,
"hp": 10
}
只会发给房客。
{
"type": "npc_spawn",
"mob": 0,
"id": 14,
"location_x": 134,
"location_y": 476,
"speed_x": 0,
"speed_y": 3,
"hp": 10
}
注意坐标是缩放前的:
{
"type": "movement",
"new_x": 753,
"new_y": 255
}
队友将得到:
{
"type": "teammate_movement",
"new_x": 753,
"new_y": 255
}
{
"type": "damage",
"id": 14,
"hp_decrease": 10,
"location_x": 514,
"location_y": 114
}
{
"type": "score",
"remove": 14,
"score": 20
}
如果 remove 为 -1,则无条件得分(炸弹道具)。
对应「飞机飞出边界」事件,由房主负责。
{
"type": "remove_aircraft",
"remove": 14
}
0 = Blood, 1 = Bomb, 2 = Bullet
{
"type": "prop_spawn",
"props": [
{
"id": 1,
"kind": 0,
"location_x": 514,
"location_y": 114
},
{
"id": 2,
"kind": 0,
"location_x": 143,
"location_y": 241
}
]
}
{
"type": "remove_prop",
"remove": 14
}
{
"type": "prop_action",
"id": 14
}
炸弹生效:接到此消息则清屏,然后给自己加上 add_score
的分数
{
"type": "bomb_action",
"add_score": 1540
}
加血生效:接到此消息,给自己无条件加血 add_hp
(注意封顶)
{
"type": "blood_action"
}
子弹道具生效:接到此消息,若 target
为 true
,则给自己启用效果;否则,给队友使用效果。
{
"type": "bullet_action",
"target": true
}
任一一方发送此消息,服务器将结束本局游戏。
reason
字段:0 = 因发信方死亡结束;1 = 因发信方按返回键结束。
{
"type": "game_end_request",
"reason": 1
}
this_score
为本方分数,teammate_score
为对方分数。reason
是结束游戏的原因。
{
"type": "game_end",
"reason": 1,
"this_score": 1700,
"teammate_score": 1870
}
使用了下面这些库,在 Gradle 文件中已配置好。
androidx.room
org.java-websocket
com.alibaba:fastjson
MIT