Can't get simple script to work :/
Im going crazy.. Can anybody explain why this is failing?
Thing I want to do is simply to make the program spit out the letters that are in there...
I suck at this :(
PS: I tried ( gameBoard[usernr1][usernr2] = {{"X"}}; ) as well but it didn't work.
Thanks in advance
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
|
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
const int x = 8;
const int y = 9;
int usernr1;
int usernr2;
char gameBoard [x][y] = {{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"}};
while (true)
{
for (int i = 1; i < x; i++)
{
cout << "-----------------------------" << endl;
cout << "| ";
for (int j = 1; j < y-1; j++)
{
Sleep(50);
cout << gameBoard[i][j];
cout << " | ";
}
cout << "\b";
cout << "\b";
cout << "\b";
cout << "\b";
cout << "\b";
cout << endl;
}
cout << "Add the X cordinate: " << endl;
cin >> usernr1;
cout << "add the y cordinate: " << endl;
cin >> usernr2;
gameBoard[usernr1][usernr2] = "X";
}
}
|
Line 44 should be
gameBoard[usernr1][usernr2] = 'X';
Thanks Chervil! :)
Hum, I'm stuck again :/
Anybody knows why I can't use "randomPick.size" at line 60? :/
Is there an error I've missed somewhere?
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include <iostream>
#include <Windows.h>
#include <vector>
#include <time.h>
using namespace std;
class randPick
{
public:
int randnr1;
int randnr2;
randPick(int _randnr1, int _randnr2)
{
randnr1 = _randnr1;
randnr2 = _randnr2;
}
};
int main()
{
srand(time(0));
int indx=-1;
int skepp;
vector<randPick>randomPick;
const int x = 8;
const int y = 9;
int usernr1;
int usernr2;
cout << "Add the ammount of ships you wish to have \nin the game. (Minimum 3 and max 10).";
cin >> skepp;
while (skepp < 3 || skepp >10)
{
cout << "\nCheck your imput, something seems to be wrong there:" << endl;
cout << "Add the ammount of ships you wish to have \nin the game. (Standard is set to 3 and max 10).";
cin >> skepp;
}
for (int i = 0; i < skepp; i++)
{
randomPick.push_back(randPick(1+rand()%7, 1+rand()%7));
cout << "x Kordinat: " << randomPick[i].randnr1 << "y kordinat: " << randomPick[i].randnr2 << endl;
}
char gameBoard [x][y] = {{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"},
{"OOOOOOOO"}};
while (true)
{
cout << "Add the X cordinate: (1-7)";
cin >> usernr2;
cout << "Add the y cordinate: (1-7)";
cin >> usernr1;
for (int i = 0; i < randomPick.size; i++)
{
{
if (gameBoard[usernr1][usernr2] = gameBoard[randomPick[i].randnr1][randomPick[i].randnr2])
cout << "You've found it!!";
indx = 1;
}
if (indx = -1)
{
cout << "Keep on tryin'!";
}
}
gameBoard[usernr1][usernr2] = 'X';
while (usernr1 > y-2 || usernr2 > x-1 || usernr1 == 0 || usernr2 == 0)
{
cout << "Check your imput, something seems to be wrong there" << endl;
cout << "Add the X cordinate: ";
cin >> usernr2;
cout << "Add the y cordinate: ";
cin >> usernr1;
gameBoard[usernr1][usernr2] = 'X';
}
for (int i = 1; i < x; i++)
{
cout << "-----------------------------" << endl;
cout << "| ";
for (int j = 1; j < y-1; j++)
{
Sleep(50);
cout << gameBoard[i][j];
cout << " | ";
}
cout << endl;
}
cout << "-----------------------------" << endl;
}
}
|
Last edited on
Topic archived. No new replies allowed.