G
Gaz
This is as barebones as I can get it in order to explain my problem.
****************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
PokerTable t = new PokerTable();
Console.WriteLine(t.ToString());
Console.ReadLine();
}
}
}
public class CardPlayer
{
public string name;
}
public class PokerPlayer : CardPlayer
{
public int chips = 1000;
}
public class CardTable
{
public CardPlayer[] player;
public CardTable()
{
player = new CardPlayer[5];
fillseats();
for (int i = 0; i < player.Length; i++)
player.name = i.ToString();
}
protected virtual void fillseats()
{
for (int i = 0; i<player.Length; i++)
player = new CardPlayer();
}
public override string ToString()
{
StringBuilder s = new StringBuilder();
for (int i = 0; i < player.Length; i++)
{
Console.WriteLine("Player " + player.name + ".");
}
return s.ToString();
}
}
public class PokerTable : CardTable
{
public PokerTable()
{
}
protected override void fillseats()
{
for (int i = 0; i < player.Length; i++)
player = new PokerPlayer();
}
public override string ToString()
{
StringBuilder s = new StringBuilder();
for (int i = 0; i < player.Length; i++)
{
s.AppendLine("Player " + player.name + " has " +
((PokerPlayer)player).chips + " chips.");
}
return s.ToString();
}
}
****************************************************************************
A PokerTable 'is' a CardTable and a PokerPlayer 'is' a CardPlayer.
A CardTable 'has' CardPlayers and a PokerTable 'has' PokerPlayers.
The only annoying thing is that every time I want to refer to the
player.chips member within PokerTable, I have to explicitly cast
player to a PokerPlayer first in order to get at it.
What I want is for player to 'be' a PokerPlayer within the PokerTable
class without having to cast it every time. I wouldn't mind so much if
CardPlayer[] player could be cast to PokerPlayer[] but I can't get that to
work.
Any ideas how to implement this idea?
****************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
PokerTable t = new PokerTable();
Console.WriteLine(t.ToString());
Console.ReadLine();
}
}
}
public class CardPlayer
{
public string name;
}
public class PokerPlayer : CardPlayer
{
public int chips = 1000;
}
public class CardTable
{
public CardPlayer[] player;
public CardTable()
{
player = new CardPlayer[5];
fillseats();
for (int i = 0; i < player.Length; i++)
player.name = i.ToString();
}
protected virtual void fillseats()
{
for (int i = 0; i<player.Length; i++)
player = new CardPlayer();
}
public override string ToString()
{
StringBuilder s = new StringBuilder();
for (int i = 0; i < player.Length; i++)
{
Console.WriteLine("Player " + player.name + ".");
}
return s.ToString();
}
}
public class PokerTable : CardTable
{
public PokerTable()
{
}
protected override void fillseats()
{
for (int i = 0; i < player.Length; i++)
player = new PokerPlayer();
}
public override string ToString()
{
StringBuilder s = new StringBuilder();
for (int i = 0; i < player.Length; i++)
{
s.AppendLine("Player " + player.name + " has " +
((PokerPlayer)player).chips + " chips.");
}
return s.ToString();
}
}
****************************************************************************
A PokerTable 'is' a CardTable and a PokerPlayer 'is' a CardPlayer.
A CardTable 'has' CardPlayers and a PokerTable 'has' PokerPlayers.
The only annoying thing is that every time I want to refer to the
player.chips member within PokerTable, I have to explicitly cast
player to a PokerPlayer first in order to get at it.
What I want is for player to 'be' a PokerPlayer within the PokerTable
class without having to cast it every time. I wouldn't mind so much if
CardPlayer[] player could be cast to PokerPlayer[] but I can't get that to
work.
Any ideas how to implement this idea?