Initial commit

This commit is contained in:
Tyrel Souza 2020-05-21 12:29:50 -04:00
commit 6be16a213c
20 changed files with 717 additions and 0 deletions

159
Hallo.dev Executable file
View File

@ -0,0 +1,159 @@
[Project]
FileName=Hallo.dev
Name=Hallo
UnitCount=11
Type=1
Ver=1
ObjFiles=
Includes=
Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=
Linker=
IsCpp=1
Icon=
ExeOutput=
ObjectOutput=
OverrideOutput=0
OverrideOutputName=
HostApplication=
Folders=
CommandLine=
UseCustomMakefile=0
CustomMakefile=
IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=0
CompilerSettings=
[Unit1]
FileName=main.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[VersionInfo]
Major=0
Minor=1
Release=1
Build=1
LanguageID=1033
CharsetID=1252
CompanyName=
FileVersion=
FileDescription=Developed using the Dev-C++ IDE
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=
AutoIncBuildNr=0
[Unit2]
FileName=room.h
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit3]
FileName=room.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit4]
FileName=monsters.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit5]
FileName=monsters.h
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit6]
FileName=secrets.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit7]
FileName=secrets.h
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit8]
FileName=exits.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit9]
FileName=exits.h
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit10]
FileName=items.h
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit11]
FileName=items.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

80
Hallo.layout Executable file
View File

@ -0,0 +1,80 @@
[Editor_10]
CursorCol=1
CursorRow=1
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_9]
CursorCol=1
CursorRow=3
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_7]
CursorCol=19
CursorRow=1
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_8]
CursorCol=1
CursorRow=3
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_5]
CursorCol=21
CursorRow=1
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_6]
CursorCol=1
CursorRow=3
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_3]
CursorCol=22
CursorRow=1
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_4]
CursorCol=1
CursorRow=3
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_2]
CursorCol=1
CursorRow=1
TopLine=1
LeftChar=1
Open=1
Top=0
[Editor_1]
CursorCol=47
CursorRow=46
TopLine=28
LeftChar=1
Open=1
Top=1
[Editors]
Focused=1
Order=0,1,2
[Editor_0]
Open=1
Top=0
CursorCol=37
CursorRow=191
TopLine=182
LeftChar=1

45
Makefile.win Executable file
View File

@ -0,0 +1,45 @@
# Project: Hallo
# Makefile created by Dev-C++ 4.9.9.2
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES =
OBJ = main.o room.o monsters.o secrets.o exits.o items.o $(RES)
LINKOBJ = main.o room.o monsters.o secrets.o exits.o items.o $(RES)
LIBS = -L"C:/Dev-Cpp/lib"
INCS = -I"C:/Dev-Cpp/include"
CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
BIN = Hallo.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before Hallo.exe all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "Hallo.exe" $(LIBS)
main.o: main.cpp
$(CPP) -c main.cpp -o main.o $(CXXFLAGS)
room.o: room.cpp
$(CPP) -c room.cpp -o room.o $(CXXFLAGS)
monsters.o: monsters.cpp
$(CPP) -c monsters.cpp -o monsters.o $(CXXFLAGS)
secrets.o: secrets.cpp
$(CPP) -c secrets.cpp -o secrets.o $(CXXFLAGS)
exits.o: exits.cpp
$(CPP) -c exits.cpp -o exits.o $(CXXFLAGS)
items.o: items.cpp
$(CPP) -c items.cpp -o items.o $(CXXFLAGS)

1
exits.cpp Executable file
View File

@ -0,0 +1 @@
#include "exits.h"

6
exits.h Executable file
View File

@ -0,0 +1,6 @@
#ifndef EXITS_H_
#define EXITS_H_
#endif

BIN
exits.o Executable file

Binary file not shown.

1
items.cpp Executable file
View File

@ -0,0 +1 @@
#include "items.h"

10
items.h Executable file
View File

@ -0,0 +1,10 @@
#ifndef ITEMS_H_
#define ITEMS_H_
#endif

BIN
items.o Executable file

Binary file not shown.

315
main.cpp Executable file
View File

@ -0,0 +1,315 @@
#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#ifdef _WIN32 //windows includes
#include<windows.h>
#endif //end windows includes
#include "room.cpp"
#include "monsters.cpp"
#include "secrets.cpp"
#include "exits.cpp"
#include "items.cpp"
using namespace std;
//VARIABLES
const int NORTH = 8;
const int SOUTH = 4;
const int EAST = 2;
const int WEST = 1;
const int OPEN = 1;
const int CLOSE = 2;
bool gameRun = true;
string PROMPT;
string prompt;
int currentX,currentY;
vector<vector<Room> > room(5, vector<Room>(5));
// END VARIABLES
//FUNCTIONS
void cls();
void move(int dir);
void checkMove(int dir);
void showMap();
void checkPrompt(string pmp);
void showHelp();
void initialize();
void ShowExits();
void jumpTo(int x,int y);
void openCloseExit(int dir, int oc);
//END FUNCTIONS
int main(int argc, char *argv[])
{
initialize();
while(gameRun){
cout<<PROMPT; //show prompt
getline(cin,prompt); //get what the prompt is
checkPrompt(prompt); //check the options
} //end game loop
return EXIT_SUCCESS;
}
void move(int dir){
//MOVE FIRST
checkMove(dir);
//check anything after
if(room[currentX][currentY].IsEnd())
{
gameRun=false;
cout<<"\a";
}
//check for monsters
//check for secrets
//check for items
}
void checkMove(int dir){
switch (dir){
case 8:
if((room[currentX][currentY].Exits() & NORTH) == NORTH) // if there are exits to the DIRECTION,
{
room[currentX][currentY].leaveRoom(); //LEAVE THE CURRENT ROOM
currentY=currentY-1; //MOVE THE CURRENT POSITION
room[currentX][currentY].enterRoom(); //ENTER NEW ROOM
showMap();
cout << "You move North.\n";
} else {
showMap();
cout<<"You cannot move that direction.\n";
}
break;
case 4:
if((room[currentX][currentY].Exits() & SOUTH) == SOUTH)
{
room[currentX][currentY].leaveRoom();
currentY=currentY+1;
room[currentX][currentY].enterRoom();
showMap();
cout << "You move South.\n";
} else {
showMap();
cout<<"You cannot move that direction.\n";
}
break;
case 2:
if((room[currentX][currentY].Exits() & EAST)== EAST)
{
room[currentX][currentY].leaveRoom();
currentX=currentX+1;
room[currentX][currentY].enterRoom();
showMap();
cout << "You move East.\n";
} else {
showMap();
cout<<"You cannot move that direction.\n";
}
break;
case 1:
if((room[currentX][currentY].Exits() & WEST)== WEST)
{
room[currentX][currentY].leaveRoom();
currentX=currentX-1;
room[currentX][currentY].enterRoom();
showMap();
cout << "You move West.\n";
} else {
showMap();
cout<<"You cannot move that direction.\n";
}
break;
}
}
void jumpTo(int x,int y){
room[currentX][currentY].leaveRoom();
currentX = x;
currentY = y;
room[currentX][currentY].enterRoom();
}
void checkPrompt(string pmp){
//directions
if((pmp=="go north") || (pmp=="north")){move(NORTH);return;}
if((pmp=="go south") || (pmp=="south")){move(SOUTH);return;}
if((pmp=="go east") || (pmp=="east")){move(EAST); return;}
if((pmp=="go west") || (pmp=="west")){move(WEST); return;}
if((pmp=="close north") || (pmp=="close n")){openCloseExit(NORTH,CLOSE); return;}
if((pmp=="close south") || (pmp=="close s")){openCloseExit(SOUTH,CLOSE); return;}
if((pmp=="close east") || (pmp=="close e")){openCloseExit(EAST,CLOSE); return;}
if((pmp=="close west") || (pmp=="close w")){openCloseExit(WEST,CLOSE); return;}
if((pmp=="open north") || (pmp=="open n")){openCloseExit(NORTH,OPEN); return;}
if((pmp=="open south") || (pmp=="open s")){openCloseExit(SOUTH,OPEN); return;}
if((pmp=="open east") || (pmp=="open e")){openCloseExit(EAST,OPEN); return;}
if((pmp=="open west") || (pmp=="open w")){openCloseExit(WEST,OPEN); return;}
if((pmp=="map")||(pmp=="m")){showMap(); return;}
if((pmp=="help") || (pmp=="?")){showHelp(); return;}
if((pmp=="look") || (pmp=="l")){ShowExits(); return;}
if((pmp=="quit") || (pmp=="exit") || (pmp=="q")){gameRun=false; return;}
cls();
cout << "What was that?";
}
void ShowExits(){
if(room[currentX][currentY].Exits() >0){
cout<<"There are exits to the...";
if((room[currentX][currentY].Exits() & NORTH) == NORTH){cout<<"\nnorth"; }
if((room[currentX][currentY].Exits() & SOUTH) == SOUTH){cout<<"\nsouth"; }
if((room[currentX][currentY].Exits() & EAST) == EAST){cout<<"\neast"; }
if((room[currentX][currentY].Exits() & WEST) == WEST){cout<<"\nwest"; }
cout<<"\n";
} else {
cout << "All of the doors are closed.";
}
}
void openCloseExit(int dir, int oc){
int state = room[currentX][currentY].opencloseExit(dir,oc);
// cout << state;
switch (oc)
{
case 1:
switch (state){
case 1:
cout <<"Something clicks...";
break;
case 2:
cout <<"Dude... that's a wall.";
break;
case 3:
cout <<"Nothing Happened.";
break;
}
break;
case 2:
switch (state){
case 1:
cout <<"...Thud...";
break;
case 2:
cout <<"Dude... that's a wall.";
break;
case 3:
cout <<"Nothing Happened.";
break;
}
break;
}
}
void showHelp(){
cls();
cout<<"Welcome Tyrel's Game\n"
<<"\t-To Begin, Try going in a direction\n"
<<"\t\t\"north\",\"south\",\"east\" or \"west\"\n"
<<"\t-There is also a \"map\"\n"
<<"\tIf you are lost, try \"look\"";
}
void showMap(){
cls();
for(int y=0; y<5;y++){
for (int x = 0; x <5;x++){
if(room[x][y].InRoom()){
cout<< "(X)\t";
} else {
cout << "(.)\t";//room[x][y].Exits() << "\t";
}
}
cout << "\n\n";
}
}
//this will clear the screen
void cls()
{
#ifdef _WIN32
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {0, 0};
DWORD count;
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hStdOut, &csbi);
FillConsoleOutputCharacter(hStdOut, ' ',
csbi.dwSize.X * csbi.dwSize.Y,
coord, &count);
SetConsoleCursorPosition(hStdOut, coord);
#else
cout << "\f";
#endif
}
void initialize(){
room[0][0] = Room(false,SOUTH, 0, 0, 0);
room[0][1] = Room(false,NORTH+ SOUTH, 0, 0, 0);
room[0][2] = Room(false,NORTH+ EAST, 0, 0, 0);
room[0][3] = Room(false,SOUTH+ EAST, 0, 0, 0);
room[0][4] = Room(false,NORTH+ EAST, 0, 0, 0);
room[1][0] = Room(false,SOUTH+ EAST, 0, 0, 0);
room[1][1] = Room(false,NORTH+ EAST, 0, 0, 0);
room[1][2] = Room(false,WEST + SOUTH, 0, 0, 0);
room[1][3] = Room(false,NORTH+ WEST, 0, 0, 0);
room[1][4] = Room(false,WEST + EAST, 0, 0, 0);
room[2][0] = Room(false,WEST + EAST, 0, 0, 0);
room[2][1] = Room(false,WEST + SOUTH, 0, 0, 0);
room[2][2] = Room(false,NORTH+ SOUTH, 0, 0, 0);
room[2][3] = Room(false,NORTH+ SOUTH, 0, 0, 0);
room[2][4] = Room(false,NORTH+ WEST, 0, 0, 0);
room[3][0] = Room(false,WEST + SOUTH, 0, 0, 0);
room[3][1] = Room(false,NORTH+ SOUTH, 0, 0, 0);
room[3][2] = Room(false,NORTH+ SOUTH, 0, 0, 0);
room[3][3] = Room(false,NORTH+ SOUTH, 0, 0, 0);
room[3][4] = Room(false,NORTH+ EAST, 0, 0, 0);
room[4][0] = Room(true,SOUTH, 0, 0, 0);
room[4][1] = Room(false,NORTH+SOUTH, 0, 0, 0);
room[4][2] = Room(false,NORTH+SOUTH, 0, 0, 0);
room[4][3] = Room(false,NORTH+SOUTH, 0, 0, 0);
room[4][4] = Room(false,NORTH+WEST, 0, 0, 0);
currentX = 0;
currentY = 0;
PROMPT = "\nAction: ";
room[currentX][currentY].enterRoom();
cout <<"Hello, try \"help\" to get started.\n";
}

BIN
main.o Executable file

Binary file not shown.

1
monsters.cpp Executable file
View File

@ -0,0 +1 @@
#include "monsters.h"

9
monsters.h Executable file
View File

@ -0,0 +1,9 @@
#ifndef MONSTERS_H_
#define MONSTERS_H_
#endif

BIN
monsters.o Executable file

Binary file not shown.

1
room.cpp Executable file
View File

@ -0,0 +1 @@
#include "room.h"

82
room.h Executable file
View File

@ -0,0 +1,82 @@
#ifndef ROOM_H_
#define ROOM_H_
#include <iostream>
using namespace std;
class Room {
bool isEnd;
int exits,newExits;
int secrets;
int monsters;
int items;
bool inRoom;
public:
Room(bool ie,int e,int s,int m,int i)
{
isEnd = ie;
exits = e;
secrets = s;
monsters = m;
items = i;
inRoom=false;
newExits = e;
}
Room(){}
//facilitates opening and closing a door
int opencloseExit(int ex, int oc){
/* * * * * * * * * * * * * * *
* TO DO:
* FIX THE OPENING ALREADY OPEN/CLOSE
*
*
* * * * * * * * * * * * * * */
if (oc == 2){ //close
if((oExits() & ex ) == ex ){
if(newExits > exits ) {
newExits = exits;
}
newExits = newExits - ex;
return 1;
} else {
return 2;
}
}
if (oc==1){ //open
if((oExits() & ex ) == ex ){
newExits = newExits + ex;
if(newExits > exits ) {
newExits = exits;
}
return 1;
} else {
return 2;
}
}
}
void leaveRoom(){inRoom=false;}
void enterRoom(){inRoom = true;}
bool InRoom(){return inRoom;}
bool IsEnd(){return isEnd;}
int Exits(){return newExits;}
int nExits(){return newExits;}
int oExits(){return exits;}
int Secrets(){return secrets;}
int Monsters(){return monsters;}
int Items(){return items;}
};
#endif /*FUNCS_H_*/

BIN
room.o Executable file

Binary file not shown.

1
secrets.cpp Executable file
View File

@ -0,0 +1 @@
#include "secrets.h"

6
secrets.h Executable file
View File

@ -0,0 +1,6 @@
#ifndef SECRETS_H_
#define SECRETS_H_
#endif

BIN
secrets.o Executable file

Binary file not shown.