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
|
#include <iostream>
#include <string>
#include <array>
const std::size_t CANVAS_WIDTH = 50 ;
const std::size_t CANVAS_HEIGHT = 9 ;
using canvas_type = std::array< std::string, CANVAS_HEIGHT > ;
const std::size_t BULLET_WIDTH = 5 ;
const std::size_t BULLET_HEIGHT = 3 ;
using bullet_type = char [BULLET_HEIGHT][BULLET_WIDTH] ;
const canvas_type empty_canvas =
{{
"##############################################",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"##############################################"
}};
const bullet_type bullet =
{
{ '>', '|', '\\', ' ', ' ' },
{ ' ', '#', '#', '#', '>' },
{ '>', '|', '\\', ' ', ' ' },
};
canvas_type place_bullet( std::size_t pos, canvas_type canvas )
{
if( pos < (CANVAS_WIDTH-BULLET_WIDTH) )
{
//std::cout <<
std::size_t canvas_row = CANVAS_HEIGHT/2 - BULLET_HEIGHT/2 ;
for( std::size_t i = 0 ; i < BULLET_HEIGHT ; ++i )
{
for( std::size_t j = 0 ; j < BULLET_WIDTH ; ++j ) canvas[canvas_row][pos+j] = bullet[i][j] ;
++canvas_row ;
}
}
return canvas ;
}
void print_canvas( std::size_t bullet_pos, canvas_type canvas = empty_canvas )
{
std::cout << "\n\n" ;
for( const auto& row : place_bullet( bullet_pos, canvas ) )
{
for( char c : row ) std::cout << c ;
std::cout << '\n' ;
}
}
int main()
{
for( std::size_t bullet_pos = 5 ; bullet_pos < 30 ; bullet_pos += 8 ) print_canvas(bullet_pos) ;
}
|