Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Design question  (Read 1906 times)
0 Members and 1 Guest are viewing this topic.
Offline Fokusas

Senior Devvie

Medals: 3
Projects: 1

« Posted 2011-10-23 10:21:56 »

Hello its me again  Grin
And I have a new question.
I am trying to upgrade my little game and decided that it should be Turn based strategy something like CIV3 expect that you have only one settlement and you have to manage what your peoples do. It now contains 2,5D (passive rendering) map with some crappy graphics  Grin, working tech research, and job systems.
So I decided that it needs some item transportation system and created it. Then I got an idea that my people cant carry much and need items that could help them to carry more items. But I am unsure how correctly implement it. I could try to create new class called Container which could contain other items, but that way I must refactor my transportation, jobs and item storing system. Or should I add more fields to my item class, but way I must refactor item storing system and jobs system. I think there is some flaws in my design.
Item storing system:
Item class is called Daiktas. It represents stack of items and contains fields DaiktoKodas (Item code), Dydis (1 item size), Kiekis (amount or stock), Size (whole object size) and some other minor variables like name, place, ...
Size=Kiekis*Dydis. If any of those variables change value other 2 is recalculated to maintain correct ratio.
My building class is called Pastatas. It contains HashMap and some other variables like Talpa (capacity), Uzimta (used space) and some other.
Items are placed in biulding if them Size is lower that free space in that building (Talpa-Uzimta). DaiktoKodas is used as key to place then in HashMap. Each time adding or removing and item uzimta is changed by that item size(+= or -=).
Transportation system:
Asmuo (person) have ArrayList<Nešulys> that contains all items that he is carrying.
Nešulys class contain Daiktas needed to transport and start and end coordinates.
Asmuo also have field Job which tells what action he can perform if is not travelling.
Jobs system is simply. It just look at asmuo.job and get recipe form HashMap containing all recipes. And then if there is enough needed items at that place creates new items. If there is shortage he go and look for then in other buildings.
I think there may be some flaws. And i don't know what to change to implement Item-Container concept.

Thanks in advance for your advice.
Offline aazimon
« Reply #1 - Posted 2011-10-27 18:19:17 »

Let me see if I understand what you have. A person class can carry some items. You want to add a container class, allowing the person to have a container. So, does teh person class have a method to "get items"? If so, you would want to change that method to check if the person has a container and then return the container's items.
And class that uses person would still call the same method to get items.
Offline Fokusas

Senior Devvie

Medals: 3
Projects: 1

« Reply #2 - Posted 2011-10-28 13:23:57 »

Thanks for your reply. Your idea is good but only a half. But my question was about my item system. (storing, transporting).
I must admit that this my post maybe was a little too complicated for you to understand (almost 200 views and first reply appeared only after week) or maybe that was your laziness to read my text wall.
Edit: I just read post about bots ( and it start making sense. Cheesy
p.s. sorry if I insult anyone I don't mean to.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #3 - Posted 2011-10-28 18:47:22 »

A Container class probably makes sense conceptually. Each person has a bag or a car has a trunk or whatever and those are all containers, and the container is what determines how many items they have. But considering the functionality of a Container is probably just to be a List with a size limit, it doesn't seem like it needs to be a whole class. You could get away with an Interface that's like ItemHolder or something, and have methods like getItem(), canGetItem(), dropItem(), itemCount() etc.

But, you know, semantics. Either way it seems like you're on the right track, more or less. Or if you just have a Unit class or whatever and all Units can potentially carry something, just put all the functions in there and give them an itemCount variable or something that you can set from subclasses.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  

EgonOlsen (45 views)
2018-06-10 19:43:48

EgonOlsen (25 views)
2018-06-10 19:43:44

EgonOlsen (47 views)
2018-06-10 19:43:20

DesertCoockie (202 views)
2018-05-13 18:23:11

nelsongames (127 views)
2018-04-24 18:15:36

nelsongames (126 views)
2018-04-24 18:14:32

ivj94 (867 views)
2018-03-24 14:47:39

ivj94 (128 views)
2018-03-24 14:46:31

ivj94 (771 views)
2018-03-24 14:43:53

Solater (143 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!