-
-
Save anonymous/73c8a0c28fe6bc14d773 to your computer and use it in GitHub Desktop.
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 "Header yo\game.h" | |
bool cPlayer::Move() | |
{ | |
map[m_posY][m_posX] = T_FLOOR; //making sure the old player position isn't there anymore to avoid multiple players | |
m_Direction = _getch(); | |
switch(m_Direction) | |
{ | |
case 'a': | |
if (m_posX == 0) {} //moving commands and ifs preventing the player from going off-map | |
else {m_posX--;} | |
break; | |
case 'd': | |
if (m_posX == sizeX-1) {} | |
else {m_posX++;} | |
break; | |
case 'w': | |
if (m_posY == 0) {} | |
else {m_posY--;} | |
break; | |
case 's': | |
if (m_posY == sizeY-1) {} | |
else { m_posY++; } | |
break; | |
default: | |
cout << "what are you doing son"; | |
break; | |
} | |
return true; | |
} | |
bool cPlayer::CheckPosition() //you probably won't guess that | |
{ | |
{ | |
for (int i = 0; i < sizeY; i++) | |
{ | |
for (int j = 0; j < sizeX; j++) { | |
if (map[i][j] == T_PLAYER) | |
{ | |
m_posY = i; | |
m_posX = j; | |
} | |
} | |
} | |
return true; | |
} | |
} |
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
/TO DO: | |
//-Generacja map, mniej sztywna na zasadzie że rząd nie musi być pełny (jaskiniowy) | |
//-Mniej debilny sposób na ramkę (Opcjonalne) | |
//-Kamienie blokujące przejście | |
//-Stworzyć klasę humanoida (;_;) - X | |
//v1.0.1 | |
#ifndef GAME_H | |
#define GAME_H | |
#include <iostream> | |
#include <ctime> | |
#include <conio.h> | |
using namespace std; | |
enum TYPE {T_PLAYER = '@', T_FLOOR = ' '}; | |
const int sizeY = 6, sizeX = 6; | |
TYPE map[sizeY][sizeX]; //psst. you move on that | |
class cPlayer | |
{ | |
int m_posY, m_posX; //coordinates of player, do you even brain | |
char m_Direction; //stores the input for Move() | |
public: | |
//cPlayer() {m_posY = 0, m_posX = 0} | |
bool CheckPosition(); //you probably won't guess that | |
bool Move(); //i highly doubt you know what that does | |
} ; | |
bool InitializeMap() //fills the map[][] table with T_EMPTY | |
{ | |
for (int i = 0; i < sizeY; i++) //y | |
{ | |
for (int j = 0; j < sizeX; j++) //x | |
{ | |
map[i][j] = T_FLOOR; | |
} | |
} | |
map[1][1] = T_PLAYER; //places the player | |
return true; | |
} | |
bool DrawMap() //no way you know what that does | |
{ | |
int k = 0; | |
for (int i = 0; i < (sizeX+2); i++) //draws top vertical border | |
{ | |
cout << "-"; | |
} | |
cout << "\n"; | |
for (int i = 0; i < sizeY; i++) | |
{ | |
for (int j = 0; j < sizeX; j++, k++) | |
{ | |
switch(map[i][j]) | |
{ | |
case T_FLOOR: | |
if (j == 0) { cout << '|' << static_cast<char>(T_FLOOR); } | |
else if (j == (sizeX - 1)) { cout << static_cast<char>(T_FLOOR) << '|';} | |
else { cout << static_cast<char>(T_FLOOR); ;} | |
break; | |
case T_PLAYER: | |
if (j == 0) { cout << '|' << static_cast<char>(T_PLAYER); } | |
else if (j == (sizeX - 1)) { cout << static_cast<char>(T_PLAYER) << '|';} | |
else cout << static_cast<char>(T_PLAYER); | |
break; | |
default: | |
return false; | |
break; | |
} | |
} | |
if (k % sizeX == 0) { cout << "\n"; } //checks if a row is full | |
} | |
for (int i = 0; i < (sizeX+2); i++) //draws bottom vertical border >he doesn't make functions for every little thing | |
{ | |
cout << "-"; | |
} | |
cout << "\n"; | |
return true; | |
} | |
#endif |
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 "Header yo\game.h" | |
#include <iostream> | |
using namespace std; | |
int main() { | |
cPlayer user; | |
InitializeMap(); | |
for(;;) { | |
system("cls"); | |
user.CheckPosition(); | |
DrawMap(); | |
user.Move(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment