Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CARD GAME LIBRARY ***clubclass.cs using System; using System.Collections.Generic; using System.Text; namespace CardGameLibray { public class ClubClass : ParentCardClass { public ClubClass(Rank pRank) { CardRank =

image text in transcribed

image text in transcribed

CARD GAME LIBRARY

***clubclass.cs

using System; using System.Collections.Generic; using System.Text;

namespace CardGameLibray { public class ClubClass : ParentCardClass { public ClubClass(Rank pRank) { CardRank = pRank; CardSuit = Suit.Club; } public override void Display() { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(CardRank + " of " + CardSuit + "s "); Console.ResetColor(); } } }

***diamondclass.cs

using System; using System.Collections.Generic; using System.Text;

namespace CardGameLibray { public class DiamondClass : ParentCardClass { public DiamondClass(Rank pRank) { CardRank = pRank; CardSuit = Suit.Diamond; } public override void Display() { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(CardRank + " of " + CardSuit + "s "); Console.ResetColor(); } } }

***HeartClass.cs

using System; using System.Collections.Generic; using System.Text;

namespace CardGameLibray { public class HeartClass : ParentCardClass { public HeartClass(Rank pRank) { CardRank = pRank; CardSuit = Suit.Heart; } public override void Display() { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(CardRank + " of " + CardSuit + "s "); Console.ResetColor(); } } }

***MyGameClass.cs

using System; using System.Collections.Generic; using System.Text;

namespace CardGameLibray { public class MyGameClass { public ParentCardClass[] TheDeckOfCards;

public MyGameClass() { TheDeckOfCards = new ParentCardClass[52];

int i = 0; Rank rankIndex = Rank.Deuce;

while (i

}

} }

***ParentCardClass.cs

using System; using System.Collections.Generic; using System.Text;

namespace CardGameLibray { public abstract class ParentCardClass { public Rank CardRank { get; set; } public Suit CardSuit { get; set; }

public abstract void Display();

} }

***rank.cs

using System;

namespace CardGameLibray { //an enum with 13 values, // Deuce Three Four Five Six Seven Eight Nine Ten Jack Queen King Ace // Deuce has value 2 and the others count up by 1 to the Ace = 14 public enum Rank { Deuce = 2, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace } }

***SpadeClass.cs

using System; using System.Collections.Generic; using System.Text;

namespace CardGameLibray { public class SpadeClass : ParentCardClass { public SpadeClass(Rank pRank) { CardRank = pRank; CardSuit = Suit.Spade; } public override void Display() { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(CardRank + " of " + CardSuit + "s "); Console.ResetColor(); } } }

***Suit.cs

using System; using System.Collections.Generic; using System.Text;

namespace CardGameLibray { //an enum with 4 values, Club Diamond Heart Spade // where Club has value 1 and the others count up by 1 public enum Suit { Club = 1, Diamond, Heart, Spade } }

FIGHT CARD GAME

***program.cs

using CardGameLibray; using System;

namespace FightCardGame { class Program { static void Main(string[] args) { // a. Create an instance of your MyGameClass class, and name it MyGame. MyGameClass MyGame = new MyGameClass();

// b. Using a foreach, build a loop that calls the Display method // for each card in the MyGame TheDeckOfCards array.

foreach (ParentCardClass item in MyGame.TheDeckOfCards) { item.Display(); } Console.WriteLine(); Console.WriteLine("================================================"); Console.WriteLine("================================================"); Console.WriteLine();

// uncomment this after you impliment the new Sort method in MyGameClass and // the IComparable method in the ParentCardClass // MyGame.Sort();

foreach (ParentCardClass item in MyGame.TheDeckOfCards) { item.Display(); }

// end of program

Console.ReadLine(); } } }

Start with my version of the card homework, makes sure it runs. It should write out the set of 52 cards twice when you run it. 1) Go to the MyGameClass and code a Sort method. It's just one line of code using the Array class's Sort method. It should sort your array of 52 cards. 2) Go to the ParentCardClass and add the IComparable reference to that class, and then implement its required Compare To method, where you will sort cards based on suit. 3) Go to Progam.cs and remove the // from the call so that it docs make that call. MyGame. Sort(); 4) Run the program again. It should write out the cards one way (see first picture) and then write them out a second time sorted by suit (see the second picture) Deuce of Spades Deuce of Hearts Deuce of Diamonds Deuce of Clubs Three of Spades Three of Hearts Three of Dianonds Three of Clubs Four of Spades Four of Hearts Four of Diamonds Four of clubs Five of Spades Five of Hearts Five of Diamonds Five of Clubs Six of Spades Six of Hearts six of Diamonds six of Clubs seven of Spades Seven of Hearts Seven of Diamonds seven of Clubs Eight Of Spades Eight of Hearts Eight of Dianends Eight of Clubs Nine of Spades Nine of Hearts Nine of Diamonds Nine of Clubs 4 Ten of Spades Ten of Hearts Ten of Diamonds Ten of Clubs Jack of Spades Jack of Hearts Dack of Diamonds Jack of clubs 4 Queen of Spades Queen of Hearts Queen of Diamonds Queen of Clubs King of Spades King of Hearts King of Dianonds King of Clubs Ace of Spades Ace of Hearts Ace of Diamonds Ace of Clubs Ace of Clubs Eight of Clubs Seven of Clubs Ton of clubs Six of clubs Jack of Clubs 4 Nine of Clubs Four of Clubs 4 Queen of Clubs Five of clubs Three of clubs Ace of clubs Eight of Clubs Seven of Clubs Ten of clubs 4 Six of Clubs Jack of Clubs + Nine of Clubs Four of Clubs Queen of Clubs + Five of Clubs Three of clubs + Deuce of Clubs King of Clubs Four of Diamonds Eight of Diamonds Ace of Diamonds Ten of Diamonds Deuce of Diamonds Seven of Diamonds Nine of Diamonds Jack of Diamonds King of Diamonds Three of Diamonds Five of Diamonds Queen of Diamonds Six of Diamonds King of Hearts Queen of Hearts Ace of Hearts Ten of Hearts Jack of Hearts Eight of Hearts Five of Hearts Deuce of Hearts Seven of Hearts Three of Hearts Six of Hearts Nine of Hearts Four of Hearts Ace of Spades - Three of Spades Four of Spades King of Spades Ten of Spades Queen of Spades Six of Spades Seven of Spades 4 Jack of Spades 4 Eight of Spades Nine of Spades Five of Spades Deuce of Spades 4 Start with my version of the card homework, makes sure it runs. It should write out the set of 52 cards twice when you run it. 1) Go to the MyGameClass and code a Sort method. It's just one line of code using the Array class's Sort method. It should sort your array of 52 cards. 2) Go to the ParentCardClass and add the IComparable reference to that class, and then implement its required Compare To method, where you will sort cards based on suit. 3) Go to Progam.cs and remove the // from the call so that it docs make that call. MyGame. Sort(); 4) Run the program again. It should write out the cards one way (see first picture) and then write them out a second time sorted by suit (see the second picture) Deuce of Spades Deuce of Hearts Deuce of Diamonds Deuce of Clubs Three of Spades Three of Hearts Three of Dianonds Three of Clubs Four of Spades Four of Hearts Four of Diamonds Four of clubs Five of Spades Five of Hearts Five of Diamonds Five of Clubs Six of Spades Six of Hearts six of Diamonds six of Clubs seven of Spades Seven of Hearts Seven of Diamonds seven of Clubs Eight Of Spades Eight of Hearts Eight of Dianends Eight of Clubs Nine of Spades Nine of Hearts Nine of Diamonds Nine of Clubs 4 Ten of Spades Ten of Hearts Ten of Diamonds Ten of Clubs Jack of Spades Jack of Hearts Dack of Diamonds Jack of clubs 4 Queen of Spades Queen of Hearts Queen of Diamonds Queen of Clubs King of Spades King of Hearts King of Dianonds King of Clubs Ace of Spades Ace of Hearts Ace of Diamonds Ace of Clubs Ace of Clubs Eight of Clubs Seven of Clubs Ton of clubs Six of clubs Jack of Clubs 4 Nine of Clubs Four of Clubs 4 Queen of Clubs Five of clubs Three of clubs Ace of clubs Eight of Clubs Seven of Clubs Ten of clubs 4 Six of Clubs Jack of Clubs + Nine of Clubs Four of Clubs Queen of Clubs + Five of Clubs Three of clubs + Deuce of Clubs King of Clubs Four of Diamonds Eight of Diamonds Ace of Diamonds Ten of Diamonds Deuce of Diamonds Seven of Diamonds Nine of Diamonds Jack of Diamonds King of Diamonds Three of Diamonds Five of Diamonds Queen of Diamonds Six of Diamonds King of Hearts Queen of Hearts Ace of Hearts Ten of Hearts Jack of Hearts Eight of Hearts Five of Hearts Deuce of Hearts Seven of Hearts Three of Hearts Six of Hearts Nine of Hearts Four of Hearts Ace of Spades - Three of Spades Four of Spades King of Spades Ten of Spades Queen of Spades Six of Spades Seven of Spades 4 Jack of Spades 4 Eight of Spades Nine of Spades Five of Spades Deuce of Spades 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

Which behavior do I want to improve the most?

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

b. Where did they come from?

Answered: 1 week ago