help me with health

how i can make if healt 0 game end???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

#include <Windows.h>
#include <iostream>
#include <BluetoothAPIs.h>
#include <ws2bth.h>



bool Move(int xadj, int yadj);  



void LoadMap();                 
void DrawScreen();              

using namespace std;
    
    




char Map[10][20] =      
{
    "###################",
    "#        *      ^^#",
    "#  #####  #########",
    "#  # Y #  #  ^    #",
    "# *# E #  # ##### #",
    "#  # A #* # # ! # #",
    "#* # H #  #     # #",
    "#  # ! #  ####### #",
    "#@ # ! #          #",
    "###################"
};

int Gamespeed = 100;
int Level = 1;
bool stopgame = false;
int Hp = 100;
int MaxHp = 100;
int Score = 0;
int PlayerX = 0;
int PlayerY = 0;
int Hp = 0;

const char Tile_Wall  = (char)219;
const char Tile_Floor = ' ';
const char Tile_Goal  = '!';
const char Tile_Enemy = '*';    
const char Tile_Bonus = '^';    

                     
                                
int main()
{
    LoadMap();      
    DrawScreen();   

    while(stopgame == false && Level == 1)      
    {
       
        
        bool playermoved = false;

             if(GetAsyncKeyState(VK_UP   ) & 0x8000)  playermoved = Move( 0,-1);
        else if(GetAsyncKeyState(VK_DOWN ) & 0x8000)  playermoved = Move( 0, 1);
        else if(GetAsyncKeyState(VK_LEFT ) & 0x8000)  playermoved = Move(-1, 0);
        else if(GetAsyncKeyState(VK_RIGHT) & 0x8000)  playermoved = Move( 1, 0);
		
        
        if(playermoved)
            DrawScreen();

        
        Sleep(Gamespeed);
    }

    while (stopgame == false && Level == 2)
    {
        system("cls");
        cout << "You Win!!!\n\n";
        cout << "Your score: " << Score << "\n\n";
        cout << "© XDmanne games\n\n";
        system("pause");
        return EXIT_SUCCESS;
    }

    return 0;
}

bool Move(int xadj, int yadj)
{
    
    int x = PlayerX + xadj;
    int y = PlayerY + yadj;

   
    bool canmove = true;      

    switch(Map[y][x])
    {
    case Tile_Wall:     canmove = false;        break;  
    case Tile_Floor:                            break;  
    case Tile_Goal:     ++Level;                break;  
    case Tile_Enemy:    Hp -= 20;               break;  
    case Tile_Bonus:    Score += 20;            break;  
    }

    
    if(canmove)
    {
        
        PlayerX = x;
        PlayerY = y;

        
        
        Map[y][x] = Tile_Floor;
    }

   
    return canmove;
}

void LoadMap()
{
    
    

    for(int y = 0; y < 10; ++y)
    {
        for(int x = 0; x < 20; ++x)
        {
            switch(Map[y][x])
            {
            case '#':                       
                Map[y][x] = Tile_Wall;      
                break;

            case '@':                       
                Map[y][x] = Tile_Floor;     
                PlayerX = x;                
                PlayerY = y;
                break;
            }
        }
    }
}


void DrawScreen()
{
    
    system("cls");
    
    

    Map[PlayerY][PlayerX] = '@';

    
    for (int y = 0; y < 10; y++)
    {
        cout << Map[y] << '\n';     
    }


    Map[PlayerY][PlayerX] = Tile_Floor;    
    
    
    cout << "Hp: " << Hp << "/" << MaxHp << '\n';      
    cout << "Score: " << Score << '\n';
    cout << "@=You" << '\n';
    cout << "*=Enemy" << '\n';
    cout << "!=Goal" << endl;       
}


Duplicate of http://www.cplusplus.com/forum/general/125786/

Please don't spam the forum with multiple threads for the same question. If the answer you received in that thread wasn't clear, you can use that thread to seek further clarification.
Topic archived. No new replies allowed.