BattleShip Arrays

Posts 1–6 of 6 · Page 1 of 1
BattleShip Arrays
Well
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;

int main(){
	int Player2board;
	int ship1;
	int ship2;
	int ship3;
	cout << " ------------------------------- " << endl;
	cout << " Welcome To ShipDestroyer V0.01 " << endl;
	cout << " ------------------------------- " << endl;
	cout << " --    PLAYER 1 SHIP BOARD    -- " << endl;
	cout << "---------------------------------" << endl;
	cout << "Enter Position Of your First Ship ( 0 -- 9 )" << endl;
	cin >> ship1;
	cout << "Enter Position Of your Second Ship ( 0 -- 9 )" << endl;
	cin >> ship2;
	cout << "Enter Position Of your Third Ship ( 0 -- 9 )" << endl;
	cin >> ship3;
	cout << "---------------" << endl;
	cout << "| GAME STARTS |" << endl;
	cout << "---------------" << endl;
	int ship11 = 5;
	int ship22 = 2;
	int ship33 = 1;
	//map1[ship1-1] = ship1;
	int map1[ 10 ][ 10 ] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
	int map2[ 10 ][ 10 ] =  {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}  ;
	map1[ship1-1][ship2-1] = ship1,ship2;
	for (int i=0; i<10; ++i){
		for (int x=0; x<10; ++x){
		cout << map1[i];
		}
		}
system("PAUSE");
}
This is my code but when I run it the 2D array dont work and I just get lots of nubmers & letters
Code:
0012FD7C
Any help?
a 10 by 10 map got 100 values not 20. you better make a function to fill the array.

Code:
map1[ship1-1][ship2-1] = ship1,ship2;
here you are giving one int variable the value of 2 int variables.
Idont know how to solve it.. xD
map 1 is a 2dimensional array of integers. it is a grid

here is a picture of a grid.
http://i41.tinypic.com/30if4ao.jpg

map1 contains 10 rows and 10 columns (rows horizontal columns vertical)
10 * 10 = 100

they are numbered this way

map1 [0][0] map1 [0][1] map1 [0][2] map1 [0][3] map1 [0][4]
map1 [1][0] map1 [1][1] map1 [1][2] map1 [1][3] map1 [1][4]
map1 [2][0] map1 [2][1] map1 [2][2] map1 [2][3] map1 [2][4]

etcetera.

i hope this is enough information to get you started
I think I now can solve this thanks
Quote Originally Posted by alvaritos View Post
I think I now can solve this thanks
they made a button for that.
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us