BI || CrescentThief
BI || CrescentThief
CC#
Created by BI || CrescentThief on 4/22/2023 in #help
❔ Circle
// In Main (here), add code to case 5 of the switch.
// • Clear the screen.
// • Generate a random Point2D point with an x, y anywhere in the console. This point will be the center position of the circle.
// • Calculate a random radius – ensure that it will NOT extend the circle beyond the bounds of the console.
// • Use the point and radius to create a Circle instance with any color you want.
// • Call Draw on the Circle instance.

Console.Clear();
rnd = new Random();
int x = rnd.Next(0, Console.WindowWidth-1);
int y = rnd.Next(0, Console.WindowHeight-1);
Point2D point = new Point2D(x, y);
int radius = rnd.Next();
while(x + radius > Console.WindowWidth || y + radius > Console.WindowHeight || x - radius < 0 || y - radius < 0)
{
radius = rnd.Next(1, Console.WindowWidth - x);
}
Circle circle = new Circle(radius, point, ConsoleColor.Magenta);
circle.Draw();
break;
// In Main (here), add code to case 5 of the switch.
// • Clear the screen.
// • Generate a random Point2D point with an x, y anywhere in the console. This point will be the center position of the circle.
// • Calculate a random radius – ensure that it will NOT extend the circle beyond the bounds of the console.
// • Use the point and radius to create a Circle instance with any color you want.
// • Call Draw on the Circle instance.

Console.Clear();
rnd = new Random();
int x = rnd.Next(0, Console.WindowWidth-1);
int y = rnd.Next(0, Console.WindowHeight-1);
Point2D point = new Point2D(x, y);
int radius = rnd.Next();
while(x + radius > Console.WindowWidth || y + radius > Console.WindowHeight || x - radius < 0 || y - radius < 0)
{
radius = rnd.Next(1, Console.WindowWidth - x);
}
Circle circle = new Circle(radius, point, ConsoleColor.Magenta);
circle.Draw();
break;
its an assignment I already turned in but would like some feedback as to why my check for radius boundary has been very wonky, i still had exceptions being thrown for it being out of bounds on my screen.
5 replies
CC#
Created by BI || CrescentThief on 4/14/2023 in #help
❔ Learning binary searching
i linked the txt file for my entire page the part im stuck on is
//
// Part B-2: FindHero
// The method should have a string parameter for the name of the hero to find.
// Call the BinarySearch method from part A-3.
// Print the result.
// If the found index is -1,
// print "<insert heroName> is not found"
// otherwise
// print "<insert heroName> was found at index <insert found index>"
//

public void FindHero(String hero)
{
BinarySearch(_heroes);
}
//
// Part B-2: FindHero
// The method should have a string parameter for the name of the hero to find.
// Call the BinarySearch method from part A-3.
// Print the result.
// If the found index is -1,
// print "<insert heroName> is not found"
// otherwise
// print "<insert heroName> was found at index <insert found index>"
//

public void FindHero(String hero)
{
BinarySearch(_heroes);
}
10 replies
CC#
Created by BI || CrescentThief on 4/5/2023 in #help
❔ Im learning refs and outs
i keep getting cs0177 errors if someone could take a look public static void RemoveAllHeroes(string name, out List<Hero> sub) { List<Hero> _heroRem = new List<Hero>();
for (int i = 0; i < _heroes.Count; i++) { if (_heroes[i].Name.StartsWith(name, StringComparison.OrdinalIgnoreCase)) { _heroRem.Add(_heroes[i]); _heroes.RemoveAt(i); } } }
44 replies