Thread: Blackjack, nearly completed!

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    Blackjack, nearly completed!

    Okay, so as most of you might know I've been working on a blackjack game and I'm very close to completion of my first project.

    I'd like anyone to reply to me if they want the source code or an executable for my blackjack game. I'm not going to bother posting any source code here except for my main.cpp file. The rest of the code is split up between nearly 30 different files. If you want to take a look at it (for constructive criticism purposes, please do take a look at it!) I can email you the source.

    The only issues I need to resolve include preventing the game from crashing when I tell it to exit, and adding the split hand option in case we get dealt two identical cards at game start. Double down works, betting works, everything works like it should for the most part.

    Here is the main.cpp file!

    Code:
    // Main.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <time.h>
    #include "Game.h"
    #include "State_Manager.h"
    #include "Menu_State.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	// random seed for the shuffle function
    	srand ( unsigned(time(NULL)) );
    	// pointer to game engine
    	Card_Game * game = new Card_Game(); 
    	// pointer to the state manager
    	State_Manager state_manager;
    	// initialize the engine
    	game->init();
    	// load the intro state & pass game engine to the state manager
    	state_manager.change_state( Menu_State::instance(), game );
    	// main loop
    	while ( state_manager.running() )
    	{
    		state_manager.update(game);			// do updates
    		state_manager.print(game);			// print text
    		state_manager.handle_events(game);  // get input and handle events
    	}
    	// cleanup the engine
    	game->cleanup();
        return 0;
    }
    suprise! it's not a single function, its not an enourmous jumbled mess. it's juuuuust right

    If you're curious reply here and pm me!

    EDIT:
    I just figured out how to get my project attached, just rename it to .rar when you dl it!


    Attachment removed by moderator.
    Last edited by VirtualAce; 01-20-2008 at 11:16 AM.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Looks well modularized, from your one function.

    Don't forget <stdlib.h>/<cstdlib> for srand() . . . .

    I wouldn't mind having a look at it (I'm developing a card game at the moment as well). You can always compress everything into an archive, rename it to .txt, and attach it to your post.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Ah figured out the attachment thing.

    Modularity is what I've been focusing on from the beginning. I'm trying to write nice object oriented code that is flexible and modular.

    Eventually I want to virtualize the game engine. I want to be able to derive other card games from a single card_game base class

    Also I want to add in key_checking so I can navigate menu's with enter and up/down arrow keys.
    Last edited by Shamino; 01-18-2008 at 04:56 PM.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Right, next time I'm on a Windows computer, I'll let you know how it goes . . . you do know that you didn't include any executables in your archive?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by Shamino View Post
    I've been working on a blackjack game and I'm very close to completion of my first project.
    In my opinion, your code has too many comments. People sometimes learn this habit from textbooks, but textbooks have a reason for translating trivial lines of code into English. Real programs don't need that.

    For the _tmain function you posted above, I would remove every single comment. The code is well-enough written, modularized with good function and variable names, that it is self-explanatory.

    Just follow this rule: If your comment simply restates what the code already clearly states, then the comment is worse than useless. It is far more readable, to me at least, like this: (although it could use an overall descriptive comment)
    Code:
    #include "stdafx.h"
    #include <time.h>
    #include "Game.h"
    #include "State_Manager.h"
    #include "Menu_State.h"
     
    int _tmain(int argc, _TCHAR* argv[])
    {
        srand ( time(NULL) );
        Card_Game * game = new Card_Game(); 
        State_Manager state_manager;
     
        game->init();
        state_manager.change_state( Menu_State::instance(), game );
     
        while ( state_manager.running() )
        {
            state_manager.update(game);
            state_manager.print(game);
            state_manager.handle_events(game);
        }
     
        game->cleanup();
        return 0;
    }

  6. #6
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    i dont know blackjack game, but it sounds like it's a card game..... ADDICTIVE they are
    i'm also developing my WinAPI32 game of UNO. Maybe later we'll exchange ideas
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    37
    is it graphical?

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    A word of caution to circumventing the attachment restrictions. All attachments that have executables in them or file formats that are not allowed will be removed from the board.

  9. #9
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    Quote Originally Posted by h3ckf1r3 View Post
    is it graphical?
    yep. Here it is (being programmed)
    here in this screen shot i was testing the "Draw" function as well as some others (like random shuffle) -- attached


    after I release the first version i intend to work some "photo-shop" guy to release a better-looking one
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  2. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  3. Help with Blackjack program
    By sugie in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2005, 12:30 AM
  4. Blackjack!
    By Dr. Bebop in forum Game Programming
    Replies: 1
    Last Post: 10-03-2002, 08:58 PM
  5. BlackJack Program...
    By 67stangman in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2002, 10:44 PM