![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You also have a rather obvious problem here:
int main(){
while (1 == 1) {
string name;
int ready;
int option;
int money;
int enemydmg;
int yourdmg;
srand ( time(NULL) );
enemydmg = rand() % 10 + 1;
yourdmg = rand() % 10 + 1;
//Opening
cout << "Hello there! What's your name?: \n";
getline (cin, name);
cout << "Welcome,";
cout << name;
cout << " , to Mage Wars! We are in a world of need, and we are hoping a true";
cout << "hero like you would help us! Please! Destroy the evil mages! \n\n";
cout << "Are you ready? 1: Yes 2: No \n";
cin >> ready;
} else if(ready == 2){
cout << "Come back when you are ready!";
} else {
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#12 |
|
Programmer
Join Date: Jul 2005
Posts: 66
Rep Power: 4
![]() |
Thanks guys, all is going well, but I have a question...
//attack one
if (enemyhealth <= 0)
{
cout << "You have slain the vile enemy! You now gain 10 gold!";
money = money + 10;
}
else if (yourhealth > 0)
{
cout << "Enemy attacks you with " << enemydmg << " damage! You attack back: \n" ;
yourhealth = yourhealth - enemydmg;
cout << "You deal " << yourdmg << " damage! \n";
enemyhealth = enemyhealth - yourdmg;
cout << "Your health is " << yourhealth << ". The enemy's health is" << enemyhealth << ". \n";
}
else
{
cout << "You have died in the mists of battle! I am sorry! The enemy steals 10 gold!";
money = money - 10;
}
//end attack oneThanks! |
|
|
|
|
|
#13 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You also need to pay attention to your responses, and to pursue a logical design. I can copy and paste the works of old masters twelve jillion times, but that does not make me an artist. Shit, it doesn't make me successful, either, unless I really luck out. Now, if you'll excuse me, I'll go play the lottery, where the odds against are only lebenty-four quadrillion to one.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#14 |
|
Programmer
Join Date: Jul 2005
Posts: 66
Rep Power: 4
![]() |
I've been paying attention...
And I've fixed what is told to be fixed. Like I said, no errors, no bugs.. just this problem. |
|
|
|
|
|
#15 |
|
Professional Programmer
|
Why would you copy and paste ten times?
Why not use: while ( yourhealth > 0 && enemyhealth > 0 )
{
...
}
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#16 | |
|
Programmer
Join Date: Jul 2005
Posts: 66
Rep Power: 4
![]() |
Quote:
![]() I mean yeah, that would help dramatacly, I'm just trying to get this thing to work... I need something that returns you back to the main menu or wherever the "while (1 == 1) {" is. Arnack |
|
|
|
|
|
|
#17 |
|
Expert Programmer
|
Perhaps the continue keyword is what you are looking for:
while (1) {
...
if (time_to_start_over)
continue; // skip to the next iteration of the while loop
...
} |
|
|
|
|
|
#18 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
while ( 1 == 1 ) is equivelent to while ( true ) or, in C, while ( 1 )
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#19 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Okay, here's the deal. You need to design your program. That's language independent.
You need to decide, logically, what it's going to do. You need to describe that in high-level (abstract) terms. You then need to break it down. Divide and conquer. The breakdown needs to be in abstract terms. Then you need to take those human-oriented expressions and implement them in your language of choice. Copying someone else's code, even if you luck out and get it to "work", is not the same thing as being a programmer. A Xerox machine can do that, but not many people would depend on a Xerox machine to guarantee their bottom line. Everyone I ever met was a newbie when they started. Decide what you're going to do. Design it. The language is just a tool for ultimate execution. When you pick the tool, try to learn the basics ('else' doesn't fly without an 'if'). When you have problems, post here. Help is readily forthcoming for those who are actually trying. (Glad you pointed that out, Jesse, my post #11 was probably not read in its entirety.)
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#20 |
|
Programmer
Join Date: Jul 2005
Posts: 66
Rep Power: 4
![]() |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
//"Mage Wars" copyright Crimson Games 2007. All rights reserved.
//Created by Arnack, distributing this source is permited, as long
//as ownership is shown.
using namespace std;
int main(){
string name;
int ready;
int option;
int money;
int enemydmg;
int yourdmg;
int weapon;
int yourhealth;
yourhealth=50;
int enemyhealth;
enemyhealth=50;
srand ( time(NULL) );
enemydmg = rand() % 10 + 1;
yourdmg = rand() % 10 + 1;
money = 10;
weapon = 1;
//Opening
cout << "\n \n Hello there! What's your name?: \n";
getline (cin, name);
cout << "Welcome,";
cout << name;
cout << " , to Mage Wars! We are in a world of need, and we are hoping a true";
cout << "hero like you would help us! Please! Destroy the evil mages! \n\n";
cout << "Are you ready? 1: Yes 2: No \n";
cin >> ready;
while ( true ) {
if (ready == 1){
//Main Game Starts Here
cout << "\n What would you like to do? \n";
cout << "1) Kill some evil mages! \n";
cout << "2) Buy some stuff! \n";
cout << "3) Check my status! \n";
cin >> option;
if (option == 1){
//attack sequence
while (5 == 5) {
//attack one
if (enemyhealth <= 0)
{
cout << "You have slain the vile enemy! You now gain 10 gold!\n\n";
money = money + 10;
break;
}
else if (yourhealth > 0)
{
cout << "Enemy attacks you with " << enemydmg << " damage! You attack back: \n" ;
yourhealth = yourhealth - enemydmg;
cout << "You deal " << yourdmg << " damage! \n";
enemyhealth = enemyhealth - yourdmg;
cout << "Your health is " << yourhealth << ". The enemy's health is " << enemyhealth << ". \n";
}
else if (yourhealth <= 0)
{
cout << "You have died in the mists of battle! I am sorry! The enemy steals 10 gold! \n\n";
money = money - 10;
break;
}
//end attack one
}
} else if(option == 2){
int option2;
cout << "So you would like to buy some weapons? \n";
cout << "1) Level 3 Weapon: Flaming Sceptor. 20 gold. \n";
cout << "2) Level 5 Weapon: Crystol Wand. 40 gold. \n";
cout << "3) Level 10 Weapon: Stave of Mages. 100 gold. \n";
cin >> option2;
if (option2 == 1){
money = money - 20;
weapon = weapon + 2;
yourdmg = rand() % 15 + 1;
cout << "You have purchased the item. You now do 0-15 damage.\n" ;
}
} else if(option == 3){
cout << "\n You have " << money << " gold. Your weapon level is " << weapon << ". Have a nice day.";
} else {
cout << "Wrong reply!";
}
//END What would you like to do
system("PAUSE");
}
}
}1) When I engage in a battle all it only produces a random number ONCE and uses it the whole battle. So I only attack for 5 dmg or whatever, it's suppose to be random each time. 2) When I complete a battle, it brings me back to the 3 options. If I want to battle again, it won' let me. It just won't do anything. 3) I am not done with the weapon selection, but from the test I made... I can't seem to do a good job with the money and buying weapons. Someone with no money could buy any weapon they want, and I tried putting up else ifs "You have no money!" but it wouldn't work. THANKS! Arnack BTW: I've tried what was said on this forum, I just can't get to it -.- |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A simple programming question | punter | C# | 8 | Jan 5th, 2006 4:04 PM |
| A simple question | Master | C++ | 9 | Dec 24th, 2005 2:20 PM |
| Question about multidimensional arrays of strings | aznluvsmc | C | 8 | Oct 15th, 2005 10:20 PM |
| Simple c# question | nez | C# | 8 | Jul 1st, 2005 6:29 PM |
| Simple (stupid cause I don't know it) basic question | massive-war | C++ | 17 | Apr 11th, 2005 11:03 PM |