Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8843373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:12:14+00:00 2026-06-14T11:12:14+00:00

I worked on a Blackjack game which I created, and I want it to

  • 0

I worked on a Blackjack game which I created, and I want it to be object oriented.

I first coded it without having that in mind, but I want it to be divided into different classes.
I believe I need to put the methods in various classes and name them appropriately.
The problem is that how do I do this?

I thought it would be as simple as putting “public” in front of every method, but it didn’t work.

How do I do this?

If you want my source code, here it is:

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

namespace blackJack
{

/// <summary>
/// 'playerCards' will store the player's cards. The maximum of cards a player can hold is 11.
/// 'hitOrStand' asks the player if they want to hit or stand.
/// 
/// 'score' cardCounts the player's score for that round.
/// 'cardCount' increases so that the player can hold multiple cards in their hand.
/// 'scoreDealer' cardCounts the dealer's score for that round.
/// 
/// 'newCard' works to randomize the player's cards.
/// </summary>

class Program
{
    static Random newCard = new Random();
    static int score = 0, cardCount = 1, scoreDealer = 0;
    static string[] playerCards = new string[11];
    static string hitOrStand = "";

    /// <summary>
    /// MAIN METHOD
    /// 
    /// The Main method starts the game by executing 'Start()'
    /// </summary>

    static void Main(string[] args)
    {
        Start();
    }

    /// <summary>
    /// START METHOD
    /// 
    /// The Start method lets the player know that they are playing Blackjack.
    /// Then it deals the player two cards (because in Blackjack, you start with two cards).
    /// It tells the player what their score score is at that moment.
    /// Finally, it asks the player if they want to hit (continue and get a new card), or stand (stop) through the Game() method (which lies below this).
    /// </summary>

    static void Start()
    {
        scoreDealer = newCard.Next(15, 22);
        playerCards[0] = Deal();
        playerCards[1] = Deal();
        do
        {
            Console.WriteLine("Welcome! The dealer gives you " + playerCards[0] + " and " + playerCards[1] + ". \nScore: " + score + ".\nWould you like to hit or stand?");
            hitOrStand = Console.ReadLine().ToLower();
        } while (!hitOrStand.Equals("hit") && !hitOrStand.Equals("stand"));
        Game();
    }

    /// <summary>
    /// GAME METHOD
    /// 
    /// The Game method checks if the player did hit or if the player did stand.
    /// If the player did hit, that method (the Hit method) is executed.
    /// But if the player did stand, it checks if their score is larger than the dealer's AND if the score equals/less than 21.
    /// If the above statement is TRUE, it will congratulate, and reveal the dealer's score. Then it'll ask if the player wants to play again.
    /// 
    /// However, if the above is FALSE, it will tell the player that they lost, reveal the dealer's score, and ask if the player wants to play again.
    /// </summary>

    static void Game()
    {
        if (hitOrStand.Equals("hit"))
        {
            Hit();
        }
        else if (hitOrStand.Equals("stand"))
        {
            if (score > scoreDealer && score <= 21)
            {
                Console.WriteLine("\nCongratulations! You won! The dealer's score was " + scoreDealer + ".\nWould you like to play again? y/n");
                PlayAgain();
            }
            else if (score < scoreDealer)
            {
                Console.WriteLine("\nYou lost! The dealer's score was " + scoreDealer + ".\nWould you like to play again? y/n");
                PlayAgain();
            }

        }
        Console.ReadLine();
    }

    /// <summary>
    /// DEAL METHOD
    /// 
    /// The Deal method creates a random number between 1 and 14.
    /// Then that int switches and assigns a value to Card.
    /// Depending on its result, it will add to the amount on score.
    /// Lastly, it'll return the string Card.
    /// 
    /// Below, all the cards that are available can be viewed.
    /// </summary>

    static string Deal()
    {
        string Card = "";
        int cards = newCard.Next(1, 14);
        switch (cards)
        {
            case 1: Card = "2"; score += 2;
                break;
            case 2: Card = "3"; score += 3;
                break;
            case 3: Card = "4"; score += 4;
                break;
            case 4: Card = "5"; score += 5;
                break;
            case 5: Card = "6"; score += 6;
                break;
            case 6: Card = "7"; score += 7;
                break;
            case 7: Card = "8"; score += 8;
                break;
            case 8: Card = "9"; score += 9;
                break;
            case 9: Card = "10"; score += 10;
                break;
            case 10: Card = "Jack"; score += 10;
                break;
            case 11: Card = "Queen"; score += 10;
                break;
            case 12: Card = "King"; score += 10;
                break;
            case 13: Card = "Ace"; score += 11;
                break;
            default: Card = "2"; score += 2;
                break;
        }
        return Card;
    }

    /// <summary>
    /// HIT METHOD
    /// 
    /// The Hit method adds another card to the player's hand, as they demanded (when they decided to hit instead of stand).
    /// Then it checks if the player still holds an amount less than 21, got Blackjack (21), or Busted (received an amount over 21).
    /// 
    /// If the amount is less than 21, the player may continue, and they will be asked if they'd like to hit or stand.
    /// </summary>

    static void Hit()
    {
        cardCount += 1;
        playerCards[cardCount] = Deal();
        Console.WriteLine("\nYou were dealed a " + playerCards[cardCount] + ".\nYour new score is " + score + ".");
        if (score.Equals(21))
        {
            Console.WriteLine("\nBlackjack! Congratulations! The dealer's score was " + scoreDealer + ".\nWould you like to play again? y/n");
            PlayAgain();
        }
        else if (score > 21)
        {
            Console.WriteLine("\nYou busted, and lost. The dealer's score was " + scoreDealer + ".\nWould you like to play again? y/n");
            PlayAgain();
        }
        else if (score < 21)
        {
            do
            {
                Console.WriteLine("\nWould you like to hit or stand?");
                hitOrStand = Console.ReadLine().ToLower();
            } while (!hitOrStand.Equals("hit") && !hitOrStand.Equals("stand"));
            Game();
        }
    }

    /// <summary>
    /// PLAYAGAIN METHOD
    /// 
    /// This method simply asks the player if they want to play again, or not.
    /// If the player replies with a 'y', it will tell the player to press enter in order to restart the game.
    /// 
    /// If the player replies with an 'n', it will tell the player to press enter in order to close the game.
    /// </summary>

    static void PlayAgain()
    {
        string playAgain = "";
        do
        {
            playAgain = Console.ReadLine().ToLower();
        } while (!playAgain.Equals("y") && !playAgain.Equals("n"));
        if (playAgain.Equals("y"))
        {
            Console.WriteLine("\nPress Enter to play again.");
            Console.ReadLine();
            Console.Clear();
            scoreDealer = 0;
            cardCount = 1;
            score = 0;
            Start();
        }
        else if (playAgain.Equals("n"))
        {
            Console.WriteLine("\nThank you for playing. \nPress Enter to close the game.");
            Console.ReadLine();
            Environment.Exit(0);
        }

    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:12:15+00:00Added an answer on June 14, 2026 at 11:12 am

    The conceptual approach to the term “Object-Oriented” is to tackle a code problem with, from my point of view, a view as close to reality as possible.

    What I meant by that is, if you would have to create the behavior of a car, you would encapsulate all the variables and functions related to that “object” inside a class, so that when you would instantiate it, you would in effect create an object “car” inside the computer that would react the same way a real object would.

    Hierarchy between classes come from the same concept. We know a car is a vehicle, but you know you cannot create a vehicle because it’s an abstract concept. Variables and functions that are general to all vehicle should be inside that abstract class, from which every other car/bike/truck derive from.

    In case of a card game, each card could become an object, that would contain a reference towards their visual. So, you would get a List<Card> allowing you to easily pick, remove or add one. The table could be an object too, that contain position/id of the players and where the cards go when distributed.

    But direct “object” approach is not always possible, as in real life, there is no such thing as a “Game” object that contains rules and overview the steps of the game. But once you understand the concept being OO Programming, you would see that it’s basically how and where you put your variables and your functions, and how polymorphism and a clean structure make for much easier to read and maintain code.

    OO Programming is not such an easy term to understand, and when people start mixing philosophy with it, it just get harder for no reason. I actually give a 4 hours class as introduction to this notion, so don’t expect to catch all of it in minutes. At first, just try putting the stuff where they sound the most logical place to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've never worked with percentage layouts. Of course, I already study them, but without
I worked in Eclipse before, but IDEA seems more comfortable for me. I want
Having worked with Django , I've seen that people tend to reccommend the use
I worked with MySQL database but since I work with Rails I understand that
I worked with a graphic designer that did not clone from my github account.
I worked with Haxe and actionscript programming, but I'm new to flex. Here's my
I worked out an XSL template that rewrites all hyperlinks on an HTML page,
THE ANSWER THAT WORKED FOR ME BASED ON AN ANSWER GIVEN while($post = mysql_fetch_array($tags))
Having worked through some tutorials on some basics via the iPhone, I'm struggling to
I worked on a project that had the following requirement: TableA is the parent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.