Jump to content
  • Advertisement
Sign in to follow this  
jordi_0071

Demo V1.00 CodeCracker

This topic is 4705 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey, i finnaly made a playable game. its still a demo but im working on the full version. I was wondering if you guys could rate it and give some advice on my code style(the code is not that good:P) etc? anyway here is my code:
///////////////////////////////////////////////////////////////////////////////////////////////////
//autor: jordi_0071
//project started: 01-09-2005
//copyright: jordi_0071
//demo version: V1.00
// This is a code of a my CodeCracker game this is a demo of the full game. You have to guess the
// code to open the first gate and to go to the next level.
// Graphics in demo version V2.00
//
// Enjoy!!
////////////////////////////////////////////////////////////////////////////////////////////////// 
#include <iostream>
#include <time.h>
using namespace std;

int main()
{
    int Ir, Ir2, Ir3, Ir4, Ir5, Id1, Id2, Id3, Id4, Id5;
    
    srand ( time(NULL) );
    
    Ir = rand()%9;
    Ir2 = rand()%9;
    Ir3 = rand()%9;
    Ir4 = rand()%9;
    Ir5 = rand()%9;

    
    cout << "CodeCracker Demo Version\n\n " << endl;
    
    cout << "You will got to see five dots. You have to crack(guess) the code to open\n";
    
    cout << "the gate to the next level.\n\n\n\n\n\t\t\tGood Luck!!";
    
    cout << "\n\n\n\n\n\n\t\t\tpress enter to continue...";
    
    cin.get();
    
    system("cls");
    
    cout << ". . . . .\n\n";
    
    cout << "Enter the first number: ";
    
    cin >> Id1;
    
    do
    {                
           cout << "\n";
           
           cout << ". . . . ." << endl;
           
           cout << "Enter the first number: ";
           
             cin >> Id1;
    }
    while(Id1 != Ir);
    
    if(Id1 == Ir)
    {
           cout << "\nYou guessed the first number of the code!" << endl;   
           
           cout << Id1 << " . . . ." << endl; 
    }
    
            cout << "Enter the second number: ";
    
           cin >> Id2;     
 
    
    do
    {
           cout << "\n";
        
           cout << Id1 << " . . . ." << endl;    
        
           cout << "Enter the second number: ";
        
           cin >> Id2;     
    
    }
    while(Id2 !=  Ir2);
    
    if(Id2 == Ir2)
    {
           cout << "You guessed the second number of the code!" << endl;
           
           cout << Id1 << " " << Id2 << " . . ." << endl;
    
    }
    
      cout << "Enter the third number: ";
           
      cin >> Id3;
    
    do
    {
           cout << "\n";
           
            cout << Id1 << " " << Id2 << " . . ." << endl;
           
           cout << "Enter the third number: ";
           
           cin >> Id3;           
}
while(Id3 != Ir3);

if(Id3 == Ir3);
{
       cout << "You guessed the third number of the code!" << endl;
       
       cout << Id1 << " " << Id2 << " " << Id3 << " . ." << endl;
       
}

       cout << "Enter the fourth number: ";
       
       cin >> Id4;

    do
    {
           cout << "\n";
           
            cout << Id1 << " " << Id2  << " " << Id3 << " . ." << endl;
           
           cout << "Enter the fourth number: ";
           
           cin >> Id4;           
}
while(Id4 != Ir4);

if(Id4 == Ir4)
{
       cout << "You guessed the fourth number of the code!" << endl;
       
       cout << Id1 << " " << Id2 << " " << Id3 << " " << Id4 << " ." << endl;
       
       cout << "Enter the fifth number: ";
       
       cin >> Id5;
}

do
{
       cout << "\n";
       
       cout << Id1 << " " << Id2 << " " << Id3 << " " << Id4 << " ." << endl;
       
       cout << "Enter the fifth number: ";
       
       cin >> Id5;
}
while(Id5 != Ir5);

if(Id5 == Ir5)
{
       system("cls");
       
        cout << Id1 << " " << Id2 << " " << Id3 << " " << Id4 << " " << Id5 << endl;
        
}
        
     cout << "\n\n\n\n\n\t\t\t\tYOU CRACKED THE CODE!!";
     
     cout << "\n\n\n\n\nThis is the end of the demo. Full version is soon available...\n\n\n";
     
     cout << "Press Enter to Quit the demo.";    
       
cin.get();
cin.get();

 
    
    return 0;
}


[Edited by - jordi_0071 on September 2, 2005 10:16:20 AM]

Share this post


Link to post
Share on other sites
Advertisement
Not bad for a first playable game!

As a next step, learn about arrays (or better yet std::vectors) and try to implement them in your game. You could make the code much more consise that way.

By the way, all of your "if" statements do nothing :).

Share this post


Link to post
Share on other sites
The next stage for you would be to start refactoring the code, breaking the checking of a code digit logic into a separate function:-

bool check_code( std::vector<int> const &a_code, int a_digit_place, int a_number )
{
if (a_digit_place) >= a_code.size()) return false;
return (a_code[a_digit_place] == a_number);
}

This function would check an arbitrary place in the code for the digit entered by the user (remember to bounds check). You might also wish to start looking at arrays instead of storing the numbers as separate variables.

For example, Ir, Ir2, Ir3, Ir4, Ir5 could just as easily be stored in an array as: int Ir[6]; As the previous poster said, you may also wish to start looking at std::vector as it'll help you control your arrays.

Once you've taken this step, you're free to start making codes of arbitrary lengths:-

void generate_code( std::vector<int> &a_code, int a_num_digits )
{
a_code.clear(); // wipe out the old code
for (int i = 0; i < a_num_digits; ++i)
a_code.push_back( rand()%9 );
}


But I don't want to confuse you ;)

Keep plugging away :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!