この記事は
とあるカードゲームが非常に面白く、
そのゲームの見た目クローンを作ろうと一人のプログラマーが奮闘していくブログのような記事です。
その4の続き
ここでは、戦闘APIを構築していきます。
API仕様
Request:battle
引数(POST)
Name | 仕様説明 |
---|---|
BType | 戦闘の種類 今後増えてくであろう戦闘の種類 arena:フリー対戦 (予定)labyrinth:地下迷宮,rank:ランキング,story:ストーリー,sheild:シールド戦,guild:ギルド戦,theif:盗賊,lilith:リリス戦,devil:魔神戦 |
UId | ユーザを識別するためのID。 初期はユーザIDで認識するが、ゆくゆくはセッションID的なものに変えていく予定 |
BTarget | 戦闘対象 BClassに応じた対戦相手の設定。 |
V | アプリバージョン (TBD)規定のバージョン以下の場合、アップデートを促す予定 |
UA | UserAgent (TBD)アクセス状況の集計とかの分析に使用する予定 |
Response
Name | 仕様説明 |
---|---|
Result | 処理結果 0:正常,1:バージョン不適格,9:異常 |
BWinner | 戦闘結果 1=勝利,0=引き分け,-1=負け |
BProcess | 戦闘過程 JSON形式にて返す。仕様は随時変更 |
下準備
APIを作成していく前に、テストデータの準備をしていく。
データ作成
ユーザ情報
$ vi test/fixtures/avatars.yml
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
UserId: Kingdom
Name: 王国使い
Password: MyString
Lv: 1
Exp: 1
DeckCurrentNo: 1
DeckDefenceNo: 1
Icon: MyString
two:
UserId: Spritual
Name: 精霊使い
Password: MyString
Lv: 1
Exp: 1
DeckCurrentNo: 1
DeckDefenceNo: 1
Icon: MyString
three:
UserId: tribal
Name: 蛮族使い
Password: MyString
Lv: 1
Exp: 1
DeckCurrentNo: 1
DeckDefenceNo: 1
Icon: MyString
four:
UserId: pluto
Name: 幽魔使い
Password: MyString
Lv: 1
Exp: 1
DeckCurrentNo: 1
DeckDefenceNo: 1
Icon: MyString
ユーザ状態
$ vi test/fixtures/user_statuses.yml
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
UserId: Kingdom
Stamina: 1
SessionId: hogehoge
two:
UserId: Spritual
Stamina: 1
SessionId: fugafuga
three:
UserId: Tribal
Stamina: 1
SessionId: mogomogo
four:
UserId: Pluto
Stamina: 1
SessionId: nobinobi
デッキ情報
$ vi test/fixtures/deck_infos.yml
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
UserId: Kingdom
DeckNo: 1
SlotNo: 1
Name: 負け組
two:
UserId: Spritual
DeckNo: 1
SlotNo: 1
Name: 負け組
three:
UserId: Tribal
DeckNo: 1
SlotNo: 1
Name: 負け組
four:
UserId: Pluto
DeckNo: 1
SlotNo: 1
Name: 負け組
ユーザカード情報
$ vi test/fixtures/user_stock_cards.yml
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
UserId: Kingdom
UserStockNo: 1
CardId: T01
CardExp: 1
AddSkillNos: MyString
two:
UserId: Spritual
UserStockNo: 1
CardId: T02
CardExp: 1
AddSkillNos: MyString
three:
UserId: Tribal
UserStockNo: 1
CardId: T03
CardExp: 1
AddSkillNos: MyString
four:
UserId: Pluto
UserStockNo: 1
CardId: T04
CardExp: 1
AddSkillNos: MyString
モンスター情報
$ vi test/fixtures/monster_infos.yml
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
CardId: T01
Name: 王国の負け組
Hp: 2
Atk: 1
Cost: 1
Wait: 1
Lv: 1
Exp: 1
Rare: 1
Race: 1
ImageId: MyString
SkillNos: MyString
two:
CardId: T02
Name: 精霊の負け組
Hp: 2
Atk: 1
Cost: 1
Wait: 1
Lv: 1
Exp: 1
Rare: 1
Race: 2
ImageId: MyString
SkillNos: MyString
three:
CardId: T03
Name: 蛮族の負け組
Hp: 2
Atk: 1
Cost: 1
Wait: 1
Lv: 1
Exp: 1
Rare: 1
Race: 3
ImageId: MyString
SkillNos: MyString
four:
CardId: T04
Name: 幽魔の負け組
Hp: 2
Atk: 1
Cost: 1
Wait: 1
Lv: 1
Exp: 1
Rare: 1
Race: 4
ImageId: MyString
SkillNos: MyString
いくつか言い訳
- 不定期連載です。
- 多分途中で挫折します。
- 筆者のメモも兼ねているため過去の記事も遠慮なく随時編集いたします。
- プログラミングの開発経験はあってもゲームの開発経験はこれが初めてです。
等色々ありますが、生暖かい目で応援してくださると光栄です。