Program.cs
unknown
plain_text
2 years ago
8.8 kB
14
Indexable
Card[] deck = new Card[30];
Card[] p1deck = new Card[4];
Card[] p2deck = new Card[4];
Card[] actionDeck = new Card[2];
Player p1 = new Player();
Player p2 = new Player();
p1.ID = 1;
p2.ID = 2;
deck = GenerateDeck(deck);
p1deck = GeneratePlayerHand(p1deck);
p2deck = GeneratePlayerHand(p2deck);
bool game = true;
while(game)
{
PlayerTurn(p1, p1deck);
PlayerTurn(p2, p2deck);
}
Card[] GenerateDeck(Card[] d){
d[0] = new AdrenalineRush();
d[1] = new BasicAttack();
d[2] = new BasicHeal();
d[3] = new ChargeOmnicannon();
d[4] = new ConcussionCharge();
d[5] = new CriticalAttack();
d[6] = new FocusedCharge();
d[7] = new ForceSiphon();
d[8] = new GuardedByTheForce();
d[9] = new leadTheCharge();
d[10] = new PrototypeOmnicannon();
d[11] = new PulseCannon();
d[12] = new Recharge();
d[13] = new ReservePowercell();
d[14] = new Shockwave();
d[15] = new Stockstrike();
d[16] = new TechOverride();
d[17] = new Unyielding();
d[18] = new BasicAttack();
d[19] = new BasicHeal();
d[20] = new Battlemind();
d[21] = new EmergencyMedpac();
d[22] = new ForceStorm();
d[23] = new ThermalDetonator();
d[24] = new WaterFromNaboo();
d[25] = new GrandAdmiralThrawn();
d[26] = new LukeSkywalker();
d[27] = new AshokaTano();
d[28] = new MorganElsbeth();
d[29] = new C3P0();
return d;
}
Card[] GeneratePlayerHand(Card[] p)
{
for (int i = 0; i < p.Length; i++)
{
if (p[i] == null)
{
bool isSelecting = true;
while(isSelecting)
{
Random rand = new Random();
int selection = rand.Next(30);
if (deck[selection] != null)
{
p[i] = deck[selection];
deck[selection] = null;
isSelecting = false;
}
}
}
}
return p;
}
void PlayerTurn(Player player, Card[] playerDeck)
{
int i = 1;
Console.WriteLine($"Player {player.ID}'s turn");
Console.WriteLine($"Shield: {player.Shield}");
Console.WriteLine($"Health: {player.Health}");
Console.WriteLine("====================================");
foreach (Card card in playerDeck)
{
Console.Write($"({i}) ");
i++;
//Sets the Card Color
if (card.Ability == true)
{
Console.ForegroundColor = ConsoleColor.Yellow;
} else if (card.SpecialAbility == true)
{
Console.ForegroundColor = ConsoleColor.Green;
} else if (card.Companion == true)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("[Companion] ");
} else
{
Console.ForegroundColor = ConsoleColor.White;
}
//Print the colored card name
Console.Write($"{card.Name}");
//Set fg color to white for text
Console.ForegroundColor = ConsoleColor.White;
Console.Write(" | ");
if (card.Heal > 0)
{
//Healing cards
Console.Write("Heals for ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write($"{card.Heal} health ");
} else if (card.Damage > 0)
{
//Damage cards
Console.Write("Damages for ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write($"{card.Damage} points ");
} else
{
Console.Write("ERROR - no damage or healing amount");
}
Console.ForegroundColor = ConsoleColor.White;
Console.Write(" | ");
Console.Write($"{card.FlavorText}");
Console.WriteLine();
}
Console.WriteLine("====================================");
PlayCard(playerDeck, player);
//Attack
if (player.ID == 1)
{
if (player.Companion != null)
{
//Player has companion
if (player.Companion.Heal > 0)
{
player.Health += player.Companion.Heal;
if (player.Health > 100)
{
player.Health = 100;
}
}
//Damage
if (player.Companion.Damage > 0)
{
p2.Shield -= player.Companion.Damage;
if (p2.Shield < 0)
{
p2.Health += p2.Shield;
p2.Shield = 0;
}
}
}
for (int j = 0; j < actionDeck.Length; j++)
{
if (actionDeck[j].Heal > 0)
{
if (player.Health != 100)
{
player.Health += actionDeck[j].Heal;
if (player.Health > 100)
{
player.Health = 100;
}
}
} else if (actionDeck[j].Damage > 0)
{
if(p2.Companion != null)
{
//They have a companion
p2.Companion.Health -= actionDeck[j].Damage;
} else
{
p2.Shield -= actionDeck[j].Damage;
if (p2.Shield < 0)
{
p2.Health += p2.Shield;
p2.Shield = 0;
}
}
}
}
}
if (player.ID == 2)
{
if (player.Companion != null)
{
//Player has companion
if (player.Companion.Heal > 0)
{
player.Health += player.Companion.Heal;
if (player.Health > 100)
{
player.Health = 100;
}
}
//Damage
if (player.Companion.Damage > 0)
{
p1.Shield -= player.Companion.Damage;
if (p1.Shield < 0)
{
p1.Health += p1.Shield;
p1.Shield = 0;
}
}
}
for (int j = 0; j < actionDeck.Length; j++)
{
if (actionDeck[j].Heal > 0)
{
if (player.Health != 100)
{
player.Health += actionDeck[j].Heal;
if (player.Health > 100)
{
player.Health = 100;
}
}
}
else if (actionDeck[j].Damage > 0)
{
p1.Shield -= actionDeck[j].Damage;
if (p1.Shield < 0)
{
p1.Health += p1.Shield;
p1.Shield = 0;
}
}
}
}
Console.ReadLine();
}
void PlayCard(Card[] playerDeck, Player player)
{
bool playerHasCompanion = false;
if (player.Companion != null)
{
playerHasCompanion = true;
}
bool select = false;
while(select == false)
{
Console.WriteLine("1st selection (type in number): ");
int selection = int.Parse(Console.ReadLine()) - 1;
if (playerDeck[selection].Companion == true && playerHasCompanion == true)
{
Console.WriteLine("Invalid selection - you already have a companion");
}
else
{
actionDeck[0] = playerDeck[selection];
if (playerDeck[selection].Companion == true)
{
player.Companion = playerDeck[selection];
playerHasCompanion = true;
}
playerDeck[selection] = null;
select = true;
}
}
select = false;
while (select == false)
{
Console.WriteLine("2nd selection (type in number): ");
int selection = int.Parse(Console.ReadLine()) - 1;
if (playerDeck[selection] != null)
{
actionDeck[1] = playerDeck[selection];
if (playerDeck[selection].Companion == true && playerHasCompanion == false)
{
player.Companion = playerDeck[selection];
playerHasCompanion = true;
}
playerDeck[selection] = null;
select = true;
}
else
{
Console.WriteLine("Invalid selection");
}
}
playerDeck = GeneratePlayerHand(playerDeck);
/* foreach (Card card in actionDeck)
{
bool placed = false;
while(placed == false)
{
for(int i = 0; i < deck.Length; i++)
{
if (deck[i] == null)
{
deck[i] = card;
placed = true;
}
placed = true;
}
}
}*/
}
Editor is loading...
Leave a Comment