ASCII Art in Arrays?

Greetings,

Relatively new to programming here, so I hope you'll go easy on me. Not sure what else to say for now, so I'll jump right into it.

Basically, I have to write a simple command window text game for my Intro to C++ class that utilizes some functions we wrote in an earlier phase. For my game, I decided to have the player try to shoot an oncoming zombie with a cannon. The player has three attempts to take the zombie down, and I made some ASCII art to visualize its approach. Players can also knock off limbs, or punch a hole in the zombie's torso without actually killing it (and just having it cut to the victory portion of the code), and so I tried to think of a clever way to display the zombie and his potential battle wounds. What I came up with is something along the lines of using a variable that records whether individual parts of the body are present or missing, and then using that variable to assign either an array with the ASCII for that part or an array with the equivalent in spaces to a separate array I used in the output statements.

Basically:
1
2
3
4
5
6
7
8
9
10
if( head == 1)
{
   for( i = 0; i < strlen(head_intact); ++i ) // Not 100% on strlen
      print_head[i] = head_intact[i];
}
else
{
   for( i = 0; i < strlen(head_intact); ++i ) // Pretty sure it's right though?
      print_head[i] = head_missing[i];
}


After I did that for all four limbs, the torso, and the head, I did something like:
1
2
3
4
5
6
   for( i = 0; i < 4; ++i )
      cout << print_leftarm[i] << print_head[i] << endl;
   for( i = 5; i < 10; ++i )
      cout << print_leftarm[i] << print_torso[i-5] << endl;
// The left arm (on the screen, from our point of view) is raised up, and that's
// why I print it with the head first. Just go down the entire zombie like this. 


Where the problem is though (I believe), is how I've been doing the arrays. I was just trying to assign the strings to elements in a string (also tried char) array, but I think I'm approaching it wrong.

For example though, how I wanted to do it was something along the lines of:
1
2
3
4
5
6
7
8
9
10
11
string leftarm_intact[20];
leftarm_intact[0] = "  #";
leftarm_intact[1] = " # ";
leftarm_intact[2] = "#  ";

string leftarm_missing[20];
leftarm_missing[0] = "   ";
leftarm_missing[1] = "   ";
leftarm_missing[2] = "   ";

//etc 


When I used string as the type, and try to output an element it gives me the compile error:
1
2
3
4
5
6
1>        h:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(653): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]

a whole bunch of times, except the (653) changes to higher numbers as it goes.

When I used char as the type, and try to output an element it gives me the compile error:
1
2
1>[...]\source1.cpp(10) : error C2440: '=' : cannot convert from 'const char [4]' to 'char'
1>        There is no context in which this conversion is possible


for every time I try to output an element.



After searching for solutions for an extended period of time, I think the answer may lie in storing the ASCII art in 2-dimensional arrays. The problem is I can't wrap my head around how the code should look to pull this off, especially since the characters in the ASCII art are varied and have no pattern. I'm on a windows machine using Visual Studio Express Edition. Any help would be greatly appreciated, and I'm clearly not the most experienced programmer so if you could keep explanations simple I'll be your best friend.

Oh, and if requested I can also post all of my actual code (was just trying to save space with simplified examples).

Thank you very much in advance!
You do know that SDL is a very good idea for something like this.

A good tutorial:
http://lazyfoo.net/SDL_tutorials/index.php
I've actually looked into SDL a little before for different reasons (that exact tutorial actually), but due to the requirements of the assignment I think that it would go beyond the scope of what's allowed. The teacher doesn't like us using too much stuff we haven't covered in class, which unfortunately isn't a whole lot yet. Just basic things like input/output, if statements, loops, functions, arrays, etc.

Another thought that crossed my mind though was storing each line of the different parts to individual variables, and then trying to think of a simple way to output all of these variables without using a lot of code. I'll look into whether or not it's possible to use variables within variables, maybe?

So that I can use a loop and output something like variables leftarm1, leftarm2, leftarm3, etc easily instead of using them as elements in an array.

It still feels like I'm approaching things very wrong though, so any insight is welcome as always.
I didn't know it was an assignment sorry, is this the precise requirement if not what exactly do you have to do?
This isn't the precise requirement, no. I just thought I'd spice things up a bit with the ASCII art haha.. Which is proving to be almost more trouble than it's worth, but I feel too committed to bail on the idea at this stage. The actual requirement is just to make a simple game (in a command prompt window), that uses a handful of functions we made in an earlier phase of the project. The functions basically just compute the distance between two points, and ask for user input for things like angles and velocities. All stuff I plan to use when aiming the cannon at the zombie.

As far as the ASCII problem goes, I think I've figured some of the problem out. I was searching more, and came across this article:
http://stackoverflow.com/questions/1088622/how-do-i-create-an-array-of-strings-in-c

It answers my question of how to assign individual strings to individual elements in an array by doing something like:
1
2
3
4
char leftarm_intact[3][4];
strcpy(leftarm_intact[0], "  #");
strcpy(leftarm_intact[1], " # ");
strcpy(leftarm_intact[2], "#  ");

I'm still having some trouble getting it to output in a loop, though! Something about it failing to convert constants to non-constants, or vice versa. Although, I've managed to get it to work in a new project with as little code as possible! Now I just have to figure out what I'm doing incorrectly in my actual program.

I'll be sure to post again if I run into another roadblock or give closure if I actually manage to finish this thing. :)

In the words of lazy foo:
I recommend something turn based because games with motion are a whole 'nother animal.

Just posting to say that I finished the program, and it works how I wanted it to. Also, the game was turn based. The player had an infinite amount of time to enter his cannon input deciding where to shoot, and then after he fired the zombie would get closer (and if you hit the zombie anywhere, it'd properly display the missing limbs etc). I think I'm just bad at explaining my problems properly, haha. Either way, it's done now but you can expect to see more of me in the future! :)
Oh sorry I thought you were trying to do something a bit more complex.
Topic archived. No new replies allowed.