Home > other >  C + + implementation simple RPG game
C + + implementation simple RPG game

Time:09-16

Hello everyone, this is my first game, so there is an error although put forward
I wrote this game is very simple, is a for loop, a few of multiple if statement and the while game
Is it easy? Is, you can point a praise,
After constantly test, I found a few problems, after some modification, the code is as follows:
Is actually added some while and break, and purchase of equipment and restoring the loopholes in the code of life also was modified,
 # include 
using namespace std;
Int main () {
Int shengming=30, gongji=10, jinbi=10, SMSX=30, duobi1=3;
Int a=0, b=0, c=0;
Cout<& lt;" Concept in power, you have been selected to protect people, so you have the following skills: ";
for(int i=0; I<1; I -) {
CoutCout<& lt;" 2. Play zone, "& lt; Cout<& lt;" 3. Personal information, "& lt; Cin> a;
If (a==1) {
While (1) {
CoutCout<& lt;" 1. The weapon of gold & gt;=10 "& lt; Cout<& lt;" 2. 10 gold + full life, "& lt; Cout<& lt;" 3. Life online gold & gt;=40 "& lt; Cout<& lt;" 4. Avoid number + 1 15 COINS "& lt; Cout<& lt;" Press 0 exit, "& lt; Cin> b;
If (b==1 & amp; & Jinbi>=10) {
While (1) {
CoutCout<& lt;" 2. Iron jian - 50 gold + 25 "& lt; Cout<& lt;" 3. The diamond sword - 200 gold + 100 "& lt; Cout<& lt;" 4. The gods sword - 1000 gold + 500 "& lt; Cout<& lt;" 0 exit, "& lt; Cin> c;
If (c==1 & amp; & Jinbi>=10) {
Gongji +=5;
Jinbi -=10;
Cout<& lt;" Attack: "& lt; } else {
Cout<& lt;" Gold is not enough, "& lt; }
}
} else if (b==2 & amp; & Jinbi>=10) {
Shengming=SMSX;
Jinbi -=10;
Cout<& lt;" Life="& lt; } else if (a=b=3 & amp; & Jinbi> 40)={
While (1) {
CoutCout<& lt;" 2. The third - 100 gold + 25 "online life & lt; Cout<& lt;" 3. Life on-line second-class - 400 gold + 100 "& lt; Cout<& lt;" 4. Life online wait - 2000 gold + 500 "& lt; Cout<& lt;" 0 exit, "& lt; Cin> c;
If (c==1) {
SMSX +=10;
Shengming +=10;
Jinbi -=40;
Cout<& lt;" Life online: "& lt; }
}
} else if (b==4 & amp; & Jinbi> 20)={
Duobi1 +=1;
Jinbi -=15;
Cout<& lt;" Avoid number + 1="& lt; {} else if (b==0)
break;
} else {
Cout<& lt;" Gold is not enough, "& lt; }
}
} else if (a==2) {
While (1) {
CoutCout<& lt;" 2. Place big strange - life 100, attacks on 25, may obtain gold 25 "& lt; Cout<& lt;" 3. Small strange life - 400, 100, 100 gold COINS can be obtained "& lt; Cout<& lt;" 4. Big strange life - 1000, 500, 500 gold COINS can be obtained "& lt; Cout<& lt;" 0 exit, "& lt; Cin> b;
If (b==1) {
Int sm=20, gj=10;
Int duobi=duobi1;
CoutWhile (sm> 0 {
CoutCin> c;
If (c==1) {
Shengming -=gj.
Sm -=gongji;
CoutCout<& lt;" The enemy of life: "& lt; } else if (duobi> 0 {
Cout<& lt;" Avoid success, "& lt; Duobi -;
Sm -=5;
Cout<& lt;" The enemy of life: "& lt; return 0;
}
}
Jinbi +=10;
Cout<& lt;" Congratulations you get gold 10 "& lt; } else if (b==2) {
Cout
  • Related