はじめに
ポケモンバトルを実装していきます。実装しやすいようにDDDで作っていくため、Entitiyの定義から始めていきます!では、Start!!!!
ソースコード
ディレクトリ構成
~/develop/pokemon_battle_app (main)$ tree lib
lib
├── data
│ └── sample_data.dart
├── domain
│ ├── entities
│ │ ├── move.dart
│ │ ├── pokemon.dart
│ │ └── stats.dart
│ └── enums
│ └── pokemon_type.dart
├── main.dart
├── models
│ └── pokemon.dart
├── page
│ ├── battle.dart
│ ├── home.dart
│ └── info.dart
└── router.dart
7 directories, 11 files
今回はdomain配下のディレクトリを中心に実装していきます。
lib/models/pokemon.dart
class Pokemon {
final String name;
final String imageUrl;
final List<Move> moves;
Pokemon({required this.name, required this.imageUrl, required this.moves});
}
class Move {
final String name;
final int power;
Move({required this.name, required this.power});
}
lib/domain/entities/move.dart
class Move {
final String name;
final int power;
Move({required this.name, required this.power});
}
lib/domain/entities/stats.dart
class Stats {
final int hp;
final int attack;
final int defense;
final int speed;
Stats({
required this.hp,
required this.attack,
required this.defense,
required this.speed,
});
}
lib/domain/enums/pokemon_type.dart
enum PokemonType {
fire,
water,
grass,
electric,
}