using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DES1_DeckAndMenu { internal class Program {
Question:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DES1_DeckAndMenu { internal class Program { static void Main(string[] args) { //PlayingCard Card = new PlayingCard(PlayingCard.Suits.Hearts, PlayingCard.Ranks.Seven); //Card.DisplayCardAtLocation(10, 5); //Card.DisplayCardBackAtLocation(16, 5); // TODO: Make a deck variable and assign a new object of type deck to it // TODO: Make a menu that will let players choose from the following options // - Fill Deck // - Shuffle Deck // - Cut Deck (Random number of cards) // - Cut Deck (Player selects how many cards to cut off the top) // - Draw a card from the deck and display the card // - Display every card in the deck // - Quit the program // TODO: Add a loop so the program keeps running until the player chooses to quit // TODO: Implement each of the menu options so they call the required functions on your deck variable // - (Will often require additional code for full functionality) PressAKey("Press any key to continue"); } static void PressAKey(string Message) { // Save console cursor position int OldX = Console.CursorLeft; int OldY = Console.CursorTop; // Write message at the bottom of the console window Console.SetCursorPosition(0, Console.WindowHeight - 1); Console.Write(Message); Console.ReadKey(); // Return the cursor to its previous location Console.SetCursorPosition(OldX, OldY); } } } using System; using System.Runtime.InteropServices; /********************************************************************************************************************** * * DO NOT CHANGE ANYTHING IN THIS FILE * * DO NOT CHANGE ANYTHING IN THIS FILE * * DO NOT CHANGE ANYTHING IN THIS FILE * *********************************************************************************************************************/ namespace DES1_DeckAndMenu { public class PlayingCard { #region DLL const string RelativePath = "lib/CardGame.dll"; [DllImport(RelativePath)] private static extern IntPtr CreatePlayingCard(int NewSuit, int NewRank); [DllImport(RelativePath)] private static extern void DestoryPlayingCard(IntPtr Target); [DllImport(RelativePath)] private static extern int GetSuit_IntPtr(IntPtr Target); [DllImport(RelativePath)] private static extern int GetRank_IntPtr(IntPtr Target); [DllImport(RelativePath)] private static extern int GetValue_IntPtr(IntPtr Target); [DllImport(RelativePath)] private static extern int GetAltValue_IntPtr(IntPtr Target); [DllImport(RelativePath)] private static extern void DisplayCardAtLocation_IntPtr(IntPtr Target, int x, int y); [DllImport(RelativePath)] private static extern void DisplayCardBackAtLocation_IntPtr(IntPtr Target, int x, int y); [DllImport(RelativePath)] private static extern int CompareCards_IntPtr_IntPtr(IntPtr TargetOne, IntPtr TargetTwo); private IntPtr Card; #endregion public enum Suits { Hearts = 0, Diamonds, Spades, Clubs, NUM_SUITS }; public enum Ranks { Ace = 1, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, NUM_RANKS }; public static int CardWidth = 5; public static int CardHeight = 3; public PlayingCard(Suits NewSuit, Ranks NewRank) { Card = CreatePlayingCard((int)NewSuit, (int)NewRank); } ~PlayingCard() { DestoryPlayingCard(Card); } public Suits GetSuit() { return (Suits)GetSuit_IntPtr(Card); } public Ranks GetRank() { return (Ranks)GetRank_IntPtr(Card); } public int Getvalue() { return GetValue_IntPtr(Card); } public int GetAltValue() { return GetAltValue_IntPtr(Card); } public void DisplayCardAtLocation(int x, int y) { DisplayCardAtLocation_IntPtr(Card, x, y); } public void DisplayCardBackAtLocation(int x, int y) { DisplayCardBackAtLocation_IntPtr(Card, x, y); } public static int CompareCards(PlayingCard CardOne, PlayingCard CardTwo) { return CompareCards_IntPtr_IntPtr(CardOne.Card, CardTwo.Card); } public override string ToString() { return $"{GetRank()} of {GetSuit()}"; } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DES1_DeckAndMenu { internal class Deck { // Fields //////////////////////////////////////////////////////////////////////////////////////////////// // TODO: Declare required fields here like the array of PlayingCards to hold all of the cards in the deck. // Constructors ////////////////////////////////////////////////////////////////////////////////////////// // TODO: Implement a default constructor // TODO: Implement a constructor that takes an parameter for the size of the deck // Public Methods //////////////////////////////////////////////////////////////////////////////////////// // TODO: Implement AddCard method // TODO: Implement Shuffle method // TODO: Implement DrawCard method // TODO: Implement CutDeck method // TODO: Implement DisplayDeck method // Private Methods /////////////////////////////////////////////////////////////////////////////////////// // TODO: Implement any private methods that you need here // Static Methods //////////////////////////////////////////////////////////////////////////////////////// // TODO: Implement FillDeckWIthPlayingCards method } } C# Only Overview: Up until this point, you have: Enumerations Switches Intentional fall-through Classes Fields Constructors Methods Methods Loops for while do-while Arrays AnyDataType[] ArrayVariableName This assignment sets the stage for making a game later in the course. For this assignment you'll make a functional Deck class using the supplied PlayingCard class (built into the starter project). In later weeks we'll expand upon the idea by using the PlayingCard and Deck classes to make a card game. The Deck class will do the following: Represent a deck of PlayingCards Have methods that will allow the user to Fill the deck with the 52 cards found in a standard playing card deck Add PlayingCards to the deck Shuffle all of the cards in the deck Draw a card from the deck Cut a number of cards off the top of the Deck and place them on the bottom of the deck. Random cut (number of cards to cut is selected randomly) Player cut (a value is passed into the cut function to indicate where the player wants to cut the deck at) Display every card in the deck The program class will implement a menu with several required options that will allow the player to test the functionality of the Deck class. This assignment will require extensive use of arrays and loops to complete. Successfully creating the PlayingCard and Deck classes sets you up to make a card game using those classes as the starting point. Instructions: Note - Do not use the following items in your code: goto, foreach loops, Linq commands, C# Properties, or Generics/Tempaltes. If you want to use anything not taught in the course lectures contact your instructor first and check if they'll allow that item. 1. View the example video to see how your program should run (Doesn't have to be exactly the same but should be similar). See example video 2. Download the supplied starter project: See download link 3. Extract the project from the zip file to a location on your hard drive. (I recommend a location like Documents/FullSail/DES1/Assignments). 4. Do not use generic types or LINQ commands - the point of this assignment is to show that you understand arrays and how to use data stored in them. 5. Deck class: 6. Create constructors 7. Default: 8. Parameters 9. None 10. Overloaded constructor: 11. Parameters 12. Int: this value represents the desired number of cards in the deck and should be used to initialize the deck's array of PlayingCards to hold that number of cards. 13. Create public methods 14. static void FillDeckWithPlayingCards 15. Parameters 16. Deck: this is the deck object that is to be filled with cards 17. Function 18. If the deck passed in cannot hold 52 cards - initialize the array to hold 52 cards. 19. fill the deck with each card ace-king for each suit (hearts, clubs ...) 20. void DisplayDeck 21. Parameters 22. Int: required parameter that specifies how many cards draw in a row before starting a new row 23. Int: optional parameter that specifies a x position on the screen to start drawing cards at 24. Int: optional parameter that specifies a y position on the screen to start drawing cards at 25. Function 26. Draw ever card in the deck 1 at a time going across the screen in rows. Drop down to a make a new row after x cards where x is the number passed in as the first parameter 27. void AddCard 28. Parameters 29. PlayingCard: card that should be added into the deck 30. Function 31. if the deck isn't full then add the passed in card on top as the next card to be drawn. 32. void Shuffle 33. Parameters 34. None 35. Function 36. This method will randomize the position of all of the cards in the deck 37. PlayingCard DrawCard 38. Parameters 39. None 40. Function 41. This method will remove the top card from the deck and return that card assuming the deck isn't empty 42. void CutDeck 43. Parameters 44. Int: optional parameter that specifies where to cut the deck (number of cards to take off of the top of the deck). Should default to a value of -1. 45. Function 46. If the parameter is a positive value then cut that many cards off the top of the deck. 47. if the parameter is negative then cut a random number of cards off the top of the deck 48. must handle players trying to cut more cards than are in the deck. 49. Program: 50. Make a menu in main that will allow the player to test the following deck options. (This menu should run in a loop until the player chooses to quit) 51. Fill the deck with playing cards 52. Shuffle the cards in the deck 53. Cut a random number of cards from the top of the deck 54. Cut a number of cards from the top of the deck specified by the player (required input from the player) 55. Display all of the cards in the deck 56. Quit 57. quit by selecting the menu options (the number) 58. quit by typing "quit" 59. quit by typing "exit" 60. The player should not be able to crash the program with invalid input