p.av
p.av
CC#
Created by p.av on 12/17/2022 in #help
❔ Battleships
Hey! I'm making a battleships program. I am currently working on the boat placing and checking that they don't overlap. A computer placing a boat works and there are no problems, however, when a player places a boat there is an infinite loop. This is most likely due to something wrong in the PlacingPlayer, CheckPlacement or CheckOverlap methods:
9 replies
CC#
Created by p.av on 10/7/2022 in #help
for loop returning nothing
using System;
using static System.Console;

namespace ColouredTriangles
{
class Program
{
static void Main(string[] args)
{

WriteLine("Enter the first line");
string line = ReadLine();

while (line.Length != 1) // for loop constantly outputting ""
{
string temp = "";
for (int i = line.Length-2; i == 0; i--)
{

if (line[i] == line[i + 1])
{
temp += line[i];
}

else if (line[i].ToString() == "R")
{
if (line[i + 1].ToString() == "G")
{
temp += "B";
}
else
{
temp += "G";
}
}

else if (line[i].ToString() == "G")
{
if (line[i + 1].ToString() == "R")
{
temp += "B";
}
else
{
temp += "R";
}
}

else
{
if (line[i + 1].ToString() == "R")
{
temp += "G";
}
else
{
temp += "B";
}
}
}

WriteLine(temp);
line = temp;

}



}
}
}
using System;
using static System.Console;

namespace ColouredTriangles
{
class Program
{
static void Main(string[] args)
{

WriteLine("Enter the first line");
string line = ReadLine();

while (line.Length != 1) // for loop constantly outputting ""
{
string temp = "";
for (int i = line.Length-2; i == 0; i--)
{

if (line[i] == line[i + 1])
{
temp += line[i];
}

else if (line[i].ToString() == "R")
{
if (line[i + 1].ToString() == "G")
{
temp += "B";
}
else
{
temp += "G";
}
}

else if (line[i].ToString() == "G")
{
if (line[i + 1].ToString() == "R")
{
temp += "B";
}
else
{
temp += "R";
}
}

else
{
if (line[i + 1].ToString() == "R")
{
temp += "G";
}
else
{
temp += "B";
}
}
}

WriteLine(temp);
line = temp;

}



}
}
}
44 replies