+1 (315) 557-6473 

Program To Create a Card Game in C Assignment Solutions.


Instructions

Objective
Write a C assignment program to create a card game.

Requirements and Specifications

Program to create a card game in C language
Program to create a card game in C language 1
Program to create a card game in C language 2
Program to create a card game in C language 3
Program to create a card game in C language 4
Program to create a card game in C language 5
Program to create a card game in C language 6
Program to create a card game in C language 7
Program to create a card game in C language 8
Program to create a card game in C language 9
Program to create a card game in C language 10

Source Code

PLAYING CARDS

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace DES1_Week1_PlayingCardAssignment

{

    class PlayingCard

    {

        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

        };

        // TODO: Implement the required Fields

        private Suits suit;

        private Ranks rank;

        // TODO: Implement the requried Constructor(s)

        public PlayingCard(Suits suit, Ranks rank)

        {

            this.suit = suit;

            this.rank = rank;

        }

        // TODO: Implement the required Methods

        public Suits GetSuit() {

            return suit;

        }

        public Ranks GetRank() {

            return rank;

        }

        public int GetValue() {

            if (rank == Ranks.Ace) {

                return 11;

            }

            if (rank == Ranks.Jack || rank == Ranks.Queen || rank == Ranks.King) {

                return 10;

            }

            return (int)rank;

        }

        public void DisplayCardAtLocation(int XPosition, int YPosition) {

            {

                int currX = 0;

                int currY = 0;

                while (currY < YPosition + CardHeight)

                {

                    if (currY < YPosition)

                    {

                        Console.WriteLine();

                        currY++;

                    }

                    else

                    {

                        if (currX < XPosition)

                        {

                            Console.Write(" ");

                            currX++;

                        }

                        else

                        {

                            switch (currY - YPosition) {

                                case 0:

                                case 2:

                                    Console.WriteLine("*" + RankToString() + SuitToString() + "*");

                                    break;

                                case 1:

                                    Console.WriteLine("* *");

                                    break;

                            }

                            currX += CardWidth;

                        }

                        if (currX >= XPosition + CardWidth)

                        {

                            currX = 0;

                            currY++;

                        }

                    }

                }

            }

        }

        public void DisplayCardBackAtLocation(int XPosition, int YPosition)

        {

            int currX = 0;

            int currY = 0;

            while (currY < YPosition + CardHeight) {

                if (currY < YPosition)

                {

                    Console.WriteLine();

                    currY++;

                }

                else {

                    if (currX < XPosition)

                    {

                        Console.Write(" ");

                        currX++;

                    }

                    else {

                        Console.WriteLine("*****");

                        currX += CardWidth;

                    }

                    if (currX >= XPosition + CardWidth) {

                        currX = 0;

                        currY++;

                    }

                }

            }

        }

        // TODO: Implement the required Static Methods

        public static int CompareCards(PlayingCard card1, PlayingCard card2) {

            int val1 = card1.GetValue();

            int val2 = card1.GetValue();

            if (val1 < val2)

            {

                return -1;

            }

            else if (val1 > val2)

            {

                return 1;

            }

            else {

                return 0;

            }

        }

        // TODO: Double check the rubric. Did you get all of your points?

        private String SuitToString() {

            switch (suit) {

                case Suits.Spades:

                    return "" + SpadeSymbol;

                case Suits.Diamonds:

                    return "" + SpadeSymbol;

                case Suits.Clubs:

                    return "" + ClubSymbol;

                case Suits.Hearts:

                    return "" + HeartSymbol;

                default:

                    return "";

            }

        }

        private String RankToString()

        {

            switch (rank)

            {

                case Ranks.Ace:

                    return " A";

                case Ranks.Two:

                    return " 2";

                case Ranks.Three:

                    return " 3";

                case Ranks.Four:

                    return " 4";

                case Ranks.Five:

                    return " 5";

                case Ranks.Six:

                    return " 6";

                case Ranks.Seven:

                    return " 7";

                case Ranks.Eight:

                    return " 8";

                case Ranks.Nine:

                    return " 9";

                case Ranks.Ten:

                    return "10";

                case Ranks.Jack:

                    return " J";

                case Ranks.Queen:

                    return " Q";

                case Ranks.King:

                    return " K";

                default:

                    return "";

            }

        }

    }

}