设计模式作业

发布于 2024-10-17 20:05:29 字数 156 浏览 1 评论 0原文

有没有地方可以找到用于实现设计模式的多项作业(以及解决方案?)

我的想法是以正确的方式进行实践。我想用Java 实现这些。目前我只需要基本的设计模式,而不是 J2EE 模式。

我实际上正在寻找要开发的完整应用程序,它使用大多数设计模式。 (单个作业中的所有设计模式)

Is there any place to find multiple assignments for implementing design patterns( along with solutions ?)

My idea is to get the hands on in a proper way. I would like to implement those in Java. at the moment I just need basic design patterns , not J2EE patterns.

I'm actually looking for the complete application to be developed which uses most of the design patterns. (All design patterns in a single assignment)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧话新听 2024-10-24 20:05:29

给我建一个蚂蚁农场!!

你想要一个任务吗?我给你一张。截止日期为太平洋时间 2 月 22 日星期二晚上 9:00。您将为我建造一个蚂蚁农场,并且您将使用一些常见的设计模式来完成它。

这并没有包含所有的设计模式,因为这很愚蠢。然而,它确实有足够的能力使交互变得复杂,同时又足够简单以快速实现。完成此操作后,我们可以考虑为我们的蚂蚁农场添加更多功能!

我将根据需要添加要求(添加了哪些修订)。

需求如下:

功能需求

  • 一块草地上可以有很多蚂蚁农场。对于这项任务,只允许在一片草地上进行。
  • 草地应该能够产生逻辑上无限数量的蚂蚁农场。
  • 蚂蚁农场应由蚂蚁农场房间网络组成。
  • 蚂蚁农场应该有空间来产卵更多的蚂蚁。
  • 蚂蚁应该能够与其他蚂蚁战斗。当他们这样做时,战斗的失败者应该死亡(它的蚂蚁农场不能再指挥它),而战斗的胜利者应该获得蚂蚁的属性。
  • 一个蚂蚁农场只能有一种蚂蚁。每个物种都应该有某种奖励。也许他们收获食物的速度更快。也许它们有更高的机会杀死其他蚂蚁。
  • 如果一个蚁群的成员杀死了另一个蚁群的蚁后,那么杀手的蚁后应该控制死去蚁后的蚂蚁种群。所有蚂蚁现在都应该具有两种蚂蚁的属性。 (因此,如果一个物种很强大,而另一个物种很高效,那么现在两个种群都会合并成一个既强大又高效的种群。)
  • 蚂蚁应该经常休息。当他们这样做时,他们应该吃食物。蚂蚁农场应根据房间数量(每个休息房间 X 数量)限制一次可以休息的蚂蚁数量。
  • 当在一个蜱虫结束时,有 1 个或更少的活跃菌落/蚁后时,模拟应该结束。这意味着您应该在第一次蜱虫之前产生至少 2 个菌落。
  • 蚂蚁农场的房间需要一定数量(可能很大)的工人蜱来建造。因此,如果需要 1 名工人 100 刻来挖掘一个房间,则需要 50 名工人 2 刻,等等。但是建造房间应该有很大的成本,因为房间决定了你可以休息多少时间。 (此要求在规范修订版 1 中添加。)

技术要求:(设计模式以粗体显示)

  • Meadow 类必须是单例
  • 蚂蚁农场应该是通过将房间建造成蚂蚁农场来建造的。 (建造者模式)
  • 无人机和战士只能使用 AntRooms 的工厂模式创建,皇后则只能使用 Meadows 的工厂模式创建,以便一个新的殖民地。
  • 使用装饰器模式来跟踪蚂蚁的属性。
  • Antfarm 应该模板化(使用 Java 泛型)来保存任何类型的蚂蚁,并且 antfarm 应该在运行时指定它保存的蚂蚁类型。
  • 模拟应该是基于刻度的。 (调解者模式) 每个蜱虫,每只蚂蚁(按随机顺序)都应该根据其周围环境执行一些操作。雄蜂应该寻找食物,战士应该猎杀敌人(或者如果饿了就回去寻找食物),蜂后应该产卵。

界面要求

蚂蚁农场的界面应该是一个命令行界面,包含以下命令:

  • spawn XY T - 应该在物种的 X、Y 位置创建一个新的蚁群T. 输出应给出菌落的标识符,以便稍后对其进行控制。
  • 示例 spawn 14 -32 Killer 在位置 x14 y-32 创建一群“Killer”蚂蚁。
  • give IR A - 应为由 I(创建时)资源 R 标识的群体提供数量 A 的
  • 资源。示例 give 1 food 50 为群体 1 提供 50 种食物。
  • 示例 give 3 Warriors 10 给出在 Colony 3 基地生成的 Colony 3 10 个战士。

  • tick [T] - 应执行 T 刻度操作。为了方便起见,允许不指定 T,只需勾选一次。

  • 示例 tick 10
  • 示例 tick

  • summary I - 应该给出殖民地 I 的摘要。摘要提供有关该殖民地的信息。

  • 示例 summary 1 可能会给出以下输出:

输出:

    Species: Killer
    Workers: 14
    Warriors: 10
    Ant Kills: 18
    Colony kills: 2 (2:Pansy 4:Gatherer)
    Ticks alive: 143
    Status: Alive
  • 示例 summary 2 可能会给出以下输出:

输出:

    Species: Pansy
    Workers: 4
    Warriors: 0
    Ant Kills: 2
    Colony kills: 0
    Ticks Alive: 25
    Status: Killed by 1:Killer

如果您遇到任何困难,请发表评论。我将尝试为您提供一些提示,例如空白类、方法头,或者只是关于如何使这些设计模式彼此交互的一般想法。

祝你好运,玩得开心

Build Me An Antfarm!!

You want an assignment? I'll give you one. It's due Tuesday, February 22 at 9:00PM Pacific time. You are going to build me an antfarm, and you're going to use some common design patterns to do it.

This does not have EVERY design pattern, because that's just silly. It does, however, have enough that the interactions will be complex while being simple enough to implement quickly. Once this is done, we can look at adding in more features to our ant farm!

I will add requirements (with what revision they were added) as needs arise.

Here's the requirements:

Functional Requirements:

  • A meadow can have many ant farms in them. For this assignment, only ever allow one meadow to take place.
  • A meadow should be capable of spawning a logically unlimited number of antfarms.
  • An antfarm should be comprised of a network of antfarm rooms.
  • An antfarm should have rooms for spawning more ants.
  • Ants should be able to battle other ants. When they do, the loser of the battle should die (it's antfarm can no longer command it), and the winner of the battle should get the attributes of the ant.
  • An antfarm should only have one species of ant. Each species should have some kind of bonus to them. Perhaps they harvest food faster. Perhaps they have a higher chance to kill other ants.
  • If a member of an ant colony kills the queen of another colony, the killer's queen should assume control of the dead queen's population of ants. all ants should now also have the attributes of both species of ant. (So if one species was strong, and the other species was efficient, now both populations are merged into a single population that is both strong and efficient.)
  • Ants should have to rest every so often. When they do, they should consume food. An antfarm should be limited in capacity of how many ants can rest at a time based on the number of rooms (X amount per resting room).
  • The simulation should end when, at the end of a tick, there is 1 or less active colonies/queens. This means you should spawn at least 2 colonies before your first tick.
  • Rooms in the Antfarm should require a certain (probably large) number of worker-ticks to build. So, if it would take 1 worker 100 ticks to dig a room, it would take 50 workers 2 ticks, etc. But there should be a significant cost to building a room, since rooms determine how much you can rest. (This requirement added in spec revision 1.)

Technical Requirements: (Design patterns bolded)

  • The Meadow class MUST be a singleton.
  • An antfarm should be a built by building rooms into an antfarm. (Builder pattern)
  • Drones and Warriors should only be created with the factory pattern by AntRooms, and Queens by the factory pattern by Meadows for purposes of a new colony.
  • Use the decorator pattern to keep track of an ant's attributes.
  • Antfarms should be templated (using Java generics) to hold any type of ant, and the antfarm should specify at runtime which type of ant it holds.
  • The simulation should be tick-based. (Mediator pattern) Each tick, every ant (in a random order) should perform some action based on its surroundings. Drones should look for food, warriors should hunt enemies (or go back for food if hungry) and queens should spawn an egg.

Interface requirements:

The interface to the ant farm should be a command line interface with the following commands:

  • spawn X Y T - should create a new colony at position X,Y of species T. The output should give an identifier for the colony so it can be controlled later.
  • Example spawn 14 -32 Killer creates a colony of "Killer" ants at position x14 y-32.
  • give I R A - should give the colony identified by I (at creation) resource R of amount A.
  • Example give 1 food 50 gives colony 1 50 food.
  • Example give 3 warrior 10 gives colony 3 10 warriors that spawn at colony 3's base.

  • tick [T] - should perform T tick operations. For convience, allow T to not be specified, and simply tick once.

  • Example tick 10
  • Example tick

  • summary I - should give a summary of colony I. A summary gives information about that colony.

  • Example summary 1 might give the following output:

Output:

    Species: Killer
    Workers: 14
    Warriors: 10
    Ant Kills: 18
    Colony kills: 2 (2:Pansy 4:Gatherer)
    Ticks alive: 143
    Status: Alive
  • Example summary 2 might give the following output:

Output:

    Species: Pansy
    Workers: 4
    Warriors: 0
    Ant Kills: 2
    Colony kills: 0
    Ticks Alive: 25
    Status: Killed by 1:Killer

If you run into any difficulty, post a comment about it. I'll try to give you some hints like blank classes, method headers, or just general ideas about how to make these design patterns interact with eachother.

Good luck, and HAVE FUN!!

岛歌少女 2024-10-24 20:05:29

http://www.allapplabs.com/java_design_patterns/java_design_patterns.htm
上述网站迎合了少数设计模式,并且还提供了大量带有解决方案的示例

http://www.allapplabs.com/java_design_patterns/java_design_patterns.htm
The above site caters to few design patterns and it also has loads of examples with solutions

乖乖 2024-10-24 20:05:29

你也可以从《Head First Design Patterns》一书中获取问题。每章末尾都有很多谜题。

You can also take problems from the book "Head first design patterns". It has a lot of puzzle problems at the end of each chapter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文