0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

ポケモンバトルを実装していきます。実装しやすいように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,
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?