C
C#11mo ago
<?>

❔ stuck on a code in a console game

so basically the compiler was STUCK on a code and I got stuck on this so I thought it'd be interesting if I came here some people say the Development Environment is messed up, or try using a new IDE I made this boring console game cause I was bored btw (I use unity most of the time but I got bored this time so yes.)
19 Replies
<?>
<?>11mo ago
Program01.cs:
using RandomProgram02;

namespace RandomProgram01
{
public class Program
{
public static void Main(string[] args)
{
System.Console.WriteLine("Press M to Start, Press K to Terminate.");
while (true)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(true);

if (keyInfo.Key == ConsoleKey.M)
{
Wizard wizard = new Wizard();
wizard.Casts(); // Call Wizard.Casts;
continue;
}
else if (keyInfo.Key == ConsoleKey.K)
{
break;
}else {
continue;
}
}
}
}
}
using RandomProgram02;

namespace RandomProgram01
{
public class Program
{
public static void Main(string[] args)
{
System.Console.WriteLine("Press M to Start, Press K to Terminate.");
while (true)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(true);

if (keyInfo.Key == ConsoleKey.M)
{
Wizard wizard = new Wizard();
wizard.Casts(); // Call Wizard.Casts;
continue;
}
else if (keyInfo.Key == ConsoleKey.K)
{
break;
}else {
continue;
}
}
}
}
}
Program02.cs:
using RandomProgram01;
using System;
using System.Security.Cryptography.X509Certificates;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.ComponentModel;

namespace RandomProgram02
{
public class Wizard {
public static float EXPERIENCE = 0f;
public void Casts () {
int Cast = 4;
string Wizard01FavouriteSpell = "Chounga Bounga!";
if (Cast == 0) {
System.Console.WriteLine("You Have run Out Of Casts!");

while (true) {
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
if (keyInfo.Key == ConsoleKey.X)
{
System.Console.WriteLine("You Have Casted" + Wizard01FavouriteSpell);
Cast--;
}
}
}

if (Cast == 3) {
Wizard.EXPERIENCE++;
if (Cast == 2) {
Wizard.EXPERIENCE++;
if (Cast == 1) {
Wizard.EXPERIENCE++;
}
}
}
}
}
}
using RandomProgram01;
using System;
using System.Security.Cryptography.X509Certificates;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.ComponentModel;

namespace RandomProgram02
{
public class Wizard {
public static float EXPERIENCE = 0f;
public void Casts () {
int Cast = 4;
string Wizard01FavouriteSpell = "Chounga Bounga!";
if (Cast == 0) {
System.Console.WriteLine("You Have run Out Of Casts!");

while (true) {
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
if (keyInfo.Key == ConsoleKey.X)
{
System.Console.WriteLine("You Have Casted" + Wizard01FavouriteSpell);
Cast--;
}
}
}

if (Cast == 3) {
Wizard.EXPERIENCE++;
if (Cast == 2) {
Wizard.EXPERIENCE++;
if (Cast == 1) {
Wizard.EXPERIENCE++;
}
}
}
}
}
}
what do y'all think?
SinFluxx
SinFluxx11mo ago
you mean stuck in your infinite while loop?
<?>
<?>11mo ago
yes. stuck on this: ConsoleKeyInfo keyInfo = Console.ReadKey(true);
SinFluxx
SinFluxx11mo ago
well it's "stuck" because of this: while (true)
<?>
<?>11mo ago
what am I supposed to change it to?
SinFluxx
SinFluxx11mo ago
well a while loop carries on looping until the condition inside the parentheses is false, so if you put "true" in there it will loop infinitely (unless there's a return or break statement etc inside the loop) so what you're supposed to do is change it to a condition that at some point becomes false, which depends on what the purpose of the loop is
<?>
<?>11mo ago
well look at the while loop.
SinFluxx
SinFluxx11mo ago
Cast--; makes me think you want it to carry on until they run out of spells casts? But then you have that loop inside the if statement where they have 0 casts left already
<?>
<?>11mo ago
yes i'll change that ik I'm just focusing on the while loop
SinFluxx
SinFluxx11mo ago
yeah which is why I wanted you to explain it
<?>
<?>11mo ago
itself
SinFluxx
SinFluxx11mo ago
ok so what do you want the while loop to do?
<?>
<?>11mo ago
well M is gonna exit out of the loop. and if they press other than K/M it will continue looping.
SinFluxx
SinFluxx11mo ago
ok so you need to change it to while (pressed key != K or M)
<?>
<?>11mo ago
omg-
SinFluxx
SinFluxx11mo ago
or keep it as while (true) and inside the loop check what key's been pressed, and if it's K or M, break out of the loop
<?>
<?>11mo ago
blud, K is gonna terminate the process while M is gonna execute Program02. no errors / warnings in any of the files.
SinFluxx
SinFluxx11mo ago
why would there be? I'm not called blud either so you'd check for what key's been pressed in your loop, if it's K, return/terminate whatever, if it's M call Program02 (then what?), otherwise do whatever
Accord
Accord11mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Minimizing WPF app to system tray?Hey, Is it possible? I looked it up online but could only find very old things for win 7 and xp, a❔ Restricting mouse movementHi!, I am trying to restrict mouse movement on the area of the whole screen. I am using SetWindowsHo❔ How to force enumaration on ExpandoObj?Hey guys, i encountered a situation where i have this ExpandoObj I need to enumerate its properties ❔ DataGrid control in MauiI am migrating a WPF app to Maui and I have issues translating a WPF <DataGrid> to Maui. There doesn❔ Event-Sourcing for a Duplicated Topic between Two MicroServices@Architecture Hi friends, I'm working on a project using `Microservices` architecture, I have `Aut✅ Opinions on Node.js + C++ vs C# for app that accesses the win32 APIHello all. I'm working on an app that can control the volume of applications through a web interface❔ What is the best OCR engine for .NET?I was searching for the best OCR engine that could convert image to text or pdfsearchable..So, what ✅ Cannot figure out resolve issuehttps://github.com/mekasu0124/Diary I have attempted to resolve the issues in my 3 axaml pages. `/✅ How to resolve CS9017 when trying passing captured arguments by primary constructor to base class?I am using C# 12. The base class: ```csharp public class DbExtension(IOptionsMonitor<AppConfig> app❔ System.BadImageFormatException: Cannot load a reference assembly for execution.Hello, I'm trying to debug this exception in my C# app. I've tried solutions from stack overflow -