C
C#5w ago
Zilly

✅ Grid Layout

else if (entercount == dialogue.Length && printcount == dialogue.Length)
{
Console.Clear();
for (int height = 0; height < 15; height++)
{
for (int width = 0; width < 17; width++)
{
Console.Write("[]");
}
}
}
else if (entercount == dialogue.Length && printcount == dialogue.Length)
{
Console.Clear();
for (int height = 0; height < 15; height++)
{
for (int width = 0; width < 17; width++)
{
Console.Write("[]");
}
}
}
37 Replies
Sebastian
Sebastian5w ago
What problems are you experiencing with your code?
Zilly
ZillyOP5w ago
flashing like this constantly
No description
Zilly
ZillyOP5w ago
I asked for help in #chat and was told to put my code here 🤷 I- frick
Sebastian
Sebastian5w ago
else if (entercount == dialogue.Length && printcount == dialogue.Length)
{
Console.Clear();
for (int height = 0; height < 15; height++)
{
for (int width = 0; width < 17; width++)
{
Console.Write("[]");
}
Console.WriteLine(); // New line here!
}
}
else if (entercount == dialogue.Length && printcount == dialogue.Length)
{
Console.Clear();
for (int height = 0; height < 15; height++)
{
for (int width = 0; width < 17; width++)
{
Console.Write("[]");
}
Console.WriteLine(); // New line here!
}
}
Zilly
ZillyOP5w ago
😔 ig we can't get rid of that unless I only call an update when something changed but that's effort so
Sebastian
Sebastian5w ago
You might be able to at least reduce the flashing (without a library)
Zilly
ZillyOP5w ago
gimme 2 minutes I'm experiencing technical difficulties man I just realised idk crap about c# maybe I should learn how to make functions first 😭
Sebastian
Sebastian5w ago
Something like this might work, haven't tested it I'm not sure you can do much better without a library or writing interop code
const int Width = 17;
const int Height = 15;

var map = new char[(Width + 1) * Height];
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x += 2)
{
int offset = (y * Width + 1) + x;
map[offset] = '[';
map[offset] = ']';
}
map[(y + 1) * Width] = '\n';
}
Console.Out.Write(map.AsSpan());
const int Width = 17;
const int Height = 15;

var map = new char[(Width + 1) * Height];
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x += 2)
{
int offset = (y * Width + 1) + x;
map[offset] = '[';
map[offset] = ']';
}
map[(y + 1) * Width] = '\n';
}
Console.Out.Write(map.AsSpan());
But if you are a beginner, you should really get the fundamentals down first Edit: if you come back to this and try to figure out why I wrote the code I wrote, here is the reason. The flashing that you are experiencing is caused by Console.Write, which is rather slow. So the idea is to write as few times as possible. You can allocate a 2D map of characters as a contiguous array (char[] instead of char[][] or char[,]) of characters. Then fill it with whatever content you want to write out. Only then call the method Write. The reason why I'm doing Console.Out.Write instead of Console.Write is because the latter doesn't support printing out arrays of characters. That would force me to do Console.Write(new string(map)), allocating a new string, which is not necessary.
Zilly
ZillyOP5w ago
uh lemme learn how to do this before I copy random code I wish to learn all of c# in -5 years fr gr this project boring I abandon just like all the others 💔💔
Sebastian
Sebastian5w ago
You can do that no problem
Zilly
ZillyOP5w ago
that's not how time works
Sebastian
Sebastian5w ago
By -5 did you mean negative five, not up to five? :kekw:
Zilly
ZillyOP5w ago
yes I meant negative 5 5 years ago I wish to be finished I can not concentrate on something for 5 years 😭 which is a real issue for me actually bc I never complete anything I have like 5 uncompleted c# projects that stopped working or became boring
Sebastian
Sebastian5w ago
Are you just doing random projects that you come up with?
Zilly
ZillyOP5w ago
yep
Sebastian
Sebastian5w ago
I've learned that way, but that was when I just coded as a hobby and wasn't rushing anywhere
Zilly
ZillyOP5w ago
I haven't really learned anything for a few months I learnt like variables and print statements and for, if and while statements and some other basic things and then nothing else
Sebastian
Sebastian5w ago
It's fine to not finish hobby projects, but you have to always do something new in them Otherwise you don't learn anything An unfinished project wasn't time wasted as long as you've learned something How about writing your own methods?
Zilly
ZillyOP5w ago
my own whats
Sebastian
Sebastian5w ago
Maybe you know them as functions
Zilly
ZillyOP5w ago
oh like uh idk an example idk how to do it in c#
Sebastian
Sebastian5w ago
A block of code; takes something in (arguments), does something (in method body) and returns some value (or void=nothing)
Zilly
ZillyOP5w ago
but in python like def blahblah(): codeystuff blahblah()
Sebastian
Sebastian5w ago
Yes
void BlahBlah()
{
// Codestuff
}

BlahBlah();
void BlahBlah()
{
// Codestuff
}

BlahBlah();
Pretty similar
Zilly
ZillyOP5w ago
ye I gotta learn that ok gimme like 17 minutes done that was simple ok I'ma translate all my python work into c# for fun
Sebastian
Sebastian5w ago
Sounds like a good way of getting to know C# syntax
Zilly
ZillyOP5w ago
ah a new issue arises query how do I test if smth is in something like
Sebastian
Sebastian5w ago
Depends on what you are trying to query. An array? A list? An enumerable? A dictionary?
Zilly
ZillyOP5w ago
string hello = "198248"
string digits = "1234567890"

if (hello in digits)
{
return true
}
string hello = "198248"
string digits = "1234567890"

if (hello in digits)
{
return true
}
a string there is no is numeric function afaik so I make one using methods 😎
Sebastian
Sebastian5w ago
There is a Contains method
Zilly
ZillyOP5w ago
what is a type that isn't void so I can return true
Sebastian
Sebastian5w ago
bool Python also has bool afaik
def get_true() -> bool:
return True
def get_true() -> bool:
return True
Zilly
ZillyOP5w ago
python lets me return whatever I want 😎 all done
namespace AC_in_C_
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the project: ");
string selector = Console.ReadLine();

switch (selector)
{
case "11":
ac11();
break;

case "21":
ac21();
break;

case "22":
ac22();
break;

case "23":
ac23();
break;

case "24":
ac24();
break;

default:
Console.WriteLine("That is not a project you dumb shit");
break;
}

}
static void ac11()
{
Console.Clear();
Console.WriteLine("Hello, World");
}
static void ac21()
{
Console.Clear();

string name = "Zilly";
string colour = "red";

Console.WriteLine($"My name is {name}");
Console.WriteLine($"My favourite colour is {colour}");
}
static void ac22()
{
Console.Clear();

Console.Write("Enter a noun: ");
string noun = Console.ReadLine();
Console.Write("Enter a verb: ");
string verb = Console.ReadLine();
Console.Write("Enter an adjective: ");
string adjective = Console.ReadLine();

Console.WriteLine($"Here's the story:\nThe {adjective} {noun} likes to {verb} in the park");
}
static void ac23()
{
Console.Clear();

Console.Write("Enter your first name: ");
string first = Console.ReadLine();
Console.Write("Enter your last name: ");
string last = Console.ReadLine();
namespace AC_in_C_
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the project: ");
string selector = Console.ReadLine();

switch (selector)
{
case "11":
ac11();
break;

case "21":
ac21();
break;

case "22":
ac22();
break;

case "23":
ac23();
break;

case "24":
ac24();
break;

default:
Console.WriteLine("That is not a project you dumb shit");
break;
}

}
static void ac11()
{
Console.Clear();
Console.WriteLine("Hello, World");
}
static void ac21()
{
Console.Clear();

string name = "Zilly";
string colour = "red";

Console.WriteLine($"My name is {name}");
Console.WriteLine($"My favourite colour is {colour}");
}
static void ac22()
{
Console.Clear();

Console.Write("Enter a noun: ");
string noun = Console.ReadLine();
Console.Write("Enter a verb: ");
string verb = Console.ReadLine();
Console.Write("Enter an adjective: ");
string adjective = Console.ReadLine();

Console.WriteLine($"Here's the story:\nThe {adjective} {noun} likes to {verb} in the park");
}
static void ac23()
{
Console.Clear();

Console.Write("Enter your first name: ");
string first = Console.ReadLine();
Console.Write("Enter your last name: ");
string last = Console.ReadLine();
Console.WriteLine($"Your initials are {first[0]}.{last[0]}");
}
static void ac24()
{
Console.Clear();

Console.Write("Enter your year of birth: ");
int YearOfBirth = int.Parse(Console.ReadLine());
Console.Write("Enter the current year: ");
int Year = int.Parse(Console.ReadLine());

Console.WriteLine($"You are {Year-YearOfBirth} years old");
}
}
}
Console.WriteLine($"Your initials are {first[0]}.{last[0]}");
}
static void ac24()
{
Console.Clear();

Console.Write("Enter your year of birth: ");
int YearOfBirth = int.Parse(Console.ReadLine());
Console.Write("Enter the current year: ");
int Year = int.Parse(Console.ReadLine());

Console.WriteLine($"You are {Year-YearOfBirth} years old");
}
}
}
very nice method: simples I also learnt switch-case which was also simple I fall asleep now goodnight peeps Oh I also learnt what int.Parse is Ok bye now
Sebastian
Sebastian5w ago
Works similarly to how int() works in Python int value = int.Parse("100"); You did a fine job
Zilly
ZillyOP5w ago
Yippee I learnt new stuff
DevastatedMan
DevastatedMan5w ago
I just learned int.parse in Dart today an it works the SAME in C#😅

Did you find this page helpful?