/
Player.c
208 lines (198 loc) · 6.04 KB
/
Player.c
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "Core.h"
void SetClass(Player *ThisPlayer, short Choice)
{
switch(Choice)
{
case 1: //Warrior
ThisPlayer->PClass.ModHealthMinMax.X = 7;
ThisPlayer->PClass.ModHealthMinMax.Y = 12;
ThisPlayer->PClass.ModStrMinMax.X = 3;
ThisPlayer->PClass.ModStrMinMax.Y = 6;
ThisPlayer->PClass.ModDexMinMax.X = 1;
ThisPlayer->PClass.ModDexMinMax.Y = 2;
ThisPlayer->PClass.ModIntMinMax.X = 1;
ThisPlayer->PClass.ModIntMinMax.Y = 2;
strcpy(ThisPlayer->PClass.ClassString, "Warrior");
break;
}
}
void SetRace(Player *ThisPlayer, short Choice)
{
switch(Choice)
{
case 1: //Human
ThisPlayer->PRace.HealthMinMax.X = 15;
ThisPlayer->PRace.HealthMinMax.Y = 30;
ThisPlayer->PRace.StrMinMax.X = 7;
ThisPlayer->PRace.StrMinMax.Y = 15;
ThisPlayer->PRace.DexMinMax.X = 9;
ThisPlayer->PRace.DexMinMax.Y = 18;
ThisPlayer->PRace.IntMinMax.X = 8;
ThisPlayer->PRace.IntMinMax.Y = 18;
strcpy(ThisPlayer->PRace.RaceString, "Human");
printw("You chose human\n");
break;
}
}
void GetRace(Player *ThisPlayer)
{
printw("Select Your Race:\n\n\n");
printw("(a) Human\n");
switch(getch())
{
case 'a':
SetRace(ThisPlayer, 1);
break;
}
}
void GetClass(Player *ThisPlayer)
{
printw("Select your class \n");
printw("(a) Warrior");
switch(getch())
{
case 'a':
SetClass(ThisPlayer, 1);
break;
}
}
void RollPlayer(Player *ThisPlayer)
{
short ModHealth = 0;
short ModStrength = 0;
short ModDex = 0;
short ModInt = 0;
//printw("Rolling Mods\n");
//refresh();
ModHealth = getrand(ThisPlayer->PClass.ModHealthMinMax.X, ThisPlayer->PClass.ModHealthMinMax.Y);
//printw("Mod Health Complete %d\n", ModHealth);
//refresh();
ModStrength = getrand(ThisPlayer->PClass.ModStrMinMax.X, ThisPlayer->PClass.ModStrMinMax.Y);
//printw("Mod Strength Complete %d\n", ModStrength);
//refresh();
ModDex = getrand(ThisPlayer->PClass.ModDexMinMax.X, ThisPlayer->PClass.ModDexMinMax.Y);
//printw("Mod Dex Complete %d\n", ModDex);
//refresh();
ModInt = getrand(ThisPlayer->PClass.ModIntMinMax.X, ThisPlayer->PClass.ModIntMinMax.Y);
//printw("Mod Int Complete %d\n", ModInt);
//refresh();
ThisPlayer->Strength = getrand(ThisPlayer->PRace.StrMinMax.X + ModStrength, ThisPlayer->PRace.StrMinMax.Y + ModStrength);
ThisPlayer->Health = getrand(ThisPlayer->PRace.HealthMinMax.X + ModHealth, ThisPlayer->PRace.HealthMinMax.Y + ModHealth);
ThisPlayer->Dex = getrand(ThisPlayer->PRace.DexMinMax.X + ModDex, ThisPlayer->PRace.DexMinMax.Y + ModDex);
ThisPlayer->Int = getrand(ThisPlayer->PRace.IntMinMax.X + ModInt, ThisPlayer->PRace.IntMinMax.Y + ModInt);
//printw("Character Rolled\n");
ThisPlayer->CurrHealth = ThisPlayer->Health;
}
void DescribePlayer(Player *ThisPlayer)
{
strcpy(ThisPlayer->PDescript, "\n You were born a ");
strcat(ThisPlayer->PDescript, ThisPlayer->PRace.RaceString);
strcat(ThisPlayer->PDescript, ", You decided to train as a ");
strcat(ThisPlayer->PDescript, ThisPlayer->PClass.ClassString);
strcat(ThisPlayer->PDescript, ", Your parents named you ");
strcat(ThisPlayer->PDescript, ThisPlayer->PName);
}
void GenPlayer(Player *ThisPlayer)
{
printw("Please input your name\n");
echo();
getstr(ThisPlayer->PName);
noecho();
clear();
GetRace(ThisPlayer);
clear();
GetClass(ThisPlayer);
clear();
RollPlayer(ThisPlayer);
DescribePlayer(ThisPlayer);
printw("%s ", ThisPlayer->PDescript);
refresh();
getch();
InitInv(&ThisPlayer->PInventory);
clear();
ThisPlayer->PlayerOut = '@';
ThisPlayer->PlayerPos.X = 15;
ThisPlayer->PlayerPos.Y = 15;
};
void EndGame(Player *ThisPlayer)
{
clear();
mvprintw(0, 0, "Evil Won, Now Live");
refresh();
getch();
endwin();
}
void MovePlayer(Map *ThisMap, Player *ThisPlayer, short Key)
{
switch(Key)
{
case UP:
if(ThisMap->MapTile[ThisPlayer->PlayerPos.X - 1][ThisPlayer->PlayerPos.Y].IsWalk == 1)
{
ThisMap->MapTile[ThisPlayer->PlayerPos.X - 1][ThisPlayer->PlayerPos.Y].TilePlayer = ThisPlayer;
ThisMap->MapTile[ThisPlayer->PlayerPos.X][ThisPlayer->PlayerPos.Y].TilePlayer = NULL;
}
break;
case DOWN:
if(ThisMap->MapTile[ThisPlayer->PlayerPos.X + 1][ThisPlayer->PlayerPos.Y].IsWalk == 1)
{
ThisMap->MapTile[ThisPlayer->PlayerPos.X + 1][ThisPlayer->PlayerPos.Y].TilePlayer = ThisPlayer;
ThisMap->MapTile[ThisPlayer->PlayerPos.X][ThisPlayer->PlayerPos.Y].TilePlayer = NULL;
}
break;
case LEFT:
if(ThisMap->MapTile[ThisPlayer->PlayerPos.X][ThisPlayer->PlayerPos.Y + 1].IsWalk == 1)
{
ThisMap->MapTile[ThisPlayer->PlayerPos.X][ThisPlayer->PlayerPos.Y + 1].TilePlayer = ThisPlayer;
ThisMap->MapTile[ThisPlayer->PlayerPos.X][ThisPlayer->PlayerPos.Y].TilePlayer = NULL;
}
break;
case RIGHT:
if(ThisMap->MapTile[ThisPlayer->PlayerPos.X][ThisPlayer->PlayerPos.Y - 1].IsWalk)
{
ThisMap->MapTile[ThisPlayer->PlayerPos.X][ThisPlayer->PlayerPos.Y - 1].TilePlayer = ThisPlayer;
ThisMap->MapTile[ThisPlayer->PlayerPos.X][ThisPlayer->PlayerPos.Y].TilePlayer = NULL;
}
break;
};
Move(ThisMap, &ThisPlayer->PlayerPos, Key);
}
void SetPlayer(Map *ThisMap, Player *ThisPlayer)
{
RandVPos(ThisMap, &ThisPlayer->PlayerPos);
ThisMap->MapTile[ThisPlayer->PlayerPos.X][ThisPlayer->PlayerPos.Y].TilePlayer = ThisPlayer;
PutObj(ThisMap, ThisPlayer->PlayerPos, ThisPlayer->PlayerOut);
}
void PlayerHit(Monster *ThisMonster, Player *ThisPlayer)
{
short HitDam;
HitDam = 5;
ThisMonster->CurrHealth -= HitDam;
}
void Attack(Map *ThisMap, Player *ThisPlayer, short AttackDir)
{
COORD HitPos;
HitPos = ThisPlayer->PlayerPos;
Direction(&HitPos, AttackDir);
if(ThisMap->MapTile[HitPos.X][HitPos.Y].TileMob)
{
PlayerHit(ThisMap->MapTile[HitPos.X][HitPos.Y].TileMob, ThisPlayer);
if(ThisMap->MapTile[HitPos.X][HitPos.Y].TileMob->CurrHealth <= 0)
{
MonsterDeath(ThisMap, HitPos);
mvprintw(MSGPOSX, MSGPOSY, "You killed it!");
};
}
else
{
mvprintw(MSGPOSX, MSGPOSY, "Nothing to hit!");
};
}
void DisplayStats(Player *ThisPlayer)
{
mvprintw(2, 65, "Str: %d", ThisPlayer->Strength);
mvprintw(3, 65, "Dex: %d", ThisPlayer->Dex);
mvprintw(4, 65, "Int: %d", ThisPlayer->Int);
mvprintw(5, 65, "HP: %d / %d", ThisPlayer->Health, ThisPlayer->CurrHealth);
refresh();
};