主力舰 [英] Battleship

查看:76
本文介绍了主力舰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我是C ++的新手,我正在制作战舰

计划。我需要能够输出一个只有点的屏幕,当人们没有尝试过这些点,然后能够用

切换我的数组中的字符他们被挑选后。这是我到目前为止的

代码。现在我想要做的就是制作一个游戏,你需要在不到50回合的时间内将电脑放到船上。感谢

我得到的任何帮助。


void battleShip :: play()

{

char map [8] [8];


map [0] [0] =''*'';

map [0] [ 1] =''*'';

map [0] [2] =''*'';

map [0] [3] =''x '';

map [0] [4] =''x'';

map [0] [5] =''x'';

map [0] [6] =''x'';

map [0] [7] =''x'';

map [0] [8] =''x'';


map [1] [0] =''x'';

map [1 ] [1] ='''x'';

map [1] [2] =''x'';

map [1] [3] =' 'x'';

map [1] [4] =''x'';

map [1] [5] =''x'';

map [1] [6] =''x'';

map [1] [7] =''x'';

map [1] [8] =''x'';


map [2] [0] =''x'';

map [2] [1] =''x'';

map [2] [2] =''x'';

map [2] [3] ='''x'';

map [2] [4] ='''x'';

map [2] [5] =''x'';

map [2] [6] ='' x'';

map [2] [7] =''x'';

map [2] [8] =''*'';


map [3] [0] =''x'';

map [3] [1] =''x'';

map [3] [2] =''x'';

map [3] [3] =''x'';

map [ 3] [4] ='''x'';

map [3] [5] =''*'';

map [3] [6] = ''x'';

map [3] [7] =''x'';

map [3] [8] =''*'';


map [4] [0] =''x'';

map [4] [1] =''x'';

map [4] [2] =''x'';

map [4] [3] =''x'';

map [4] [4] ='''x'';

map [4] [5] =''*'';

map [4] [6 ] ='''x'';

map [4] [7] =''x'';

map [4] [8] =''*' ';


map [5] [0] =''x'';

map [5] [1] =''x'';

map [5] [2] =''x'';

map [5] [3] =''x'';

map [5] [4] =''x'';

map [5] [5] =''*'';

map [5] [6] =''x'';

map [5] [7] ='' x'';

map [5] [8] =''x'';


map [6] [0] =''x' ';

map [6] [1] =''*'';

map [6] [2] =''*'';

map [6] [3] =''x'';

map [6] [4] =''x'';

map [ 6] [5] =''*'';

map [6] [6] =''x'';

map [6] [7] = ''x'';

map [6] [8] =''x'';


map [7] [0] ='' x'';

map [7] [1] =''x'';

map [7] [2] =''x'';

map [7] [3] =''x'';

map [7] [4] =''x'';

map [7] [5] ='''x'';

map [7] [6] =''x'';

map [7] [7 ] ='''x'';

map [7] [8] =''x'';


map [8] [0] = ''x'';

map [8] [1] =''x'';

map [8] [2] =''*'';

map [8] [3] =''*'';

map [8] [4] =''*'';

map [8] [5] =''*'';

map [8] [6] =''*'';

map [8] [7] =''x'';

map [8] [8] ='' x'';


system(" cls");

cout<< endl;

cout<< " RADAR SCREEN << endl;

cout<< " | ===================================== | " << endl;

cout<< " | 1 2 3 4 5 6 7 8 9 | " << endl;

cout<< " | 1。 。 。 。 。 。 。 。 。 | " << endl;

cout<< " | 2。 。 。 。 。 。 。 。 。 | " << endl;

cout<< " | 3。 。 。 。 。 。 。 。 。 | " << endl;

cout<< " | 4。 。 。 。 。 。 。 。 。 | " << endl;

cout<< " | 5。 。 。 。 。 。 。 。 。 | " << endl;

cout<< " | 6。 。 。 。 。 。 。 。 。 | " << endl;

cout<< " | 7。 。 。 。 。 。 。 。 。 | " << endl;

cout<< " | 8。 。 。 。 。 。 。 。 。 | " << endl;

cout<< " | 9。 。 。 。 。 。 。 。 。 | " << endl;

cout<< " | ===================================== | " << endl<< endl;

for(z = 0; z< 50; z ++)

{


cout<< "输入要触发的坐标:" ;;

cin>> x;

cin>> y;


cout<<地图[x-1] [y-1];


}


}

Hey, Im kind of new to C++ and I''m working on making a Battleship
program. I need to be able to output a screen with just dots on it for
when people havent tried those spots and then be able to switch it with
the characters in my array after they have been picked. This is the
code I have so far. Right now all all I want to do is make a game where
you have to sink the computers ships in less than 50 turns. Thanks for
any help that I get.

void battleShip::play()
{
char map [8][8];

map[0][0] = ''*'';
map[0][1] = ''*'';
map[0][2] = ''*'';
map[0][3] = ''x'';
map[0][4] = ''x'';
map[0][5] = ''x'';
map[0][6] = ''x'';
map[0][7] = ''x'';
map[0][8] = ''x'';

map[1][0] = ''x'';
map[1][1] = ''x'';
map[1][2] = ''x'';
map[1][3] = ''x'';
map[1][4] = ''x'';
map[1][5] = ''x'';
map[1][6] = ''x'';
map[1][7] = ''x'';
map[1][8] = ''x'';

map[2][0] = ''x'';
map[2][1] = ''x'';
map[2][2] = ''x'';
map[2][3] = ''x'';
map[2][4] = ''x'';
map[2][5] = ''x'';
map[2][6] = ''x'';
map[2][7] = ''x'';
map[2][8] = ''*'';

map[3][0] = ''x'';
map[3][1] = ''x'';
map[3][2] = ''x'';
map[3][3] = ''x'';
map[3][4] = ''x'';
map[3][5] = ''*'';
map[3][6] = ''x'';
map[3][7] = ''x'';
map[3][8] = ''*'';

map[4][0] = ''x'';
map[4][1] = ''x'';
map[4][2] = ''x'';
map[4][3] = ''x'';
map[4][4] = ''x'';
map[4][5] = ''*'';
map[4][6] = ''x'';
map[4][7] = ''x'';
map[4][8] = ''*'';

map[5][0] = ''x'';
map[5][1] = ''x'';
map[5][2] = ''x'';
map[5][3] = ''x'';
map[5][4] = ''x'';
map[5][5] = ''*'';
map[5][6] = ''x'';
map[5][7] = ''x'';
map[5][8] = ''x'';

map[6][0] = ''x'';
map[6][1] = ''*'';
map[6][2] = ''*'';
map[6][3] = ''x'';
map[6][4] = ''x'';
map[6][5] = ''*'';
map[6][6] = ''x'';
map[6][7] = ''x'';
map[6][8] = ''x'';

map[7][0] = ''x'';
map[7][1] = ''x'';
map[7][2] = ''x'';
map[7][3] = ''x'';
map[7][4] = ''x'';
map[7][5] = ''x'';
map[7][6] = ''x'';
map[7][7] = ''x'';
map[7][8] = ''x'';

map[8][0] = ''x'';
map[8][1] = ''x'';
map[8][2] = ''*'';
map[8][3] = ''*'';
map[8][4] = ''*'';
map[8][5] = ''*'';
map[8][6] = ''*'';
map[8][7] = ''x'';
map[8][8] = ''x'';

system("cls");
cout<< endl;
cout<< " RADAR SCREEN " <<endl;
cout<< " |=====================================| " <<endl;
cout<< " | 1 2 3 4 5 6 7 8 9 | " <<endl;
cout<< " |1 . . . . . . . . . | " <<endl;
cout<< " |2 . . . . . . . . . | " <<endl;
cout<< " |3 . . . . . . . . . | " <<endl;
cout<< " |4 . . . . . . . . . | " <<endl;
cout<< " |5 . . . . . . . . . | " <<endl;
cout<< " |6 . . . . . . . . . | " <<endl;
cout<< " |7 . . . . . . . . . | " <<endl;
cout<< " |8 . . . . . . . . . | " <<endl;
cout<< " |9 . . . . . . . . . | " <<endl;
cout<< " |=====================================| " <<endl<<endl;
for(z=0; z<50; z++)
{

cout<< " Enter the coordinates to fire at: ";
cin>> x;
cin>> y;

cout<< map[x-1][y-1];

}

}

推荐答案

gonzo86写道:
gonzo86 wrote:
嘿,我是C ++的新手,我正在制作战舰
程序。我需要能够输出一个只有点的屏幕,以便当人们没有尝试过这些点时,然后能够在拾取后用数组中的字符切换它。这是我到目前为止的代码。现在我所要做的就是做一个游戏,你必须在不到50回合的时间内将电脑放到船上。感谢
我得到的任何帮助。
Hey, Im kind of new to C++ and I''m working on making a Battleship
program. I need to be able to output a screen with just dots on it for
when people havent tried those spots and then be able to switch it with
the characters in my array after they have been picked. This is the
code I have so far. Right now all all I want to do is make a game where
you have to sink the computers ships in less than 50 turns. Thanks for
any help that I get.




我们很乐意为您提供帮助,但您的问题是什么?

Jonathan



We''d be happy to help you, but what is your question?
Jonathan


我只是不确定如何打印一个二维数组,以便它看起来像板子一样好于
有人猜到这个位置的时候能够改变它上面的不同点。

Im just not sure exactly how to print a 2d array so that it would look
like the board and be able to change the different dots on it every
time someone guessed the position.


gonzo86写道:
gonzo86 wrote:
我只是不确定如何打印一个二维阵列,以便它看起来像板子一样,并且每当有人猜到这个位置时能够改变它上面的不同点。
Im just not sure exactly how to print a 2d array so that it would look
like the board and be able to change the different dots on it every
time someone guessed the position.




请引用你要回复的信息。


我想你正在寻找一种方法来指定输出的坐标

字符;这在标准C ++中是不可能的(这是
新闻组的主题)。见

http://www.parashift.com/c++-faq-lit...html#faq-15.19
http://www.parashift.com/c++-faq-lit...t.html#faq- 5.9


了解更多信息。您可能会对标准C ++的图形化可能性感到失望,但这就是它的方式。一个标准

的方式是将网格输出一个接一个的单元格,检查它是什么,并显示正确的符号。要清除屏幕,

只需输出几个空行并再次输出整个网格。

Jonathan



Please quote the message you are answering to.

I guess you are looking for a way to specify a coordinate to output a
character; this is impossible in standard C++ (the subject of this
newsgroup). See

http://www.parashift.com/c++-faq-lit...html#faq-15.19
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

for more informations. You''ll probably be disappointed by the graphical
possibilities of standard C++, but that''s the way it is. One standard
way would be to output the grid one cell after the other, checking
what''s in it and displaying the correct symbol. To "clear the screen",
just ouput a few empty lines and output the whole grid again.
Jonathan


这篇关于主力舰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆