Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include <iostream> #include <conio.h> #include <stdlib.h> #include <time.h> #include <windows.h> using namespace std; int main() { int enemyHP = 100; int yourHP = 100; int enemyNRG = 40; //NRG stands for energy int yourNRG = 40; srand(time(NULL)); int normalDMG = rand() % 9 + 1; int specialDMG = rand() % 15 + 5; int enemyrandomattack = rand() % 4 + 1; // random enemy action int input, n = 0; int enemyDodge = 0; int yourDodge = 0; int action; int runenemyattack = 1; enum actions { Attack = 1, SpecialAttack = 2, Heal = 3, Dodge = 4, Recharge = 5, }; cout << "Welcome!" << endl; cout << "Press 1 for a normal attack (80% chance of hitting 1 - 10)" << endl; cout << "Press 2 for a special attack (50% chance of hitting 5 - 20)" << endl; cout << "Press 3 to use half of you current energy to heal for that amount" << endl; cout << "Press 4 to decrease the chance of the enemy hitting you by 30% next turn (decreases your energy regeneration by 50% this turn)" << endl; cout << "Press 5 to recharge your energy 4 times the rate but the enemy has a 10% higher chance of hitting you this turn" << endl << endl << endl; do { int HEALING = 0; // Lets the player to heal first and not use up the turn do { input = _getch() - '0'; switch (input) { case Attack: if (enemyDodge == 0) // if the enemy did not prepare to dodge the player's creature will deal normal damage providing it does not miss { if (yourNRG < 40) { yourNRG = (yourNRG + 10); if (yourNRG > 40) { yourNRG = 40; } } action = rand() % 9 + 1; if (action > 2) // the player has an 80% chance of hitting { normalDMG = rand() % 9 + 1; enemyHP -= normalDMG; cout << "You used a normal attack and did " << normalDMG << " damage!" << endl; HEALING = 2; break; } else { cout << "The player tried using a normal attack but missed!" << endl; HEALING = 2; break; } } if (enemyDodge == 1) // if the enemy dodged then the player will have an extra 30% chance of missing { if (yourNRG < 40) { yourNRG = (yourNRG + 10); if (yourNRG > 40) { yourNRG = 40; } enemyDodge = 0; // uses up the enemy's dodge action = rand() % 9 + 1; if (action > 5) // 50% chance of the player hitting a normal attack due to the enemy dodging { normalDMG = rand() % 9 + 1; enemyHP -= normalDMG; cout << "You used normal attack and did " << normalDMG << " damage!" << endl; HEALING = 2; break; } else { cout << "The player tried using a normal attack but missed!" << endl; HEALING = 2; break; } } break; } case SpecialAttack: if (yourNRG < 40) { cout << "You do not have enough energy to use a special attack!" << endl; HEALING = 0; break; } if (yourNRG == 40) { if (enemyDodge == 0) // if the enemy did not prepare to dodge the player's creature will deal normal damage providing it does not miss { if (rand() % 9 + 1 > 5) // the player has a 50% chance of hitting { enemyHP -= specialDMG; cout << "You used a special attack and did " << specialDMG << " damage!" << endl; yourNRG = 10; // uses up 40 energy and then adds 10 at the end of the turn (saves lines of code) (40-40+10) HEALING = 2; break; } else { cout << "The player tried using a special attack but missed!" << endl; yourNRG = 10; HEALING = 2; break; } } if (enemyDodge == 1) // if the enemy dodged then the player will have an extra 30% chance of missing { enemyDodge = 0; // uses up the enemy's dodge if (rand() % 9 + 1 > 8) // 20% chance of the player hitting a special attack due to the enemy dodging { enemyHP -= specialDMG; cout << "You used a special attack and did " << specialDMG << " damage!" << endl; yourNRG = 10; HEALING = 2; break; } else { cout << "The player tried using a special attack but missed!" << endl; yourNRG = 10; HEALING = 2; break; } } } case Heal: if (HEALING == 0) // only lets the player heal as his first action and not use up the turn { yourHP += (yourNRG / 2); if (yourHP >= 100) { yourHP = 100; } cout << "Your creature healed itself and now has " << yourHP << " HP" << endl; HEALING++; //stops the player from healing twice in one turn, because HEALING will no longer be == 0 break; } case Dodge: yourDodge = 1; if (yourNRG < 40) { yourNRG = (yourNRG + 5); // gains 5 instead of 10 because the energy gained per turn is halved by using dodge that turn if (yourNRG > 40) { yourNRG = 40; // does not let the player's energy exceed 40 } } cout << "Your creature gets ready to evade the enemy" << endl; HEALING = 2; break; case Recharge: yourNRG = 40; cout << "Your creature recharged it's energy" << endl; HEALING = 2; break; default: cout << "Unknown action try 1-5" << endl; HEALING = 1; break; } } while (HEALING != 2); // The player's turn ends once he uses an action other than heal // The lines below are the enemy's actions enemyrandomattack = rand() % 4 + 1; // generates a random enemy action if (runenemyattack = 1) { if (enemyrandomattack == 1) // if the number one is randomly generated the enemy then does a normal attack { if (enemyNRG < 40) { enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10 if (enemyNRG > 40) { enemyNRG = 40; //does not let the enemy exceed 40 energy } } if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss { action = rand() % 9 + 1; if (action > 2) // the enemy has an 80% chance of hitting { normalDMG = rand() % 9 + 1; yourHP -= normalDMG; cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } else { cout << "The enemy tried using a normal attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing { yourDodge = 0; // uses up players dodge action = rand() % 9 + 1; if (action > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging { normalDMG = rand() % 9 + 1; yourHP -= normalDMG; cout << "The enemy used a normal attack and did" << normalDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } else { cout << "The enemy tried using a normal attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } } if (enemyrandomattack == 2 && enemyNRG < 40) // if a special attack action is generated and the enemy does not have max energy the enemy will then recharge instead { enemyNRG = 40; cout << "The enemy decided to rest for a turn and fully regenerated it's energy" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } if (enemyrandomattack == 2 && enemyNRG == 40) // enemy special attack { if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal special damage providing it does not miss { if (rand() % 9 + 1 > 5) // the enemy has a 50% chance of hitting { yourHP -= specialDMG; cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; enemyNRG = 10; // energy gained at the end of the turn } else { enemyNRG = 10; // 10 energy gained at the end of the turn (0 + 10) cout << "The enemy tried using a special attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing { yourDodge = 0; // uses up players dodge if (rand() % 9 + 1 > 8) // 80% chance of the enemy missing a special attack due to the player dodging { yourHP -= specialDMG; cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; enemyNRG = 5; // player uses up the 40 energy and has 0 but at the end of the turn the enemy gains 5 so I just set it to 5 here to cut lines of code } else { cout << "The enemy tried using a special attack but missed because of your creatures swift moves!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } } if (enemyrandomattack == 3 && enemyHP == 100) // if the enemy already had max hp and rolled the heal action he will then attack instead { if (enemyNRG < 40) { enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10 if (enemyNRG > 40) { enemyNRG = 40; //does not let the enemy exceed 40 energy } } if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss { if (rand() % 9 + 1 > 2) // the enemy has an 80% chance of hitting { yourHP -= normalDMG; cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } else { cout << "The enemy tried using a normal attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing { yourDodge = 0; // uses up players dodge if (enemyNRG < 40) { enemyNRG = (enemyNRG + 5); // enemy gains 5 energy at the end of the turn because the player dodged and the energy gain is halved } if (rand() % 9 + 1 > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging { yourHP -= normalDMG; cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } else { cout << "The enemy tried using a normal attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } } if (enemyrandomattack == 3 && enemyHP < 100) // enemy heal { enemyHP = enemyHP + (enemyNRG / 2); enemyNRG = (enemyNRG / 2); if (enemyHP > 100) { enemyHP = 100; } cout << "The enemy decided to heal!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } if (enemyrandomattack == 4 && enemyDodge == 1) // if the enemy rolls a dodge action and already had dodge it will then use a normal attack { if (enemyNRG < 40) { enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10 if (enemyNRG > 40) { enemyNRG = 40; // if the enemy exceeds 40 energy then it sets it at 40 } } if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss { if (rand() % 9 + 1 > 2) // the enemy has an 80% chance of hitting { yourHP -= normalDMG; cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } else { cout << "The enemy tried using a normal attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing { yourDodge = 2; // uses up players dodge if (enemyNRG < 40) { enemyNRG = (enemyNRG + 5); // enemy gains 5 energy at the end of the turn because the player dodged and the energy gain is halved if (enemyNRG > 40) { enemyNRG = 40; } } if (rand() % 9 + 1 > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging { yourHP -= normalDMG; cout << "The enemy used a normal attack and did" << normalDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } else { cout << "The enemy tried using a normal attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } if (enemyrandomattack == 4 && enemyDodge != 1) // the enemy will dodge if he doesn't have dodge already { enemyDodge = 1; if (enemyNRG < 40) { enemyNRG = (enemyNRG + 5); // enemy gains 5 energy at the end of the turn because the player dodged and the energy gain is halved if (enemyNRG > 40) { enemyNRG = 40; } } cout << "The enemy decided to dodge the next attack!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } if (enemyrandomattack == 5) // enemy recharge { if (enemyNRG < 40) { enemyNRG = 40; cout << "The enemy rests for a turn and regenerates it's energy... " << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } if (enemyNRG == 40) // if the enemy generates this action and already has max energy he will then use a special attack instead { if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal special damage providing it does not miss { if (rand() % 9 + 1 > 5) // the enemy has a 50% chance of hitting { yourHP -= specialDMG; cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; enemyNRG = 10; // energy gained at the end of the turn } else { enemyNRG = 10; // 10 energy gained at the end of the turn (0 + 10) cout << "The enemy tried using a special attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing { yourDodge = 0; // uses up players dodge if (rand() % 9 + 1 > 8) // 80% chance of the enemy missing a special attack due to the player dodging { yourHP -= specialDMG; cout << "The enemy used a special attack and did " << specialDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; enemyNRG = 5; // player uses up the 40 energy and has 0 but at the end of the turn the enemy gains 5 so I just set it to 5 here to cut lines of code } else { cout << "The enemy tried using a special attack but missed because of your creatures swift moves!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } } } } else { if (enemyNRG < 40) { enemyNRG = (enemyNRG + 10); // if the enemy has less than 40 energy it then gains 10 if (enemyNRG > 40) { enemyNRG = 40; //does not let the enemy exceed 40 energy } } if (yourDodge == 0) // if the player did not prepare to dodge the enemy will deal normal damage providing it does not miss { action = rand() % 9 + 1; if (action > 2) // the enemy has an 80% chance of hitting { normalDMG = rand() % 9 + 1; yourHP -= normalDMG; cout << "The enemy used a normal attack and did " << normalDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } else { cout << "The enemy tried using a normal attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } if (yourDodge == 1) // if the player dodged then the enemy will have an extra 30% chance of missing { yourDodge = 0; // uses up players dodge action = rand() % 9 + 1; if (action > 5) // 50% chance of the enemy hitting a normal attack due to the player dodging { normalDMG = rand() % 9 + 1; yourHP -= normalDMG; cout << "The enemy used a normal attack and did" << normalDMG << " damage!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } else { cout << "The enemy tried using a normal attack but missed!" << endl; cout << "Your creature has " << yourHP << " HP and " << yourNRG << " energy and the enemy has " << enemyHP << " HP and " << enemyNRG << " energy" << endl << endl << endl; } } } } while (enemyHP > 0 && yourHP > 0); // the program runs while both creatures are alive if (enemyHP <= 0) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE); cout << "Congratulations, your creature won!!!"; } if (yourHP <= 0) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); cout << "Your creature died and the enemy ate you..."; } cin.clear(); cin.ignore(); _getch(); return 0; }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
F-Formula
2 hours ago | 1.23 KB
SEEING GOD IN THE MATH
3 hours ago | 0.12 KB
Untitled
18 hours ago | 1.88 KB
Untitled
18 hours ago | 0.67 KB
Untitled
18 hours ago | 3.33 KB
Untitled
18 hours ago | 1.00 KB
Untitled
18 hours ago | 0.33 KB
Untitled
18 hours ago | 1.55 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!