Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Text-Based-game/Gustes code/hp.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
26 lines (25 sloc)
699 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
using namespace std; | |
int main() | |
{ | |
int hp = 15; | |
int enemyattack = 5; | |
string a; | |
cout << "Alien has " << hp << " health, every time you type 'Hit' it will drop by " << enemyattack << ".\n" << endl; | |
string Yes = "Hit"; | |
while(true) // While typing 'Hit' it will minus the enemy attack value | |
{ | |
cin >> a; | |
if (a == Yes) | |
{ | |
hp -= enemyattack; | |
cout << "Alien now has " << hp << "HP left.\n\n"; | |
if (hp==0) // When there is no Hp loop will break | |
{ | |
break; | |
} | |
} | |
} | |
cout << "You have killed an enemy alien!" << endl; | |
} |