Game screen

i have a question, i want to make a small game, but i dont want to write the whole screen more then once, i know it is possible because my friend made it and he didnt even use matricates, thanks :D
closed account (zb0S216C)
Begginer wrote:
but i dont want to write the whole screen more then once (sic)

By this do you mean a menu? or maybe the map?

Have you considered the use of functions: (?) http://www.cplusplus.com/doc/tutorial/functions/

Wazzak
I think he means moving the cursor position.

Obligatory link:

http://www.cplusplus.com/forum/articles/28558/
i mean the map, and disch yes he is moving the cursor position, i want to know how... that link didnt helped me..
Did you read it? =P
Dude, your friend is either lying or he doesn't know what he's talking about. If you want to make a C++ computer game and you're a begginer (sic) you need to start simple and learn a graphics package. C++ itself has NO CONCEPT of a computer screen or a keyboard. It only knows what streams in and out of its I/O. It can't possibly remember what is on the display YOU are looking at (that info is in graphics card RAM) so it MUST refresh the entire screen to reflect changes in its game memory. If you're friend is using some libraries under the hood to fool himself then good for him but you should be smarter and use one of the powerful graphics and sound libraries available for C++.

You will go nowhere until you understand these concepts. Posting the same question again will not get you the magical piece of code you're looking for: http://cplusplus.com/forum/beginner/51426/
lol u spelled beginner wrong, i spelled it wrong on purpose...
anyway, that doesnt help me one bit i already said i dont want to use that, i only want a small normal 2d game in console... without sprites...
this was a small console game i worked on in uni, no graphics just ascii

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
#include <iostream>
#include <string>
//#include "Array.h"


class Monster       // Declares monster class
{
public:
     int m_x;
     int m_y;
     int m_hitpoints;
};

class Player                //Declares player class
{
public:
Player() {p_x=9;p_y=9;}  //constructor for player class
int p_x;
int p_y;
};


const int blankspace = 0;  // constants for player, monster, and blankspace display
const int  player = 2;
const int monster = 1;

const int ROW = 10;  // array to hold level
const int COL = 10;

         int level[ROW][COL] = {{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0}};
  
using namespace std; // declares usage of standard namespace


    char in;             // declares variable 'in' used for player movement
std::string name;    // declares "name" as a string
int response;        // declares response variable
int oldX,oldY;       // declares variables for storing old x and y co-ordinates
    Player p;            // declares player Variable
   
    bool addmonster()
{
        int r;
for(int i=0;i<10;i++) {
for(int j=0;j<10;j++) {
if(level[i][j]==player)        // function for adding monsters
continue;
else {
r=rand()%10;
if(r==1) {
level[i][j]=monster;
}
}
}
}
return true;

}


   void game()
   {
   
    oldX=p.p_x;
oldY=p.p_y;
cin >> in;
if(in=='w') {     // Upward movement for player
p.p_y--;
level[p.p_y][p.p_x]=2;
level[oldY][oldX]=0;
}

if (in=='a') {   //Downward movement for player
p.p_x--;
level[p.p_y][p.p_x]=2;
level[oldY][oldX]=0;
}

if (in=='s') {  // Left movement for player
p.p_y++;
level[p.p_y][p.p_x]=2;
level[oldY][oldX]=0;
}

if (in=='d') {  // Right movement for player
p.p_x++;
level[p.p_y][p.p_x]=2;
level[oldY][oldX]=0;
}



cout << string(50, '\n');
//cout << "\n";

addmonster();



for (int row=0;row<ROW;row++) {               //Displays the level map on the screen and refreshes it with each input
for (int col=0;col<COL;col++) {
if (level[row][col]==0) cout << " . ";
if (level[row][col]==1) cout << " M ";
if (level[row][col]==2) cout << " P ";
}


cout << "\n";
}

   }





    int main()
{
cout << "           ...............WELCOME TO MONSTER HUNTER...............   " << endl;
cout << "\n";
cout << "Press 1 to hunt some monsters! Or press 2 to run to the exit! " << endl;    // Asks player to start game or exit game

cin >> response;
    if (response == 1) cout << "Welcome Monster Hunter please enter your name!"  <<endl; // Prompts player for their name
    if (response == 2) exit (0);

cin >> name;
    cout << "Right then "  << name << " it's time to hunt some monsters! " << endl;  // Displays player name and indicates
                                                                                     // begining of game
cout << "Press W to move up" << endl;
cout << "Press S to move down" << endl;
cout << "Press A to move left" << endl;
cout << "Press D to move right" << endl;
cout << "\n";
cout << "To begin move Left with A , or Up with W " << endl;
cout << "\n";

int counter = 0;


do
{
 game();
 counter++;
 cout << "\n";
 cout << "You have " << 20 - counter << " tries left" << endl;
}while(counter < 20);
  
   
return 0;
}





the only way ur gonna get proper 2D or 3D graphics in a game would be to use a graphics API such as DirectX or OpenGL
the only way ur gonna get proper 2D or 3D graphics in a game would be to use a graphics API such as DirectX or OpenGL


Agree. The closest to console GUI you can get is from someone told me in this forum to use ncurses library. It is still console but provide some resemblance of a GUI.

Or since Web is so prevalent nowadays, build your game running in the browser! Adobe Flash is often used to create interactive game effect with relative ease.
Topic archived. No new replies allowed.