Simple Aircraft War on Android (frontend of SAWS)

Related tags

App sawa
Overview

SAWA: Simple Aircraft War on Android

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
}

上传 NPC 信息

只能由房主上传。

{
  "type": "npc_upload",
  "mob": 0,
  "id": 14,
  "location_x": 134,
  "location_y": 476,
  "speed_x": 0,
  "speed_y": 3,
  "hp": 10
}

下发 NPC 信息

只会发给房客。

{
  "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"
}

子弹道具生效:接到此消息,若 targettrue,则给自己启用效果;否则,给队友使用效果。

{
  "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

You might also like...
A Full-Stack mobile app, including Android & Server, Simple-Poem 简诗. You can write poem in graceful & traditional Chinese style.
A Full-Stack mobile app, including Android & Server, Simple-Poem 简诗. You can write poem in graceful & traditional Chinese style.

JianShi 简诗 A Full-Stack mobile app, including Android side & Server side, Simple-Poem 简诗. You can write poem in graceful & traditional Chinese style.

A simple android Twitter client written in Kotlin
A simple android Twitter client written in Kotlin

Blum Blum is an unofficial, simple, fast Twitter client written in Kotlin. This project is a complete rewrite of the Java version. Screenshot Build To

Simple Android movies app using MVVM clean architecture.
Simple Android movies app using MVVM clean architecture.

Simple Android movies app using MVVM clean architecture.

This is a simple example of Aspect Oriented Programming in Android
This is a simple example of Aspect Oriented Programming in Android

Android-AOPExample This is a simple example of Aspect Oriented Programming in Android as part of a blog post I have written. The idea was to measure h

A simple chat demo for socket.io and Android

socket.io-android-chat This is a simple chat demo for socket.io and Android. You can connect to https://socket-io-chat.now.sh using this app. Installa

A simple Notes Android app
A simple Notes Android app

Taskie - A Note Taking MVVM Application! Designed a simple Notes Android app following features A simple Notes Android app following features Single a

This library makes it easy for you to develop an simple drawing app in android
This library makes it easy for you to develop an simple drawing app in android

DrawingCanvas Library for drawing app canvas Features Size , transperancy and color manupulation of brush -- Using setSizeForBrush(), setBrushAlpha()

⏺ A simple android app to browse your phone call recordings
⏺ A simple android app to browse your phone call recordings

⏺ Reky A simple android app to browse your phone call recordings [Under Construction] ✅ TODO Support more file name formats 🏗 Built-with MVVM with Si

An simple image gallery app utilizing Unsplash API to showcase modern Android development architecture (MVVM + Kotlin + Retrofit2 + Hilt + Coroutines + Kotlin Flow + mockK + Espresso + Junit)
An simple image gallery app utilizing Unsplash API to showcase modern Android development architecture (MVVM + Kotlin + Retrofit2 + Hilt + Coroutines + Kotlin Flow + mockK + Espresso + Junit)

Imagine App An simple image gallery app utilizing Unsplash API. Built with ❤︎ by Wajahat Karim and contributors Features Popular photos with paginatio

This is my first Spring Boot with Kotlin project and used React as frontend.

༒☬༒ ꜱᴘʀɪɴɢ ʙᴏᴏᴛ + ᴋᴏᴛʟɪɴ ༒☬༒ This project is simple course enrolment site built with React with Typescript and Spring boot with Kotlin. Frontend - Ove

Panduka Nandara 1 Mar 22, 2022
Simple-todo-app - Simple Memo App using SQLite

Judul Aplikasi Aplikasi Memo Sederhana menggunakan SQLite. Fitur Aplikasi Memo y

Ananda Muhamad Lukman 0 Jan 3, 2022
A simple app to showcase Androids Material Design and some of the cool new cool stuff in Android Lollipop. RecyclerView, CardView, ActionBarDrawerToggle, DrawerLayout, Animations, Android Compat Design, Toolbar

#Android-LollipopShowcase This is a simple showcase to show off Android's all new Material Design and some other cool new stuff which is (new) in Andr

Mike Penz 1.8k Nov 10, 2022
A simple Android app to demonstrate the use of Hover SDK for M-PESA Send Money while offline. This SDK does not require an internet connection, it automates USSD sessions in the background of an android application.

HoverSDKDemo Hover SDK is an Android SDK that lets mobile developers to add money features to the applications. This SDK does not require an internet

Joel Kanyi 9 Dec 21, 2022
A Simple and Minimal Quotes Android Application to demonstrate the Modern Android Development tools

Quotee Android ?? A Simple and Minimal Quotes Android Application to demonstrate the Modern Android Development tools. Developed with ❤️ by Aminullah

null 12 Aug 24, 2022
🎥 A Simple and Minimal Movies Android Application to demonstrate the Modern Android Development and Jetpack Compose.

ComposeMovie Android ?? A Simple and Minimal Movies Android Application to demonstrate the Modern Android Development and Jetpack Compose. Built with

null 13 Oct 1, 2022
Simple Android app during a coding night. Just Learning Firebase and Android

KUI-App Simple Android app during a coding night. Just Learning Firebase and Android What we learned: Some basics of Android Basic setup of Firebase:

Kibabii University Informatics Club (KUI) 7 Aug 28, 2022
BlueNote-Android - an android app that provides simple notes and answer

BlueNote AnswerSheet Blue Note is an android app that provides simple notes and

HyukJin Kwon 0 Jan 4, 2022
A simple Android project using modern Android development tools and libraries.

A simple Android project using modern Android development tools and libraries.

Ahmed Sumeiry 0 Feb 3, 2022
Spantastic - an Android library that provides a simple and Kotlin fluent API for creating Android Spannable

Spantastic is an Android library that provides a simple and Kotlin fluent API for creating Android Spannable. This library wrappers SpannableStringBuilder and add methods to easily decorate the text with multiple spans.

Wellington Cabral da Silva 12 Nov 27, 2022