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,
then at the other part of my script, -
if(UnlockLevel2)
-
{
-
bool Level2();
-
}
-
I just dont know what to put there.
thank you
5 1806
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,
then at the other part of my script, -
if(UnlockLevel2)
-
{
-
bool Level2();
-
}
-
I just dont know what to put there.
thank you
You can have an array of bools showing which levels are unlocked: -
bool unlockedlevels[NUM_LEVELS] = {false}; //initialize all to false
-
...
-
...
-
if (currentlevel is beaten){
-
unlockedlevels[current_level_num - 1] = true;}
-
...
-
...
-
if (unlockedlevels[level_number - 1] == true){
-
do stuff for that level}
-
Is that what you're looking for?
You can have an array of bools showing which levels are unlocked: -
bool unlockedlevels[NUM_LEVELS] = {false}; //initialize all to false
-
...
-
...
-
if (currentlevel is beaten){
-
unlockedlevels[current_level_num - 1] = true;}
-
...
-
...
-
if (unlockedlevels[level_number - 1] == true){
-
do stuff for that level}
-
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, -
#include "Library.h"
-
bool Main
-
{
-
cout<<"what would you like to do?";
-
cout<<"1.Level One";
-
if (LevelOneComplete)
-
{
-
cout<<"2.Level Two";
-
}
-
}
-
Then, in another .cpp File (same project) -
#include "Library.h"
-
bool Level One
-
{
-
cout<<"Congrats, you beat level one.
-
(LevelOneComplete)
-
}
-
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, -
#include "Library.h"
-
bool Main
-
{
-
cout<<"what would you like to do?";
-
cout<<"1.Level One";
-
if (LevelOneComplete)
-
{
-
cout<<"2.Level Two";
-
}
-
}
-
Then, in another .cpp File (same project) -
#include "Library.h"
-
bool Level One
-
{
-
cout<<"Congrats, you beat level one.
-
(LevelOneComplete)
-
}
-
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: -
bool level_one_complete = false; //beggining of game; level one is not complete
-
bool level_two_unlocked = false; //level two not unlocked yet
-
-
//game passes
-
//...
-
//player completes level one
-
-
level_one_complete = true; // level one is now completed
-
level_two_unlocked = true; //level two is unlocked since level one is complete
-
//somewhere later in game:
-
if (level_two_unlocked == true){
-
//run function for level 2}
-
Does that help, or do you need some more?
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.
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: -
bool level_one_complete = false; //beggining of game; level one is not complete
-
bool level_two_unlocked = false; //level two not unlocked yet
-
-
//game passes
-
//...
-
//player completes level one
-
-
level_one_complete = true; // level one is now completed
-
level_two_unlocked = true; //level two is unlocked since level one is complete
-
//somewhere later in game:
-
if (level_two_unlocked == true){
-
//run function for level 2}
-
Does that help, or do you need some more?
Yes, ilikepython's worked well.
thank you very much
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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...
|
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...
|
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() {}
};
....
|
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...
|
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...
|
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...
|
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...
|
by: Lidia |
last post by:
Anybody has any ideas?
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |