#include #include #include using namespace std; short def,att,hp,stren,lvl,arm=0,weap=0; unsigned int gold=0, xp; unsigned char game,cas; /*def-defence; att-attack; hp-hit points; lvl-level; arm/or-bonus defence; weap/on-bonus attack; gold-gold; xp-exp points game-0,1,if game is still running; cas=time,used for rand()*/ void lvlup(); void menu1(); void menu3(); int randm(int cis); void battle(); void lvlup() { unsigned char rozdelbody, points; /*rozdelbody-choice for attribute++; points-to increase attributes;*/ points=5; lvl=lvl+1; xp=0; while (points>0) { printf("\nYou have %d points\n",points); printf("1. defence; 2. attack; 3. strength, 4. hp\n"); printf("Your stats: defence: %d, attack: %d, strength: %d, hp: %d\n",def,att,stren,hp); printf("What do you want to increase? \n"); cin >> rozdelbody; switch (rozdelbody) { case '1': def++; break; case '2': att++; break; case '3': stren++; break; case '4': hp=hp+5; break; } points--; } } void menu1() { unsigned char menu,remenu; /*menu-choice in menu; remenu-still in menu?*/ remenu=1; while (remenu==1) { printf("1. New game\n"); printf("2. Load game\n"); printf("3. Help\n"); printf("5. Quit\n"); printf("your choice: "); cin >> menu; switch (menu) { case '1': lvl=1; arm=0; weap=0; gold=0; def=1; att=1; stren=1; hp=15; lvlup(); game=1; remenu=0; break; case '2': { unsigned char times=0; FILE *f; f = fopen("save.txt", "r"); if (!f==0) { fseek(f, -1, SEEK_END); times = getc(f); fseek(f, 0, SEEK_SET); xp = getc(f); lvl = getc(f); def = getc(f); att = getc(f); stren = getc(f); hp = getc(f); weap = getc(f); arm = getc(f); while (times>0) {gold += getc(f);times--;}; gold += getc(f); fclose(f); game=1; remenu=0; printf("\nloaded...\n\n"); printf("stats:\n"); printf("strength: %d, defence: %d, attack: %d, hp: %d\n",stren,def,att,hp); printf("gold %d, xp: %d, lvl: %d\n",gold,xp,lvl); printf("bonuses:\n"); printf("armor: %d, weapon: %d\n\n\n",arm,weap); } else printf("\nfile not found\n\n"); break; } case '3': printf("\n\n\n\nGame Gladiators is 'RPG' for fun, which I do, when I was totally bored...\n"); printf("You are a gladiator, can fight in arena, get exp-levels, increase stats\n"); printf("...buy some stuff and other\n"); printf("Turn based battles...\n"); printf("Its not complete, so its a little bit boring...\n"); printf("...and thats all\n\n\n"); break; case '4': printf("Good bye!"); remenu=0; break; } } } void battle() { char menu,alive,distance,strenp,attp,defp,attbet,defbet,strenbet,x2,statsp,hpfight,hpp; /*menu-choice in menu; alive-both chars still alive?; strenp-opponent's strength; att-opp's attack; defp-opp's defence; att/def/strenbet-help char for battle; x2/statsp-help char for calculate opps' stats; hpfight-hp of player in battle; hpp-hp of opp*/ distance=15; alive=1; /*+++++opponents' stats+++++*/ statsp=rand()%2; x2=randm(5); switch (statsp) { case 0: if (stren-x2<0) strenp=0; else strenp=stren-x2; break; case 1: strenp=stren+x2;break; } statsp=randm(2); x2=randm(5); switch (statsp) { case 0: if (def-x2<0) defp=1; else defp=def-x2; case 1: defp=def+x2;break; } statsp=randm(2); x2=randm(5); switch (statsp) { case 0: if (att-x2<0) attp=1; else attp=att-x2; break; case 1: attp=att+x2;break; } statsp=randm(2); x2=randm(15); switch (statsp) { case 0: if (hp-x2<10) hpp=10; else hpp=hp-x2; break; case 1: hpp=hp+x2;break; } /*+++++fight+++++*/ hpfight=hp; while (alive==1) { printf( "\nyou enemy\n"); printf( "strength: %d strength: %d\n",stren,strenp); printf( "attack: %d attack: %d\n",att,attp); printf( "defence: %d defence:%d \n",def, defp); printf( "hp: %d hp: %d\n",hpfight, hpp); printf( "distance: %d\n\n", distance); printf( "1. go to him\n"); printf( "2. go away from him\n"); printf( "3. attack\n"); printf( "4. wait\n"); cin >> menu; switch (menu) { case '1': if (distance>0) { distance=distance-5; printf("You gone to him"); } break; case '2': distance=distance+5; printf("Away"); break; case '3': if (distance<5) { attbet=att+(randm(6))+1+weap; defbet=defp+(randm(6))+1; if (attbet>defbet) { strenbet=stren-randm(3); x2=rand()%3; if (stren-x2>0) { strenbet=stren-x2; hpp=hpp-strenbet; printf( "You hit him for %d hp",strenbet); } } else printf("You missed"); } else printf("You're to far away"); break; case '4': printf("You're waiting");break; } printf("\n\nOpponent's turn...\n\n"); if (distance<5) { defbet=attp+randm(6)+1; defbet=def+randm(6)+1+arm; if (attbet>defbet) { x2=randm(5); if (strenp-x2>0) strenbet=strenp-x2; else strenbet=strenp; hpfight=hpfight-strenbet; printf("He hit you for %d hp \n",strenbet); } else printf("He missed\n"); } else { statsp=randm(2); switch (statsp) { case 0: printf("To you\n"); distance=distance-5; break; case 1: printf("He's waiting\n"); break; } } if (hpfight<=0) { alive=0; game=0; printf("You loose!\nLet's quit the game"); } if (hpp<=0) { alive=0; xp=xp+500; gold=gold+(randm(200)+200); printf( "You won! Added 500 exp\n Your gold is %d \n",gold); if (xp>=500*lvl) { lvlup(); } } } } int randm(int cis) { srand(cas); if (cas>254) cas=0; else cas++; return rand() % cis; } int main() { char menu,offer; /*menu-choice in menu; offer-choice in shop*/ srand((unsigned)time(NULL)); cas=rand()%254; game==0; menu1(); while (game==1) { printf("\n\nYou're in town\n"); printf("What do you want to do??\n"); printf("1. battle\n"); printf("2. buy weapon\n"); printf("3. buy armor\n"); printf("4. save and quit\n"); cin >> menu; switch (menu) { case '1': battle();break; case '2': printf("Offer:"); printf("1.staff+1; 2.hammer+2; 3.sword+3; 4.two-handed sword+4; 5.bread!+5;\n\n"); cin >> offer; if (gold>=offer*500) { weap=offer; gold=gold-(offer*500); printf("You got it, attack +%d", weap); } else printf("No money, no funny"); break; case '3': printf("Offer:"); printf("1.shirt+1; 2.leather +2; 3.copper +3; 4.plate+4; 5.power+5;\n\n"); cin >> offer; if (gold>=offer*500) { arm=offer; gold=gold-(offer*500); printf("You got it, defence +%d", arm); } else printf("No money, no funny"); break; case '4': unsigned char times=0; FILE *f; f = fopen("save.txt","w"); if (!f==0) { putc(xp,f); putc(lvl,f); putc(def,f); putc(att,f); putc(stren,f); putc(hp,f); putc(weap,f); putc(arm,f); while (gold>255) {times++;putc(255,f);gold=gold-255;} putc(gold,f); putc(times,f); fclose(f); } game=0; break; } } return 0; }