-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
116 lines (104 loc) · 3.12 KB
/
main.cpp
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
#include "castor1.1\castor.h"
#include <map>
#include <ctime>
#include "KB.h"
#include "Phases.h"
//GLOBAL VARS
int g_GameState = 0; //0:continue game, 1:A won, 2:B won, -1: exceeded max turns
int g_turns = 0;
//
bool endGame()
{
return g_GameState != 0;
}
using CharInfoMap = std::map<std::string/*name*/, CharInfo>;
int main()
{
using namespace std;
using namespace castor;
//[USER INPUT]
std::string input;
std::string msg = "\nENTER TYPE OF GAME: ('STANDARD' OR 'CUSTOM') \n"
+ string( " (standard: auto run a normal game) \n (custom: custom unit choosing, difficulty level, etc.)\n (use lowercase)\n" );
cout << msg;
std::getline( std::cin, input );
string wantedUnitType = "all";
if ( input != "standard" )
{
std::string msg = "\nENTER WANTED UNIT TYPE: \n"
+ string( " ('rock' or 'paper' or 'scissors')\n (use lowercase)\n" );
cout << msg;
std::getline( std::cin, wantedUnitType );
if ( wantedUnitType != "rock" && wantedUnitType != "scissors" && wantedUnitType != "paper" )
{
cout << "invalid input. defaulting to type: 'rock' \n\n";
wantedUnitType = "rock";
}
}
using CharInfoVec = map<string/*name*/, CharInfo>;
CharInfoVec playerInfos;
//Initialize board representation
for(int i = 0; i < g_mapWidth;i++)
{
for (int j = 0; j < g_mapHeight; j++)
{
g_gameMap[i][j]._movementValue = 1;
g_gameMap[i][j]._defenseBonus = 0;
g_gameMap[i][j]._occupant = CharInfo();
}
}
//[POPULATE CHARACTERS]
{
lref<string> charName, teamName;
lref<float> hp;
lref<int> attack, movement, posX, posY;
relation characterInfo = onTeam( charName, teamName, hp, attack, movement, posX, posY );
while ( characterInfo() )
{
//Note: 'A') player team
if ( teamName.get() == "A" && wantedUnitType != "all" )
{
//if character has chosen a custom preferred type, only use units with that type
relation charHasWeaponType = characterHeldWeaponType( charName, wantedUnitType );
if ( !charHasWeaponType() )
continue;
}
relation charInBounds = coordsWithinMap( posX, posY );
relation charOnMoveableTile = onMoveableCoord( posX, posY );
if ( charInBounds() && charOnMoveableTile() )
{
CharInfo charInfo;
charInfo._name = charName.get();
charInfo._teamName = teamName.get();
charInfo._hp = hp.get();
charInfo._attack = attack.get();
charInfo._movement = movement.get();
charInfo._pos = { posX.get(), posY.get() };
playerInfos.emplace( charName.get(), charInfo );
UpdateCharPos( charInfo, posX.get(), posY.get() );
}
}
}
//[GAME LOOP]
while ( g_GameState == 0 )
{
cout << "\n";
Phases::evalGameState( playerInfos );
if ( endGame() ) break;
//each player in team attacks a player in the other team
Phases::fightPhase( playerInfos );
if ( endGame() ) break;
++g_turns;
}
if ( g_GameState == -1 )
cout << string_format( "\nGame exceeded max turns:%i ", g_turns ) << endl;
else
{
//announce winner + finish
cout << string_format( "\nTeam:%s has won! (tot_rounds:%i) (player team:A)\n",
( g_GameState == 1 ? "A" : "B" ), g_turns ) << endl;
}
cout << "press enter to finish";
std::getline( std::cin, input );
return 0;
}