d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help With Creating Classes Of Arrays In Java
Add Reply New Topic New Poll
Member
Posts: 4,095
Joined: Apr 24 2011
Gold: 0.25
Mar 8 2017 06:03am
Hi guys, I really need help with creating classes for cards in a board game. I am making a board game in java and I need few clue how to attempt creating the class for each card type played in the game called "The North Sea Oil".

There are three different card colour types : Blue, brown and Red.

I need to make classes for each of the card types for later to use in the game, I want to create them so I can for example pick a random blue card.
I was thinking of making arrays in arrays but I'm not sure if that will later work with the rest of the code.

For example these are blue cards =

My idea was to make a class of "Bluecards" and in the class create 3 arrays called : shallow water, reefs and deep water. Inside of these 3 arrays create another arrays with the unique entities of every different card type. Would that work?
I'm bit confused because each card holds few types of data.


This post was edited by Marcelpro on Mar 8 2017 06:04am
Member
Posts: 15,717
Joined: Aug 20 2007
Gold: 481.00
Mar 8 2017 08:32am
I don't see a reason for you to use arrays

I would make the class BlueCards and have a property DepositType, then set the property

BlueCards -
WaterType
DepositType

myCard.WaterType = x
myCard.DepositType = x


then you can make an array of bluecards if you like

This post was edited by t9x on Mar 8 2017 08:33am
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Mar 10 2017 04:18pm
I don't really know what all the attributes are for the cards in this game you're making but it sounds like you have 3 identical decks of cards for 3 players
in any case I would imagine you have some classes

Abstract class called Card that holds
Color of Card
Depth Type enum {Shallow, Reef, Deep}

Then you need 2 other classes LocationCard and DepositCard that extend the card class
LocationCard will probably not need any fields from the looks of it but it will probably have some methods to do whatever it is you do with em
DepositCard however will have an enum for depositSize {NO, SMALL, MEDIUM, LARGE} and whatever methods to do whatever you do with them

Then you need a Decks class that holds 3 List<Card> redList; blueList; yellowList and you can just put a constructor for the deck class that fills the Lists with LocationCards and DepositCards however you see fit according to the rules and give it specific public Card DrawRed(), DrawBlue() DrawYellow() methods

of course I'm assuming that the different colors of cards are for different players if not then you just need 1 list and 1 draw method

It looks like those are the only properties you need though, maybe a couple constants for numbers of specific types of cards or something but all the values shown on the cards you posted can be derrived from this data

edit: if the brown and red cards have different functionality than the bluecard though this whole structure goes out the window

This post was edited by Ideophobe on Mar 10 2017 04:21pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll