Jump to content


Photo

Wow


  • Please log in to reply
9 replies to this topic

#1 Detail

Detail

    King Detail

  • Hosted
  • 7,767 posts
  • Location:Dayonic
  • Projects:Dayvi.com
  •  Blu Spy

Posted 17 January 2004 - 11:08 PM

You might be better teaching me ;)2

#2 hellfire

hellfire
  • New Members
  • 53 posts

Posted 18 January 2004 - 12:05 AM

Lol now wouldn't that be interesting ur in college, and me teach you. :p Well from what I've read in older posts I seem to be one of the few to understand arrays.(At least enough to be able to use em effectively.) Hmmmm heres a thought I have a couple of sheets to a castle exploration program, we're using in class I can scan it and show let you guys answer questions. It uses a two dimensional array.

#3 Mastermind

Mastermind

    Server Technician

  • Undead
  • 7,014 posts
  • Location:Cambridge, MA
  • Projects:MasterNews 3
  •  The Man Behind the Curtain

Posted 18 January 2004 - 12:10 AM

I know about arrays, and since standard arrays are easy to use, I understand those. At school, we used a special class for arrays and matrices with error checking and such. I've got about 4 months of C++ behind me, so if you need help, feel free to ask.
:p
Posted Image

Well, when it comes to writing an expository essay about counter-insurgent tactics, I'm of the old school. First you tell them how you're going to kill them. Then you kill them. Then you tell them how you just killed them.

Too cute! | Server Status: If you can read this, it's up |

#4 the_kid

the_kid

    L337 Pwnerer of N00bs

  • Project Team
  • 1,734 posts
  • Location:La$ Vega$, NV
  • Projects:freelancing between what interests me
  •  + TRIPLEhelix

Posted 18 January 2004 - 09:40 PM

i've got about 4 week of c++ behind me... and I don't know that much, I hope they teach us c++ in computers next year...

#5 hellfire

hellfire
  • New Members
  • 53 posts

Posted 18 January 2004 - 10:10 PM

Ya it should be easy if some more lessons are posted, I'll also scan in the 6 pages of code for the fortress program tonight, and post em when they're finished.

#6 hellfire

hellfire
  • New Members
  • 53 posts

Posted 22 January 2004 - 12:19 PM

actually what I think it is, is the else, which is within the else there. It doesn't have an IF. Ok well I'll post updates in about 3 hours when I finish my exam.

#7 hellfire

hellfire
  • New Members
  • 53 posts

Posted 21 January 2004 - 05:55 PM

Well I was supposed to post scans but I lost the first page, so now taht I'm at school I decided, I'll post the code, as I can't seem to get it going, but that might be this comps fault. So if anyone can load this in dev and get it working just tell me what was wrong if anything. Also I already know that weapon() isn't called anywhere in the program, so just leave it be for now.


#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>

using namespace std;

void status();
void fight();
void weapon();
int nHealthTotal, nWeapon, nGoldTotal, nXnow, nYnow, nMonster, nGold, nResult, nP, nForce;
int nFortress [6][5];
string szChoices, szMonsterName, szWeapon;
char chDirection;

int main()
{
	
	//Q1: Why do we have an nGoldTotal, and nGold as well?
	//A1: There is an nGoldTotal because this is the total amou nt of gold collected,
	// where nGold is just how much gold is collected when a room is entered or a monster is killed.
  
	//This is the size of the fortress.
	//Q2: How many rooms are in the fortress all together?
	//A2: There are 30 rooms in the fortress.

	//The difference between a string, and a char is a string may have many characters
	//in it and a char cannot. the string symbols are surroundedby double quotes (")
	//the char symbols by single quotes (')

	//Here the main program begins.

	//The following nested loop fills the rooms of the fortress with random numbers

	for (int i=0; i<6; i)
	{
  for (int j=0; j<5; j++)
  {
 	 nMonster=rand()%6+1;
 	 nGold=rand()%6+1;
 	 nResult=nGold-nMonster;
 	 nFortress[i][j]=nResult;
  }
	}
  //nMonster ranges from 1 to 6 as does nGold then nMonster is subtracted from nGold
  
  //Q3: What is the range of values for nresult?
  //A3: The range of values for nResult is 1 - 6

  //Almost all random number generators produce a number between 0 and .9999999
  //Almost all random number generastors produce a number between 0 and .9999999
  //therefore to get a number between on and six some adjustments have to be made.
  
  //Q4: What would be the code to get a number between 1 and 10? 
  //A4:	nMonster=rand()%10+1;
  //  nGold=rand()%10+1;
  //  nResult=nGold-nMonster;
  //  nFortress[i][j]=nResult;


  //We start at the south west door of the castle which is nFortress[0][0]
  //We also initialize many of the other variables such as health and fortune
  //Also to avoid unnecessary warnings from the compiler we give initial values to
  //other things as well.

	nHealthTotal=100;
	nGoldTotal=0;
	nXnow=0;
	nYnow=0;
	szMonsterName="";
	chDirection='q';
	szChoices="";
	szWeapon="";
  //We clear the first room of golld and monsters and initialize all remaining variables
	nFortress[0][0];

  //xNow is the x coordinateat anytime as nYnow is the y coordinate these display
  //the valid choices within the fortress and input the player's move - if the move
  //is outside the walls it is assumed the player has left the castle.

	nXnow=0;
	nYnow=0;
	cout<<"You have entered the Fortress of opportunity!"<<endl;
	cout<<"You see an empty room with with 2 doors."<<endl;
  
  //szChoices will be this be the directions the player can traveland stillremain in the fortress

	while ((nXnow>=0)&&(nXnow<=5)&&(nYnow>=0)&&(nYnow<=4))
	{


  //Q5: Explain the boundaries on this while loop? 
  //A5: The boundries of this loop are set to make sure the player is in the castle.

  //Q6: Rewrite the while loop line below the way it would be if the earlier matrix
  //declaration had been nFortress[10][7]
  //A6: ((nXnow>=0)&&(nXnow<=9)&&(nYnow>=0)&&(nYnow<=6))
 	 
  szChoices="";
  //Here we set the directions of travel backto 'none'
  
  //We will use the conventional x and y system learned in math class
  //therefore 'west' is negative x movement and 'east' is positive x movement
  //likewise 'south' is negative y movement and 'north' is positive y movement

  if (nXnow>0) szChoices+="'W'";

  //Q7: Explain the line above? 
  //A7: This line decides if the player is able to go west without leaving the fortress.

  if (nXnow<5)
  {
 	 if (szChoices!="") szChoices+=" or ";

  //Q8: Explain the line above?
  //A9: This line determines if the player is able to travel east with out leaving the castle
   	 
   	 szChoices+="'E'";
  }
 	 if (nYnow>0)
 	 {
    if (szChoices!="") szChoices+=" or ";
    szChoices+="'S'";
 	 }
 	 if (nYnow<4)
 	 {
    if (szChoices!="") szChoices+=" or ";
    szChoices+="'N'";
 	 }

    cout<<"To stay in the fortress your choices of direction are "<<szChoices<<endl;
    cout<<"Type 'F' to fight or 'R' for a status report"<<endl;

    do
    {
   	 cin>>chDirection;
   	 if ((chDirection=='f')||(chDirection=='F')||(chDirection=='r')||(chDirection=='R'));

   	 else if ((chDirection!='n')&&(chDirection!='N')&&(chDirection!='w')
   	 &&(chDirection!='W')&&(chDirection!='e')&&(chDirection!='E')&&
   	 (chDirection!='s')&&(chDirection!='S'))

   	 cout<<"enter a direction: "<<szChoices<<"!"<<endl;
    }
    while ((chDirection!='n')&&(chDirection!='N')&&(chDirection!='W')&&
    (chDirection!='W')&&(chDirection!='e')&&(chDirection!='E')&&
    (chDirection!='s')&&(chDirection!='S')&&(chDirection!='f')&&
    (chDirection!='F')&&(chDirection!='r')&&(chDirection!='R'));

  //Q9: What is the purpose of the above while loop?
  //Q9: This makes sure that the player inputs a valid direction or command.

    switch(chDirection)
    {
   	 case 'n':;
   	 case 'N':nYnow++;break;
   	 case 's':;
   	 case 'S':nYnow--;break;
   	 case 'e':;
   	 case 'E':nXnow++;break;
   	 case 'w':;
   	 case 'W':nXnow--;break;
   	 case 'r':;
   	 case 'R':status();break;
   	 case 'f':;
   	 case 'F':fight();break;
    }
  //Q10: What is the purpose of the above switch statement?
  //A10: The line determines which room the player moves to
  //next or if the player calls a status screen, or if the player fights a monster
 	 
   	 if ((nXnow<0)||(nXnow>5)||(nYnow<0)||(nYnow>4)) break;

  //Q11: Explain the line above.
  //A11: This tells the game to stop if the player leaves the fortress.
    
   	 nP=nFortress [nXnow][nYnow];//using nP is merely a convenient short form 
   	 if ((chDirection=='F')||(chDirection=='f')||(chDirection=='r')||
   	 (chDirection=='R'));
  
  //This is the bypass if the traveller is merely wishing a report or is already engaged in combat

   	 else if (nP>0)
  //Q12: Explain this line:
  //A12: This shows if a room has gold in it

   	 {
      cout<<"Congrats you found "<<nP<<" gold pieces."<<endl;
      nGoldTotal+=nP;
      nFortress[nXnow][nYnow]=0;
   	 }
   	 else if (nP<0)

  //Q13: Explain this line:
  //A13: This decides if a room has a monster in it

      {
     	 switch(nP)
     	 {
     	 case -1:szMonsterName="Quill Rat";break;
     	 case -2:szMonsterName="Saruman Orc";break;
     	 case -3:szMonsterName="Mordor Uruk-hai";break;
     	 case -4:szMonsterName="Cave Troll";break;
     	 case -5:szMonsterName="Balrog";break;
      }
  
  //Q14: Explain the switch statement above.
  //A14: This switch decides which monster the player fights

      cout<<"A "<<szMonsterName<<"! HeStrikes 'Fight'";
      cout<<" -or just run away nursing "<<endl;
      cout<<"your wounds puny mortal!"<<endl;
      cout<<" "<<endl;
      nHealthTotal+=nP;

  //Q15: Since np is a negative number here, Explain the line nHealthTotal+=nP;
  //A15: This decides how much damage the monster can do when it attacks.
   	 
   	 }
 	 else
 	 {
      cout<<" "<<endl;
      cout<<"You are in an empty room!"<<endl;
      cout<<" "<<endl;
 	 }
 	 chDirection='q';

	}	//This makes sure that the new chioce will have to be made next round.

	
	cout<<"You left the fortress in fear!"<<endl;
	cout<<"Here are your your final statistics puny mortal!"<<endl;
	status();
	cout<<"Good ridance and never return!"<<endl;
	
	return 0;	
}    
//End of main method

  //Here is a method of reporting the fortune and health of the traveller

void status()
{
 	 cout<<" "<<endl;
 	 cout<<"STATUS REPORT"<<endl;
 	 if (nHealthTotal<10)
 	 {
    cout<<"Multiple deep gashes, Bleeding Profusely!";
    cout<<"Balin's tomb has room for one more!"<<endl;
 	 }
 	 else if (nHealthTotal<60)
 	 {
    cout<<"You don't look so good - and your blood";
    cout<<" is making the flor slippery!"<<endl;
    cout<<"Perhaps this whole adventure is too much for you?"<<endl;
 	 }
 	 else if (nHealthTotal<85)
	{
    cout<<"Some bruising already evident, you are winded!!"<<endl;
   	 cout<<"Guess the cheap chain mail wasn't such a good deal after all!"<<endl;
    cout<<" "<<endl;
	}
	cout<<"Your health is now "<<nHealthTotal<<endl;
	cout<<"Your total gold now is "<<nGoldTotal<<endl;
	cout<<" "<<endl;
 	 
    
}
  //Whenever status() is called in the main program it prints the above report.
  
  //Q16: Explain the status routine in your own words.
  //A16: The status routine displays the amount of health 
  //a player has, and the amount of gold the player has collected.
 	 
  //Here is the fight routine played out

void fight()
{
    cout<<" "<<endl;
    cout<<"FIGHT REPORT"<<endl;
    cout<<" "<<endl;
    if (nP==0) cout<<"You are in an empty room silly mortal!"<<endl;

  //Q17: Is a line like the above included just to taunt the player?
  //A17: This line also makes sure the player cannot fight what is not there as well
  //as taunts the player

    else
    {
   	 nForce=rand()%2+1;

  //Q18: What is the highest 'Hit Value' the player can inflict?
  //A18: The highest hit value the player can deal is 2
   	 {
      cout<<"You have killed the monster and claim his treasure!"<<endl;
      nGoldTotal+=rand()%nFortress [nXnow][nYnow]+1;
      nFortress [nXnow][nYnow]=0;
   	 }
   	 else
   	 {
      cout<<"He strikes at you again and wounds you!"<<endl;
      nHealthTotal+=nP*3;
   	 
  //Q19: Explain the line above:
  //A19: This is if the player misses.
   	 }
   	 if (nHealthTotal<10)
   	 {
      cout<<"You desperately need a doctor! - Check your health!"<<endl;
   	 }
   	 else if (nHealthTotal<60)
   	 {
      cout<<"You don't look so good! - "<<endl;
      cout<<"Check your health!"<<endl;
   	 }
   	 else if (nHealthTotal<85)
   	 {
      cout<<"You may want to check your health!"<<endl;
   	 }
    }
    
 	 


  //Q20: The above if and else if statement does not have an 'else' ... why?
  //A20: It has no else, because there is no way that the variable will not fit into one
  // statements.

}
 	 

  //Whenever fight() is called form the main program an attack upon a monster is made. 	 
 	 
void weapon()
{
	cout<<"You have enter the fortress, and see 4 weapons infront of you."<<endl;
	cout<<"You quickly drop your own cheap aluminum sword, and start pondering"<<endl;
	cout<<"which weapon you will take. There is a Long Sword, Axe,"<<endl;
	cout<<"Lance, and a Short Sword."<<endl;
	cout<<"Short Sword = 1"<<endl;
	cout<<"Axe = 2"<<endl;
	cout<<"Lance = 3"<<endl;
	cout<<"Long Sword = 4"<<endl;
	cin>>nWeapon;
	switch (nWeapon)
	{
  case 1: szWeapon+="Short Sword";break;
  case 2: szWeapon+="Axe";break;
  case 3: szWeapon+="Lance";break;
  case 4: szWeapon+="Long Sword";break;
	}
	cout<<"You have selected the "<<szWeapon;
}


#8 Mastermind

Mastermind

    Server Technician

  • Undead
  • 7,014 posts
  • Location:Cambridge, MA
  • Projects:MasterNews 3
  •  The Man Behind the Curtain

Posted 22 January 2004 - 01:57 AM

  if (nP==0) cout<<"You are in an empty room silly mortal!"<<endl;

 //Q17: Is a line like the above included just to taunt the player?
 //A17: This line also makes sure the player cannot fight what is not there as well
 //as taunts the player

   else
   {
    nForce=rand()%2+1;

 //Q18: What is the highest 'Hit Value' the player can inflict?
 //A18: The highest hit value the player can deal is 2
    {
     cout<<"You have killed the monster and claim his treasure!"<<endl;
     nGoldTotal+=rand()%nFortress [nXnow][nYnow]+1;
     nFortress [nXnow][nYnow]=0;
    }
    else
    {
     cout<<"He strikes at you again and wounds you!"<<endl;
     nHealthTotal+=nP*3;
   
 //Q19: Explain the line above:
 //A19: This is if the player misses.
    }
   else
    {
     cout<<"He strikes at you again and wounds you!"<<endl;
     nHealthTotal+=nP*3;
   
 //Q19: Explain the line above:
 //A19: This is if the player misses.
    }
This else clause, repeated, with the context area above it, is the problem. There is no if statement to allow that else statement to be executed.

:\program file\vs\myprojects\hellfire\main.cpp(299) : error C2181: illegal else without matching if

This is the error that MS VC 6.0 spits out.
:p
Posted Image

Well, when it comes to writing an expository essay about counter-insurgent tactics, I'm of the old school. First you tell them how you're going to kill them. Then you kill them. Then you tell them how you just killed them.

Too cute! | Server Status: If you can read this, it's up |

#9 hellfire

hellfire
  • New Members
  • 53 posts

Posted 22 January 2004 - 03:10 AM

Ya I used to get this too, at school. Dunno thats what it showed in the papers. Ok I guess it should be fixable. I'll do it tommorow after school.

#10 the_kid

the_kid

    L337 Pwnerer of N00bs

  • Project Team
  • 1,734 posts
  • Location:La$ Vega$, NV
  • Projects:freelancing between what interests me
  •  + TRIPLEhelix

Posted 22 January 2004 - 05:15 AM

try adding in the squirrly barracks { like this

if (nP==0)
{
cout<<"You are in an empty room silly mortal!"<<endl;
}
//Q17: Is a line like the above included just to taunt the player?
//A17: This line also makes sure the player cannot fight what is not there as well
//as taunts the player
  else
  {
   nForce=rand()%2+1;

//Q18: What is the highest 'Hit Value' the player can inflict?
//A18: The highest hit value the player can deal is 2
   {
    cout<<"You have killed the monster and claim his treasure!"<<endl;
    nGoldTotal+=rand()%nFortress [nXnow][nYnow]+1;
    nFortress [nXnow][nYnow]=0;
   }
   else
   {
    cout<<"He strikes at you again and wounds you!"<<endl;
    nHealthTotal+=nP*3;
  
//Q19: Explain the line above:
//A19: This is if the player misses.
   }

I actually don't have the time to test or even read through the whole thing at the moment... but perhaps I shall some other time, anyway, this is just what I think is the problem, cuz you don't really need the brackets, but I don't think it will hurt you to add them.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users