Coding a Game, Need Some Help

So I programmed this game on TI Basic and I wanted to be able to transfer it over to C++. I am not saying like, connect the TI to the computer, I will rewrite the game, but I really can't find a suitable output function.

I have it set up something like this, not exact code and definitely not a working code, but this is what I can remember:


//X and Y are going to be coordinates on screen
X stored as 1
Y stored as 1

output (X,Y,"0")

Getkey store as Z

if Z = 'up key' //I really don't remember what the up key was...
then
X-1 store as X

You get the concept. I really need to find a way to make this on C++. Can anyone help?
To help understand my thought process:
I went about making a matrix to simulate borders to a screen. I studied a Tic Tac Toe code and this is what I made of it (P.S. I just started coding like, two months ago, so nothing too crazy?):

/*Just wrote this to reassure myself, I am going at this with almost no prior knowledge/*
the code "matrix[3][3];"
makes a multi-dimensional array with an area of 9.
three rows, three columns

/* This is what I put together from the code that I saw*/
you can output whatever you want in these individual spaces using:
"cout << matrix[1][3] <<"0"; //This will output a zero at the coordinate 1,3

/*This is specific to my game, I had already made a map before I knew that there was no specific output function*/
Sooo for our game code, make a matrix of.... matrix[80][23]..? I believe
then we would have to create the map.

/*Thought process on how to move my character*/
We would start the player at a certain spot:
cout << matrix[x][y] << "Character I am using for my character";
and then, using the getchar to do:
if w is pressed, make it so matrix[x++][y]... I think?

That was my thought process..
I've made programs on those calculators too. I don't really understand what your question is, but if you want to know how to draw a map or whatever then you could do something like this if you're using windows. It's not tested but gives an idea of what to do.

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
const int SCREEN_WIDTH = 8, SCREEN_HEIGHT = 8; //whatever size it needs to be

void InitMap(char map[SCREEN_WIDTH][SCREEN_HEIGHT]) {
	for (unsigned y = 0; y < SCREEN_HEIGHT; y++) {
		for (unsigned x = 0; x < SCREEN_WIDTH; x++) {
			map[x][y] = ' ';
		}
	}
}

void DrawMap(char map[SCREEN_WIDTH][SCREEN_HEIGHT]) {
	system("cls");
	for (unsigned y = 0; y < SCREEN_HEIGHT; y++) {
		for (unsigned x = 0; x < SCREEN_WIDTH; x++) {
			cout << map[x][y];
		}
		cout << endl;
	}
}

int main() {
	char map[SCREEN_WIDTH][SCREEN_HEIGHT];
	int playerX = 3, playerY = 4;

	InitMap(map);

	while (1) {
		//Take input

		//Update player location


		map[playerX][playerY] = '@';
		DrawMap(map);
		Sleep(100);
	}
}
@Bingocat4 That was exactly what I was asking, I honestly had no idea there was a map function. Thanks, this actually helps me a lot.

You said windows, so I am guessing I need the windows.h header?
Last edited on
so I am guessing I need the windows.h header?

The code that Bingocat4 posted does not require windows.h.
It is a pure console text solution.

I honestly had no idea there was a map function

There is no "map" function. map is the name of an array in the program.

Note that the Sleep() function at line 35 is specific to Windows.

 
cout << matrix[1][3] <<"0";	//This will output a zero at the coordinate 1,3 

That comment is not correct. The above code will output the contents of cell[1][3] of matrix followed by a "0".

 
cout << matrix[x][y] << "Character I am using for my character";

Again that's not correct. That doesn't change the location to x,y. It outputs the contents of matrix[x][y] followed by the quoted string.
Last edited on
Alright, thank you. I feel kind of stupid, but I guess it makes sense.. Map being the name of the array. Oops.

Thanks though, I understand this a lot better now.
Topic archived. No new replies allowed.