Question: I am new to coding and would just like some help understanding this project. I am stuck on Function - Use the Suits and
I am new to coding and would just like some help understanding this project. I am stuck on "
- Function - Use the Suits and Ranks passed in as parameters to initialize the new objects fields.
- Create public methods
- static int CompareCards (PlayingCard Card1, PlayingCard Card2)
- Function - Compare the value (See GetValue method) of Card1 with the value of Card2. Return -1 if Card1 has a higher value than Card2, return 0 if Card1 and Card2 have the same value, and return 1 if Card2 has a higher value than Card1."
There are times i understand the coding and times like this where i am just lost. If changes to the coding below be used with a different color so i can understand what i missed or even some //comments so i can finish the coding myself
Overview:
Up until this point, you have learned:
- How to create variables
- How to take input from the user
- How to create conditional statements in code
- How to create functions / methods
- and more
This assignment sets the stage for making a game later in the course. For this assignment you'll make a functional PlayingCard class using the starter project. In later weeks we'll expand upon the idea of the PlayingCard by adding a Deck class for week 2 and then using those classes to create a card game during week 3. The playing card class will be able to do the following:
- Represent any card normally found in a deck of playing cards by holding values for a playing cards suit (hearts, diamonds, clubs, or spades) and rank (Ace-King)
- Provide methods for getting a cards suit, rank, and value (using typical black jack values of 2-10 with Ace having a value of 11 or alternate value of 1)
- Provide a method for comparing the value of two cards
- Provide methods for displaying the cards face and back
The purpose of this assignment is to define a class that can be used in later projects. Youll practice problem solving by writing the logic required to make methods work as described in the instructions / rubric. This assignment isnt about how to design a playing card. Playing cards already exist. The assignment is how to represent the concept of a Playing card in code (By default C# doesnt know what a PlayingCard is). Can you take the fundamental building blocks you have learned and put them together to create the desired result?
You will be using Visual Studio to make a C# Console Application (.net framework).
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 theyll allow that item.
- Make sure to complete the Setup Confirmation assignment. It will walk you through how to prepare a Visual Studoi project.
- Download the supplied starter project: See download link
- Extract the project from the zip file to a location on your hard drive. (I recommend a location like Documents/FullSail/DES1/Assignments).
- Youll need to implement the required functionality for the PlayingCard class. I recommend writing code in main to test the different methods as you complete them.
- PlayingCard class:
- Create fields:
- private field of type Suits - this field will hold the PlayingCards suit (ex hearts, diamonds, etc).
- private field of type Ranks - this field will hold the PlayingCards rank (ex two, ten, queen, etc).
- Create constructor
- public PlayingCard (Suits NewSuit, Ranks NewRank)
- Function - Use the Suits and Ranks passed in as parameters to initialize the new objects fields.
- Create public methods
- static int CompareCards (PlayingCard Card1, PlayingCard Card2)
- Function - Compare the value (See GetValue method) of Card1 with the value of Card2. Return -1 if Card1 has a higher value than Card2, return 0 if Card1 and Card2 have the same value, and return 1 if Card2 has a higher value than Card1.
- Suits GetSuit()
- Return the PlayingCards suit
- Ranks GetRank()
- Return the PlayingCards rank
- int GetValue()
- Return the value of the card based on its rank (Ace - 11, Face cards - 10, 10-2 value is the same as the rank).
- int GetAltValue()
- Return the value of the card based on its rank (Ace - 1, Face cards - 10, 10-2 value is the same as the rank)
- void DisplayCardAtLocation (int XPosition, int YPosition)
- Use simple console drawing techniques to display the card face at the specified (x, y) position on the screen. See rubric for additional requirements about the display methods (ex how the card should look etc).
- void DisplayCardBackAtLocation (int XPosition, int YPosition)
- Use simple console drawing techniques to display the card back at the specified (x, y) position on the screen. See rubric for additional requirements about the display methods (ex how the card should look etc).
Using Visual Studios code is as follows:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace DES1_Week1_PlayingCardAssignment { class PlayingCard private Suits private Ranks public PlayingCard(Suits NewSuit, Ranks NewRank) static int CompareCards (PlayingCard Card1, PlayingCard Card2) { private static char HeartSymbol = Encoding.GetEncoding(437).GetChars(new byte[] { 3 })[0]; private static char DiamondSymbol = Encoding.GetEncoding(437).GetChars(new byte[] { 4 })[0]; private static char ClubSymbol = Encoding.GetEncoding(437).GetChars(new byte[] { 5 })[0]; private static char SpadeSymbol = Encoding.GetEncoding(437).GetChars(new byte[] { 6 })[0];
public static int CardWidth = 5; public static int CardHeight = 3;
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 };
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
