Thread: First program (Black Jack game)

  1. #16
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    Hmmmm, I don't see why you encrypt anything. And you can also just do this if you want to check for a file.



    Code:
    FILE* SaveGame= fopen(FILENAME, "r");
    
    if (file == NULL) {cout << "SAVED GAME NOT FOUND...";}
    
    else {
    
    //load game.
    
    }
    you will need to #include <stdio.h>...

  2. #17
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by Dagger
    Hmmmm, I don't see why you encrypt anything. And you can also just do this if you want to check for a file.



    Code:
    FILE* SaveGame= fopen(FILENAME, "r");
    
    if (file == NULL) {cout << "SAVED GAME NOT FOUND...";}
    
    else {
    
    //load game.
    
    }
    you will need to #include <stdio.h>...
    Great idea!! Let's use outdated C File I/O in C++ when we're already including libraries that use ostream and istream. Why would you mix the two and what makes you think that code works better?
    Last edited by SlyMaelstrom; 02-24-2006 at 01:42 PM.
    Sent from my iPadŽ

  3. #18
    Nothing is impossible! 74466's Avatar
    Join Date
    Jan 2006
    Location
    Bloemfontein South-Africa
    Posts
    29
    well i followed the following path...
    Code:
    	while(true) //To Open/make new game.
    	{
    		ifstream Rd("save.dat");
    		if(!Rd)
    		{
    				GameHistory();
    				MakeNewGame();
    				clrscr;
    			break;
    		}
    		Rd>>Name;
    		Rd>>Cash;
    		cout<<"Welcome back "<<Name<<", you have $"<<Cash<<" in your pocket\n";
    		break;
    and then in MakeNewGame
    Code:
    void MakeNewGame()
    {
    	string Name;
    	int Cash;
    	cout<<"What is your name?\n";
    	cin>>Name;
    	Cash=100;
    	ofstream Wrt("save.dat");
    	Wrt<<Name<<'\n';
    	Wrt<<Cash;
    	Wrt.close();
    	cout<<"Thank You "<<Name<<"! Saved game has been created!\n";
    	cout<<"You have $"<<Cash<<" in your pocket.\n";
    }
    And this works quite good...

    Now what i need to know, is this a decemt way to do it, or can anyone reconmend a better way...
    I am trying to keep
    int main()
    {
    ...
    }

    as short as possible
    Feel welcome to visit my web/wapsite at FantasticWap anytime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How does this Game Maker-like c program look
    By hahaguy in forum Game Programming
    Replies: 0
    Last Post: 04-23-2009, 06:32 AM
  2. Replies: 9
    Last Post: 11-11-2007, 02:31 PM
  3. Problems in a game program
    By ChronoSquare in forum C++ Programming
    Replies: 4
    Last Post: 06-08-2006, 07:32 AM
  4. My Memory Game
    By jazy921 in forum C Programming
    Replies: 0
    Last Post: 05-05-2003, 05:13 PM
  5. need help with a guessing game program
    By davidnj732 in forum C++ Programming
    Replies: 3
    Last Post: 04-01-2003, 11:59 AM