anywho making a battleships in C#i needed to generate 2 random numbers for the computer to attack, these numbers would have to be between 1 and 10 and obviously not have a pattern, so ofcourse i attempted ...
using system;
class battleships
{
public static Random rannum = new Random(10);
~ a few hundred lines of unrelated code later~
static void Computermove()
{
bool check = false;
while(!Gameover())
{
check = false;
do
{
Battleships.x = rannum.Next(10);
if (Battleships.x == 1 || Battleships.x == 2 || Battleships.x == 3 || Battleships.x == 4 || Battleships.x == 5 || Battleships.x == 6 || Battleships.x == 7 || Battleships.x == 8 || Battleships.x == 9 ||Battleships.x == 10){check = true;}
}
while(check == false);
Battleships.x2 = Battleships.x;
check = false;
do
{
Battleships.y = rannum.Next(10);
if (Battleships.y == 1 || Battleships.y == 2 || Battleships.y == 3 || Battleships.y == 4 || Battleships.y == 5 || Battleships.y == 6 || Battleships.y == 7 || Battleships.y == 8 || Battleships.y == 9 ||Battleships.y == 10){check = true;}
}
while(check == false);
Battleships.y2 = Battleships.y;
Battleships.x = (Battleships.x *2) + 1;
Console.SetCursorPosition(Battleships.x,Battleships.y);
Hitmiss();
Gameover();
Gridupdate();
}
}
running my battleships the computer seems to get stuck in the loops endlessly after the 10th move always the 10th move as well
the problem doesnt lie withing hitmiss, gameover or gridupdate as they work fine during a 2 player game.
have i done the whole random number thing wrong which im assuming it is
so i dont really know whats gone wrong help on how to fix/change or just how to do random numbers in the likely case ive done it completely wrong, would be muchly appreciated