简体   繁体   English

这是正确的建模方法吗? 类图示例

[英]Is this correct modelling approach? Class diagram example

I'm trying to model chess game. 我正在尝试为国际象棋游戏建模。 My UML-newbie thinking goes like this: 我的UML新手想法如下:
GameEngine has just one chessboard and two players (who inherits from Player) and when GameEngine is destroyed, so are these (composition). GameEngine只有一个棋盘和两个玩家(从Player继承),而当GameEngine被销毁时,这些(组成)也是如此。 Chessboard can contain up to 32 chessmen and each player can control/have references to 16 chessmen (aggregation). 棋盘最多可包含32个棋手,每个玩家可以控制/拥有16个棋手的参考(集合)。 The players need to call or access some methods of the board (directed association). 玩家需要调用或访问棋盘的某些方法(定向关联)。 Is that correct or at least close? 那是正确的还是至少接近的?

在此处输入图片说明

You made abstraction Player over Human and CPU . 您已使HumanCPU成为了抽象Player I think all your arrows must use the common one Player . 我认为您所有的箭头都必须使用普通的Player For example: 例如:

class Chessboard {
  Player p1;
  Player p2;
}

It is more convenient way, and you can change in runtime your players and different game modes: Human vs Human, Human vs CPU, even CPU vs CPU 这是更方便的方式,您可以在运行时更改玩家和不同的游戏模式:“人与人”,“人与CPU”,甚至“ CPU与CPU”

The same changes applied to GameEngine. 相同的更改应用于GameEngine。

By the way, I don't think it is a good idea to player aggregate controlled chessmen. 顺便说一句,我认为由玩家控制的棋手不是一个好主意。 All control over Chessman nut be responsibility of Chessboard , and player just send him a message when he want to make a move in his turn. Chessman螺母的所有控制权Chessman Chessboard负责,玩家在想转牌时只是向他发送消息。

That change allows you to have several chessboards per player for multi-table game. 这项更改使您可以为多人游戏每个玩家拥有几个棋盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM