Beggining Beginning of simple rogue-like rpgRPG (in cosoleconsole) onin C++
I've started to learn programming recently and it's my first more or less "big" project. But coding this projectsproject for me is quite hard. I spent a lot of time to understand what I've done and my coding is developing really slowslowly. And I'm curious what's my problem? Is it my lack of experience or Isis it my ugly style of programming? If it's all about style Pleaseplease tell me about my mistakes.
"@""@"
- Main character
"#""#"
- Wall
".""."
- Floor
You can move the charectercharacter by numpad ("8""8"
- to go up, "6""6"
to go right and etc.) but controls are made by cin>>cin>>
(for now I hope).
Main.cppMain.cpp
Map.hMap.h
Map.cppMap.cpp
MainChar.hMainChar.h
Screen.hScreen.h
Screen.cppScreen.cpp
Thanks for reading at least!
Beggining of simple rogue-like rpg (in cosole) on C++
I've started to learn programming recently and it's my first more or less "big" project. But coding this projects for me is quite hard. I spent a lot of time to understand what I've done and my coding is developing really slow. And I'm curious what's my problem? Is it my lack of experience or Is it my ugly style of programming? If it's all about style Please tell me about my mistakes.
"@" - Main character
"#" - Wall
"." - Floor
You can move the charecter by numpad ("8" - to go up, "6" to go right and etc.) but controls are made by cin>> (for now I hope)
Main.cpp
Map.h
Map.cpp
MainChar.h
Screen.h
Screen.cpp
Thanks for reading at least!
Beginning of simple rogue-like RPG (in console) in C++
I've started to learn programming recently and it's my first more or less "big" project. But coding this project for me is quite hard. I spent a lot of time to understand what I've done and my coding is developing really slowly. And I'm curious what's my problem? Is it my lack of experience or is it my ugly style of programming? If it's all about style please tell me about my mistakes.
"@"
- Main character
"#"
- Wall
"."
- Floor
You can move the character by numpad ("8"
- to go up, "6"
to go right and etc.) but controls are made by cin>>
(for now I hope).
Main.cpp
Map.h
Map.cpp
MainChar.h
Screen.h
Screen.cpp
Beggining of simple rogue-like rpg (in cosole) on C++
I've started to learn programming recently and it's my first more or less "big" project. But coding this projects for me is quite hard. I spent a lot of time to understand what I've done and my coding is developing really slow. And I'm curious what's my problem? Is it my lack of experience or Is it my ugly style of programming? If it's all about style Please tell me about my mistakes.
What do I have now?
"@" - Main character
"#" - Wall
"." - Floor
You can move the charecter by numpad ("8" - to go up, "6" to go right and etc.) but controls are made by cin>> (for now I hope)
Main.cpp
#include "Map.h" // Map class
#include "MainChar.h" // Main charecter class
#include "Screen.h" // Screen Class
void WaitKey(char& key) //sooner or later I will move all functions in separate file
{
std::cin>>key;
}
int main()
{
//Creating objects
char key=' '; //key that pressed
bool quit=false; // flag for quit
Screen scr; // it's my screen
Map map; // it's my map
MainChar Mchar;
scr.cordx=39; //x coordinate of camera
scr.cordy=39; //y coordinate of camera
//Game Preaparation
scr.FillHelp();
map.Fill();
scr.RenderScr(map,Mchar);
while (!quit) // Main loop
{
// Game Logic
//Contolls
WaitKey(key);
switch (key)
{
case '6' :
if (scr.Scr[Mchar.y][Mchar.x + 1]=='#')
scr.log="There is a wall on my way";
else
scr.cordx++;
break;
case '4' :
if (scr.Scr[Mchar.y][Mchar.x - 1]=='#')
scr.log="There is a wall on my way";
else
scr.cordx--;
break;
case '8' :
if (scr.Scr[Mchar.y - 1][Mchar.x]=='#')
scr.log="There is a wall on my way";
else
scr.cordy--;
break;
case '2' :
if (scr.Scr[Mchar.y + 1][Mchar.x]=='#')
scr.log="There is a wall on my way";
else
scr.cordy++;
break;
}
//Rendering the screen
scr.RenderScr(map,Mchar);
}
return 0;
}
Map.h
#ifndef Map_h
#define Map_h
#endif
class Map
{
public:
void Fill(); // Creating Map
public:
char Layout[120][120]; // The Walls on the map
};
Map.cpp
#include "Map.h"
void Map::Fill() //Creating Map
{
for (int i=0;i<120;i++)
{
for (int j=0;j<120;j++)
{
if (i==40 || i==80 || j==40 || j==80) // For now it's just the simpliest map
Layout[i][j]='#'; // This symbol means Wall
else
Layout[i][j]='.'; // This symbol means Floor
}
}
}
MainChar.h
#ifndef MainChar_h
#define MainChar_h
#endif
class MainChar
{
public:
MainChar(); //constructor of the class
char Symb; //Symbol of a character
int x,y; //Coordinates of a character
};
MainChar.cpp
#include "MainChar.h"
#include <stdlib.h>
MainChar::MainChar() //constructor
: Symb {'@'} , x{10}, y{10} // x=10; y=10 - center of the screen
{
}
Screen.h
#include <iostream> // call ios to use render
#include <stdlib.h>
#include <string.h>
#ifndef Map_h
#include "Map.h"
#endif
#ifndef MainChar_h
#include "MainChar.h"
#endif
class Screen
{
public:
void RenderScr(Map lay,MainChar mchar); // "capturing" the screen
void FillHelp(); // filling help
public:
std::string help[21]; // It's description of controls
std::string log; // It's the log of events
char Scr[21][21]; // it's the screen we are printing on or "camera view" if you can call it
int cordx,cordy; // coordinates of the screen
};
Screen.cpp
#include "Screen.h"// Calling our header file
void Screen::RenderScr(Map lay,MainChar mchar) // "capturing" the screen and printing it
{
system("cls");
for (int i=0;i<21;i++) // first loop for "capturing" the screen
{
for (int j=0;j<21;j++) // second loop for "capturing" the screen
{
Scr[i][j]=lay.Layout[i+cordy][j+cordx]; // "rendering" the walls
if (i==mchar.y && j==mchar.x)
Scr[i][j]=mchar.Symb; // "rendering" the Main Character
//bla bla bla other objects
std::cout<<Scr[i][j]; //printing the screen
}
std::cout<<'\t'<<help[i]<<'\n'; // printing help
}
std::cout<<log<<'\n'; //printing the log
log="";
void Screen::FillHelp() //filling help
{
help[0]="\"Numpad\"... - Movement"; //help message No 1
help[1]=""; //help message No 2
for (int i=2; i<21; i++) //blanket messages
help[i]="";
}
Thanks for reading at least!