Reputation: 10669
Is it possible to create a public enum class property of an anonymous type?
I'm running through a list of OOD scenarios and working on a basic card game. Each game is a specific class with an enum of "PlayerActions". Each class has their own specific enum values, however I'd like to pass the game's enum of actions to each player once the player objects are initialized.
Is this possible or am I completely off-base?
public class Player{
//take set of actions based on the game you're playing
public enum <T> Actions {get;set;}
//Hold deck of cards approximate to rules of game
public List<Card> hand {get;set;}
public bool IsTurn {get;set;}
public Player(Game gameType){
hand = new List<Card>(gameType.HandSize);
Actions = gameType.GameActions;
IsTurn = false;
}
public void AssignCard(Card card){
hand.Add(card);
}
}
public enum GameType{
BlackJack,
TexasHoldEm
}
public abstract class Game{
public enum<T> GameActions {get; set;}
public GameType gameType {get;set;}
public Card[] River {get;set;}
public Player[] UserList {get;set;}
public Dealer dealer = new Dealer();
public int HandSize { get; set; }
}
public class BlackJack : Game{
private enum Actions
{
Hit,
Stay
}
private const int handSize = 2;
private const int totalUsers = 5;
public BlackJack()
{
this.gameType = GameType.BlackJack;
this.River = new Card[handSize];
this.UserList = new Player[totalUsers];
this.GameActions = Actions;
}
}
public class TexasHoldEm : Game{
enum Actions
{
Hit,
Keep,
Fold,
Call,
AllIn
}
public Actions myActions { get; set; }
public const int HANDSIZE = 3;
public const int TOTALUSERS = 7;
public TexasHoldEm()
{
this.GameActions = Actions;
this.gameType = GameType.BlackJack;
this.River = new Card[HANDSIZE];
this.UserList = new Player[TOTALUSERS];
}
}
Upvotes: 0
Views: 3872
Reputation: 101681
I think you want an array of Action
enums instead of re-declaring the enum for each class, for example declare your enum once, outside of the classes and put all the actions in it:
enum Action
{
Hit,
Keep,
Fold,
Call,
AllIn,
Hit,
Stay
}
Then have an Action[]
array and initialize it in your constructors:
private Action[] GameActions;
public BlackJack()
{
this.GameActions = new [] { Action.Hit, Action.Stay };
this.gameType = GameType.BlackJack;
this.River = new Card[HANDSIZE];
this.UserList = new Player[TOTALUSERS];
}
You might also want to make GameActions
field readonly
..
Upvotes: 2