|
Hello all
I would like to ask how to make a simple graphics for this txt based rpg I create . I was planning to make some via dark gdk . So my question would be if anyone would like to tell some basic sprite in dark gdk
below here is my game
#include<iostream>
#include<string>
#include<ctime>
#include<cstdlib>
using namespace std;
class player {
int getDamage( );
string getName( );
string getJob( );
public:
string p_name;
string p_job;
int potion;
int manaPotion;
int powerPotion;
int p_lvl;
int p_damage;
int p_magicDamage;
int p_powerDamage;
int p_life;
int p_mana;
int p_power;
int p_xp;
int p_gold;
int p_maxXp;
int p_maxLife;
int p_maxMana;
int p_maxPower;
player ( );
};
player :: player( ){
p_maxLife = 30;
p_lvl = 1;
p_maxXp = 2;
p_xp = 0;
p_gold = 10;
p_name = getName ( );
p_job = getJob ( );
p_life = p_maxLife;
p_damage = getDamage ( );
if ( p_job == "Warrior" ){
p_maxMana = 5;
p_maxPower = 10;
p_magicDamage = 5;
p_powerDamage = 10;
p_mana = p_maxMana;
p_power = p_maxPower;
}else if ( p_job == "Assasin" ){
p_maxMana = 7;
p_maxPower = 7;
p_magicDamage = 7;
p_powerDamage = 7;
p_mana = p_maxMana;
p_power = p_maxPower;
}else{
p_maxMana = 10;
p_maxPower = 5;
p_magicDamage = 10;
p_powerDamage = 5;
p_mana = p_maxMana;
p_power = p_maxPower;
}
}
string player::getName( ) {
system ( "cls" );
cout<<"\tJourney Txt Fighting Game\n\n"
<<"What is your name : ";
string name;
cin>>name;
system ( "pause" );
return name;
}
string player::getJob( ) {
int choice;
do{
system ( "cls" );
cout<<"\tJourney Txt Fighting Game\n\n"
<<"What job do you want :\n"
<<"[ 1 ] - Warrior\n"
<<"[ 2 ] - Assasin\n"
<<"[ 3 ] - Soolsa\n"
<<"Choice : ";
cin>>choice;
} while ( choice < 1 || choice > 3 );
system ( "pause" );
if ( choice == 1 ){
return "Warrior";
}else if ( choice == 2 ){
return "Assasin";
}else{
return "Soolsa";
}
}
int player::getDamage( ) {
srand ( time ( 0 ) );
int damage = rand ( ) % 5 + 1;
return damage;
}
class enemy {
int getDamage ( );
public :
enemy ( );
int e_damage;
int e_life;
int e_maxLife;
};
enemy ::enemy( ){
e_maxLife = 20;
e_life = e_maxLife;
e_damage = getDamage ( );
}
int enemy::getDamage( ) {
int damage;
if ( e_life <= 5 ) {
damage = 10;
}else {
srand ( time ( 0 ) );
damage = rand ( ) % 5 + 1;
}
return damage;
}
player hero;
enemy villain;
void menu ( );
string title ( );
void fight ( );
char switchTurn ( char turn );
int playerMove ( int &heroLife , int &heroDamage , int &enemyLife );
void run ( int &heroLife , int &enemyMaxLife );
int useItems ( int &heroLife , int &potion , int &manaPotion, int &powerPotion , int &mana , int &power );
int attack ( int &heroLife , int &mana , int &power , int &enemyLife );
int enemyMove ( int &heroLife , int enemyDamage );
void displayStatus (int &xp , int &gold , int &maxXp );
void displayHp( );
void shop ( int &gold , int &potion , int &manaPotion , int &powerPotion);
void check ( int &xp , int &maxXp , int &life , int &maxLife , int &mana , int &maxMana , int &power , int &maxPower );
int main ( ) {
menu ( );
cin.ignore ( cin.rdbuf ( ) ->in_avail ( ) + 1 );
return 0;
}
inline string title ( ){
return "\tJourney Txt Fighting Game\n\n";
}
void menu ( ){
int choice;
do {
system ( "cls" );
cout<<title ( )
<<"What do you want to do ? \n"
<<"[ 1 ] - fight an enemy\n"
<<"[ 2 ] - goto a shop\n"
<<"[ 3 ] - display character status\n"
<<"[ 4 ] - exit the game\n"
<<"Choice : ";
cin>>choice;
} while ( choice < 1 || choice > 4 );
switch ( choice ){
case 1 :
cout<<"Your are about to fight now an enemy \n";
system ( "pause" );
fight ( );
break;
case 2 :
cout<<"You are about to go in to a shop now\n";
system ( "pause" );
shop ( hero.p_gold , hero.potion , hero.manaPotion , hero.powerPotion );
break;
case 3 :
cout<<"Character info now loading.....\n";
system ( "pause" );
displayStatus ( hero.p_xp , hero.p_gold , hero.p_maxXp );
break;
case 4:
cout<<"Thanks for playing .......\n";
break;
}
}
void fight ( ){
char playerTurn = 'x';
char enemyTurn = 'o';
char turn = playerTurn;
int life;
int faint = 0;
do {
if ( turn == playerTurn ){
life = playerMove ( hero.p_life , hero.p_damage , villain.e_life );
turn = switchTurn ( turn );
}else {
life = enemyMove ( hero.p_life , villain.e_damage );
turn = switchTurn ( turn );
}
}while ( life > faint );
system ( "cls" );
cout<<title ( );
if ( hero.p_life <= 0 ){
cout<<"GAME OVER YOU HAVE BEEN DEFEATED.....\n"
<<"To play again please restart the game....\n";
system ( "pause" );
}else{
cout<<"CONGRATULATION YOU DEFEAT THE ENEMY......\n"
<<"you have loot 1 gold .\n";
check ( hero.p_xp , hero.p_maxXp , hero.p_life , hero.p_maxLife , hero.p_mana , hero.p_maxMana , hero.p_power , hero.p_maxPower );
villain.e_life = villain.e_maxLife ;
hero.p_gold = hero.p_gold + 1;
system ( "pause" );
menu ( );
}
}
char switchTurn ( char turn ) {
if ( turn == 'x')
return 'o';
else
return 'x';
}
int playerMove ( int &heroLife , int &heroDamage , int &enemyLife ) {
int move;
int life;
do{
system ( "cls" );
displayHp ( );
cout<<"What is your move ?\n"
<<"[ 1 ] - attack the enemy\n"
<<"[ 2 ] - use items\n"
<<"[ 3 ] - run \n"
<<"Choice : ";
cin>>move;
} while ( move < 1 || move > 3 );
switch ( move ) {
case 1 :
life = attack ( hero.p_life , hero.p_mana , hero.p_power , villain.e_life );
return life;
break;
case 2 :
life = useItems ( hero.p_life , hero.potion , hero.manaPotion , hero.powerPotion , hero.p_mana , hero.p_power );
return life;
break;
case 3 :
run ( hero.p_life , villain.e_maxLife );
return life;
break;
}
}
void run ( int &heroLife , int &enemyMaxLife) {
displayHp ( );
cout<<"Escaped safely ....\n";
hero.p_life = heroLife;
villain.e_life = enemyMaxLife;
menu ( );
}
int useItems ( int &heroLife , int &potion , int &manaPotion , int & powerPotion , int &mana , int &power ){
int choice;
do{
system ( "cls" );
cout<<title ( )
<<"Inventory : \n"
<<"[ 1 ] - potion "<<potion<<" pcs\n"
<<"[ 2 ] - mana potion "<<manaPotion<<" pcs\n"
<<"[ 3 ] - power potion "<<powerPotion<<" pcs\n"
<<"What do you want to use : ";
cin>>choice;
} while ( choice < 1 || choice > 3 );
switch ( choice ) {
case 1 :
if ( potion <= 0 ){
cout<<"Sorry out of stock\n";
system ( "pause" );
return heroLife;
}else{
cout<<"You have use a potion\n";
system ( "pause" );
heroLife = heroLife + 10;
potion--;
if ( heroLife > hero.p_maxLife ){
heroLife = hero.p_maxLife ;
return heroLife;
}else{
return heroLife;
}
}
break;
case 2:
if ( manaPotion <= 0 ){
cout<<"Sorry out of stock\n";
system ( "pause" );
return heroLife;
}else{
cout<<"You have use a mana potion\n";
system ( "pause" );
mana = mana + 10;
manaPotion--;
if (mana >hero.p_maxMana ){
mana = hero.p_maxMana ;
return heroLife;
}else{
return heroLife;
}
}
break;
case 3:
if ( powerPotion <= 0 ){
cout<<"Sorry out of stock\n";
system ( "pause" );
return heroLife;
}else{
cout<<"You have use a power potion\n";
system ( "pause" );
power = power + 10;
powerPotion--;
if (power > hero.p_maxPower ){
power = hero.p_maxPower ;
return heroLife;
}else{
return heroLife;
}
}
break;
}
}
int attack ( int & heroLife , int &mana , int &power , int &enemyLife ){
int choice;
do{
system ( "cls" );
cout<<title ( )
<<"what do you want to use ?\n"
<<"[ 1 ] - normal attack\n"
<<"[ 2 ] - magic attack\n"
<<"[ 3 ] - power attack\n"
<<"choice : ";
cin>>choice;
} while ( choice < 1 || choice > 3 );
switch ( choice ) {
case 1 :
cout<<"You have inflicted a normal damage of "<<hero.p_damage <<" to your enemy\n";
system ( "pause" );
enemyLife = enemyLife - hero.p_damage ;
return enemyLife;
break;
case 2 :
if ( mana <= 0 ){
cout<<"Sorry out of mana\n";
system ( "pause" );
return enemyLife;
}else {
cout<<"You have inflicted a magic damage of "<<hero.p_magicDamage <<" to your enemy\n";
system ( "pause" );
mana = mana - 1;
enemyLife = enemyLife - hero.p_magicDamage ;
return enemyLife;
}
break;
case 3:
if ( power <= 0 ){
cout<<"Sorry out of power\n";
system ( "pause" );
return enemyLife;
}else {
cout<<"You have inflicted a power damage of "<<hero.p_powerDamage <<" to your enemy\n";
system ( "pause" );
enemyLife = enemyLife - hero.p_powerDamage ;
power = power - 1;
return enemyLife;
}
break;
}
return enemyLife;
}
int enemyMove ( int &heroLife , int enemyDamage ){
system ( "cls" );
displayHp ( );
cout<<"The enemy inflicted damage of "<<enemyDamage<<" to your life.\n";
heroLife = heroLife - enemyDamage;
system ( "pause" );
return heroLife;
}
void displayStatus ( int &xp , int &gold , int & maxXp ){
system ( "cls" );
cout<<title ( )
<<"Player Status \n"
<<"Player Name : "<<hero.p_name <<endl
<<"Player Job : "<<hero.p_job <<endl
<<"Player lvl : "<<hero.p_lvl <<endl
<<"HP : "<<hero.p_life <<endl
<<"MANA : "<<hero.p_mana <<endl
<<"POWER : "<<hero.p_power <<endl
<<"\ncurrent Gold : "<<gold <<endl
<<"Exp : "<<xp <<endl
<<"Exp to lvl up : "<<maxXp <<endl;
system ( "pause" );
menu ( );
}
void displayHp ( ) {
system ( "cls" );
cout<<title ( )
<<"Player \n"
<<"HP : "<<hero.p_life <<endl
<<"MANA : "<<hero.p_mana <<endl
<<"POWER : "<<hero.p_power <<endl<<endl
<<"Enemy \n"
<<"HP : "<<villain.e_life <<endl<<endl<<endl;
}
void shop ( int &gold , int &potion , int &manaPotion , int &powerPotion ){
system ( "cls" );
int choice;
do {
cout<<title ( )
<<"Current gold : "<<gold<<endl
<<"what do you want to buy ?\n"
<<"[ 1 ] - <potion> restores 10 hp cost 5 gold\n"
<<"[ 2 ] - <mana potion> restores 2 mana cost 5 gold \n"
<<"[ 3 ] - <power potion> restores 2 power cost 5 gold\n"
<<"choice : ";
cin>>choice;
} while ( choice < 1 || choice > 3 );
switch ( choice ) {
case 1 :
if ( gold > 0 ){
cout<<"You have buy a potion.\n"
<<"Thanks for buying.\n";
system ( "pause" );
potion++;
gold = gold - 5;
}else{
cout<<"Insufficient gold.\n";
system ( "pause" );
}
break;
case 2 :
if ( gold > 0 ){
cout<<"You have buy a mana potion.\n"
<<"Thanks for buying.\n";
system ( "pause" );
gold = gold - 5;
manaPotion++;
}else{
cout<<"Insufficient gold.\n";
system ( "pause" );
}
break;
case 3:
if ( gold > 0 ){
cout<<"You have buy a power potion.\n"
<<"Thanks for buying.\n";
system ( "pause" );
gold = gold - 5;
powerPotion++;
}else{
cout<<"Insufficient gold.\n";
system ( "pause" );
}
break;
}
menu ( );
}
void check ( int &xp , int &maxXp , int &life , int &maxLife , int &mana , int &maxMana , int &power , int &maxPower ){
if ( xp >= maxXp ){
system ( "cls" );
cout<<"CONGRATULATION YOU HAVE LVL UP .....\n";
life = life + 1;
maxLife = maxLife + 1 ;
mana = mana + 1;
maxMana = maxMana + 1;
power = power + 1;
maxPower = maxPower + 1 ;
maxXp = maxXp + 2;
}else
xp = xp + 1;
}
Any comments or suggestion to make this game better is kindly appreciated
|
|
|
|
|
I suppose the Collaboration / Testing forum [^] is more appropriate.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
sorry to ask but is it in here also?
|
|
|
|
|
Yes, there's the link to, in my previous answer.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Sorry sir but I am a little confuse ^_^
I am still newbie here in codeproject so I thought its better
to ask a little ^_^
|
|
|
|
|
Click here to gain access to the collaboration / testing forum.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello sir now I post again the game code in the section what you have said ^_^
By the way sir where can i find here some tutorials about the basic of 2d sprite using dark gdk kit for c++
thanks again
|
|
|
|
|
HI all,
I m using System Tray Icon for my application.
i m taking help of this article for system tray icon.
Adding Icons to the System Tray[^]
I m already ask this query to author of article but he not respond me.
please help me for this.
this application works fine on VISTA,but when i run application on XP,its create system tray icon but bot display the ballon.
please help me....
Please provide me any demo application for this
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
modified on Thursday, September 24, 2009 7:16 AM
|
|
|
|
|
See MSDN official sample for System tray (in SDK)
|
|
|
|
|
I am useing VC++ 2008 Service Pack2 OS Microsoft Windows XP.I had create simple Dialog Based application and add a button and Edit box.On Button Click open a folder dialog Box.When i click on Button and select a file name and again click on button then i am getting exception.
Unhandled exception at 0x7ca51646 in test.exe: 0xC0000005: Access violation reading location 0x01064db0.
I debug the code and found when cursor come here then exception
if (dlg.DoModal()==IDOK)
code of ButtonClick
const char szFilters[]="Excel Files|*.xls;*.xlsx|";
CKSFileDialog dlg (TRUE, "xlsx", NULL,OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters,this);
dlg.SetMyParent(this);
if (dlg.DoModal()==IDOK)
{
SetDlgItemText(IDC_EDIT1, dlg.GetPathName());
}
Plz help me
|
|
|
|
|
The end of the filter must have 2 pipe symbols.
const char szFilters[]="Excel Files|*.xls;*.xlsx||";
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
thank for reply but still problem is same.
|
|
|
|
|
Please try without the SetMyParent call.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
i try this but still problem is same.
|
|
|
|
|
Did you override DoModal in your class?
If so, what changes has been done in it.
Generally, what was the reason to derive your own class from CFileDialog ?
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
derive your own class from CFileDialog
i was try this.But in that case also same exception show.
|
|
|
|
|
I'm trying to understand what your class CKSFileDialog does.
Why don't you directly use the CFileDialog class like this -
const char szFilters[]="Excel Files|*.xls;*.xlsx||";
CFileDialog dlg (TRUE, "xlsx", NULL,OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters,this);
if (dlg.DoModal()==IDOK)
{
SetDlgItemText(IDC_EDIT1, dlg.GetPathName());
}
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
i test code given by you but still exception is same.
|
|
|
|
|
|
|
At one time this was a known problem with CFileDialog . I would have thought it to be fixed by VS2008. It has to do with the size of the OPENFILENAME structure. This structure has three extra members if _WIN32_WINNT >= 0x0500. This causes problems because CFileDialog has a OPENFILENAME member, but MFC itself was built with the smaller size. Since the class in your app will not line up with what is in MFC, it crashes. See the first Q&A here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thanks for article.
You have any solution for that problem.
|
|
|
|
|
MsmVc wrote: thanks for article.
Which I just realized was close but not the exact one I meant to post. Sorry about that.
MsmVc wrote: You have any solution for that problem.
Did you see the CFileDialogEx class? Have you considered using GetOpenFileName directly?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
yes i try
CFileDialogEx but nothing change in output.Still i am getting exception.
|
|
|
|
|
I am using automation classes to draw chart through excel from VC
Is there any documetation where i can get the values of the variables to passed to ChartType
Ex I have this code
_Application app;
_Workbook newBook;
Workbooks books;
Worksheets sheets;
_Worksheet newSheet;
Charts charts;
_Chart newChart;
COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//Create Excel server (start Excel)
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Can’t start Excel server!");
return;
}
app.SetVisible(true); //set Excel visible
// app.p.put_UserControl(TRUE); //user can operate Excel
books = app.GetWorkbooks();
newBook=books.Open("d:\\wipro1.csv",vOpt, vOpt, vOpt, vOpt, vOpt,
vOpt, vOpt, vOpt, vOpt, vOpt,vOpt, vOpt,vOpt,vOpt);
sheets = newBook.GetSheets();
newSheet = sheets.GetItem(COleVariant((short)2));
charts = newBook.GetCharts();
newChart = charts.Add(vOpt,vOpt,COleVariant((short)1));
newChart.SetName("My chart");
newChart.SetChartType((long)1);
---------------------------
The above code works fine but what variables should be passed to SetChartType ? which Variable corresponds to which charttype?
Prithaa
|
|
|
|
|