473,382 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

C++: unlock somthing

134 100+
how can i make it so for example, at the end of a level in a text-based(C++) RPG, it actives something like a function so it unlocks the next level. such as

at the end of Level One,
Expand|Select|Wrap|Line Numbers
  1. UnlockLevel2
  2.  
then at the other part of my script,
Expand|Select|Wrap|Line Numbers
  1. if(UnlockLevel2)
  2. {
  3. bool Level2();
  4. }
  5.  
I just dont know what to put there.
thank you
Apr 30 '07 #1
5 1806
ilikepython
844 Expert 512MB
how can i make it so for example, at the end of a level in a text-based(C++) RPG, it actives something like a function so it unlocks the next level. such as

at the end of Level One,
Expand|Select|Wrap|Line Numbers
  1. UnlockLevel2
  2.  
then at the other part of my script,
Expand|Select|Wrap|Line Numbers
  1. if(UnlockLevel2)
  2. {
  3. bool Level2();
  4. }
  5.  
I just dont know what to put there.
thank you
You can have an array of bools showing which levels are unlocked:
Expand|Select|Wrap|Line Numbers
  1. bool unlockedlevels[NUM_LEVELS] = {false}; //initialize all to false
  2. ...
  3. ...
  4. if (currentlevel is beaten){
  5.     unlockedlevels[current_level_num - 1] = true;}
  6. ...
  7. ...
  8. if (unlockedlevels[level_number - 1] == true){
  9.     do stuff for that level}
  10.  
Is that what you're looking for?
Apr 30 '07 #2
lumpybanana247
134 100+
You can have an array of bools showing which levels are unlocked:
Expand|Select|Wrap|Line Numbers
  1. bool unlockedlevels[NUM_LEVELS] = {false}; //initialize all to false
  2. ...
  3.   ...
  4. if (currentlevel is beaten){
  5.     unlockedlevels[current_level_num - 1] = true;}
  6.  ...
  7. ...
  8. if (unlockedlevels[level_number - 1] == true){
  9.     do stuff for that level}
  10.  
Is that what you're looking for?

Well, i dont really understand that code, so ill explain more.
Lets just PRETEND that im making a game where you just say what the program tells you to and you win. (i do know there is a simpler format and i know how to do it) but this is what i want it to do.

in one .cpp file,
Expand|Select|Wrap|Line Numbers
  1. #include "Library.h"
  2. bool Main
  3. {
  4.   cout<<"what would you like to do?";
  5.   cout<<"1.Level One";
  6.   if (LevelOneComplete)
  7.      {
  8.      cout<<"2.Level Two";
  9.      }     
  10. }     
  11.  

Then, in another .cpp File (same project)

Expand|Select|Wrap|Line Numbers
  1. #include "Library.h"
  2. bool Level One
  3. {
  4. cout<<"Congrats, you beat level one.
  5. (LevelOneComplete)
  6. }
  7.  
Apr 30 '07 #3
ilikepython
844 Expert 512MB
Well, i dont really understand that code, so ill explain more.
Lets just PRETEND that im making a game where you just say what the program tells you to and you win. (i do know there is a simpler format and i know how to do it) but this is what i want it to do.

in one .cpp file,
Expand|Select|Wrap|Line Numbers
  1. #include "Library.h"
  2. bool Main
  3. {
  4.   cout<<"what would you like to do?";
  5.   cout<<"1.Level One";
  6.   if (LevelOneComplete)
  7.      {
  8.      cout<<"2.Level Two";
  9.      }     
  10. }     
  11.  

Then, in another .cpp File (same project)

Expand|Select|Wrap|Line Numbers
  1. #include "Library.h"
  2. bool Level One
  3. {
  4. cout<<"Congrats, you beat level one.
  5. (LevelOneComplete)
  6. }
  7.  
Ok,
so you want when something happens to complete that level and unlock the next, then run that next level, right?
You can have a bool data type that tells you wether a level is completed or not or a bool that tells wether a level is unlocked or not:
Expand|Select|Wrap|Line Numbers
  1. bool level_one_complete = false;   //beggining of game; level one is not complete
  2. bool level_two_unlocked = false;   //level two not unlocked yet
  3.  
  4. //game passes
  5. //...
  6. //player completes level one
  7.  
  8. level_one_complete = true;     // level one is now completed
  9. level_two_unlocked = true; //level two is unlocked since level one is complete
  10. //somewhere later in game:
  11. if (level_two_unlocked == true){
  12.      //run function for level 2}
  13.  
Does that help, or do you need some more?
Apr 30 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Check out the State Design Pattern.

State is a pattern where each state knows the following state only. This pattern is a way to make a C++ object appear to change its type. Each of the derived classes represent your various states (the levels) of your game.
Apr 30 '07 #5
lumpybanana247
134 100+
Ok,
so you want when something happens to complete that level and unlock the next, then run that next level, right?
You can have a bool data type that tells you wether a level is completed or not or a bool that tells wether a level is unlocked or not:
Expand|Select|Wrap|Line Numbers
  1. bool level_one_complete = false;   //beggining of game; level one is not complete
  2. bool level_two_unlocked = false;   //level two not unlocked yet
  3.  
  4. //game passes
  5. //...
  6. //player completes level one
  7.  
  8. level_one_complete = true;     // level one is now completed
  9. level_two_unlocked = true; //level two is unlocked since level one is complete
  10. //somewhere later in game:
  11. if (level_two_unlocked == true){
  12.      //run function for level 2}
  13.  
Does that help, or do you need some more?



Yes, ilikepython's worked well.
thank you very much
Apr 30 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John | last post by:
I've got multiple threads and processes that write to same file. Before writing all threads / processes first lock part of file and then write to file. If one thread / process locks file, another...
1
by: Shlomo Anglister | last post by:
Hi, How can I unlock stdio streams? There used to be an unlock API, what happened to it? I will appreciate any kind of help. Thanks, Shlomo
1
by: deko | last post by:
Is there a way to unlock a table so a subroutine can complete? frmMain!frm0 has got a lock on a table I need to do stuff with. Error Number 3211: The database engine could not lock table...
2
by: Unlock | last post by:
Greetings, Any expert able to help me to unlock the database at http://www.generate.netfirms.com/cgi-bin/to.cgi?l=res04 You will need to download the database which I have compressed into a...
1
by: M.C | last post by:
Following is a snap-shot of compiler created code when using UEM, use /Fx: struct __EventCriticalSectionStub { void Lock() {} void Unlock() {} }; ....
2
by: Mitch | last post by:
Would anyone have a routine kicking around that would take a users email address and convert it into a string of numbers to use as an unlock code? I am writing an application and would like it to...
3
by: m | last post by:
Hi, I'm running MySQL (5.0.18-nt) on WinXP with latest patches. I've some SQL code that generates an 'ERROR 11' in two different places depending on how the code is submitted. At the moment...
0
by: Petra | last post by:
Hi! I don't know how to handle the following problem: When a User clicks on the detail view of an item, I lock the item in the database. If the user exits with clicking the cancel or ok button...
1
by: Sony Kalkan | last post by:
Hi, I want to unlock the drive programmatically ? is there an api function related to it. For instance, when i run chkdsk with /F parameter, i get "drive in use" error . I want to unlock drive...
2
by: Lidia | last post by:
Anybody has any ideas?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.