bialasik__
bialasik__
CC#
Created by bialasik__ on 3/9/2023 in #help
❔ I am trying to make a simple game in C# console.
Problem: Whenever the player character goes out of bounds/ touches the border, I get an exception. I want the player to bounce back/ stop at the border. I was thinking of resetting velocity, but this doesnt seem to work.
static void Main(string[] args)
{
Game game = new Game();

Vec playerPosition = new Vec(Console.WindowWidth / 2, Console.WindowHeight / 2);
Vec playerVelocity = new Vec(0, 0);
char playerSymbol = 'O';
GameObject player = new GameObject(playerPosition, playerVelocity, playerSymbol);
game.AddGameObject(player);

float deltaTime = 0.2f;
while (true)
{
game.Update(deltaTime);
game.Draw();

if (Console.KeyAvailable)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
if (keyInfo.Key == ConsoleKey.LeftArrow)
{
player.velocity.x = -1;
}
else if (keyInfo.Key == ConsoleKey.RightArrow)
{
player.velocity.x = 1;
}
else if (keyInfo.Key == ConsoleKey.UpArrow)
{
player.velocity.y = -1;
}
else if (keyInfo.Key == ConsoleKey.DownArrow)
{
player.velocity.y = 1;
}
}
Thread.Sleep(16);
}
static void Main(string[] args)
{
Game game = new Game();

Vec playerPosition = new Vec(Console.WindowWidth / 2, Console.WindowHeight / 2);
Vec playerVelocity = new Vec(0, 0);
char playerSymbol = 'O';
GameObject player = new GameObject(playerPosition, playerVelocity, playerSymbol);
game.AddGameObject(player);

float deltaTime = 0.2f;
while (true)
{
game.Update(deltaTime);
game.Draw();

if (Console.KeyAvailable)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
if (keyInfo.Key == ConsoleKey.LeftArrow)
{
player.velocity.x = -1;
}
else if (keyInfo.Key == ConsoleKey.RightArrow)
{
player.velocity.x = 1;
}
else if (keyInfo.Key == ConsoleKey.UpArrow)
{
player.velocity.y = -1;
}
else if (keyInfo.Key == ConsoleKey.DownArrow)
{
player.velocity.y = 1;
}
}
Thread.Sleep(16);
}
3 replies
CC#
Created by bialasik__ on 1/10/2023 in #help
❔ LinkedList
List<string> people = new()
{
"Xavier", "Alex",
"James", "Laura",
"Adil", "Cheryl",
"Charlie"
};
LinkedList<string> classList = new();

char[] alpha = "bcdefghijklmnopqrstuvwxy".ToCharArray();
foreach(string person in people)
{
LinkedListNode<string> firstNode = classList.First;
person.ToLower();
if (person.StartsWith('a'))
{
firstNode = classList.AddFirst(person);
}
else if (person.StartsWith('z'))
{
classList.AddLast(person);
}
else
{
for (int i = 0; i < alpha.Length; i++)
{
if (person.StartsWith(alpha[i]))
{
if (firstNode == null)
{
firstNode = classList.AddFirst(person);
}
classList.AddAfter(firstNode, person);
}
}
}
}
List<string> people = new()
{
"Xavier", "Alex",
"James", "Laura",
"Adil", "Cheryl",
"Charlie"
};
LinkedList<string> classList = new();

char[] alpha = "bcdefghijklmnopqrstuvwxy".ToCharArray();
foreach(string person in people)
{
LinkedListNode<string> firstNode = classList.First;
person.ToLower();
if (person.StartsWith('a'))
{
firstNode = classList.AddFirst(person);
}
else if (person.StartsWith('z'))
{
classList.AddLast(person);
}
else
{
for (int i = 0; i < alpha.Length; i++)
{
if (person.StartsWith(alpha[i]))
{
if (firstNode == null)
{
firstNode = classList.AddFirst(person);
}
classList.AddAfter(firstNode, person);
}
}
}
}
I then tried:
foreach(string person in people)
{
LinkedListNode<string> firstNode = classList.First;
person.ToLower();
if (person.StartsWith('a'))
{
classList.AddFirst(person);
}
else
{
for (int i = 0; i < alpha.Length; i++)
{
if (person.StartsWith(alpha[i]))
{
classList.AddLast(person);
}
}
}
}
foreach(string person in people)
{
LinkedListNode<string> firstNode = classList.First;
person.ToLower();
if (person.StartsWith('a'))
{
classList.AddFirst(person);
}
else
{
for (int i = 0; i < alpha.Length; i++)
{
if (person.StartsWith(alpha[i]))
{
classList.AddLast(person);
}
}
}
}
5 replies
CC#
Created by bialasik__ on 12/27/2022 in #help
❔ Lexer and parser, cannot get expressions to formulate as they should, have a look at the output...
8 replies
CC#
Created by bialasik__ on 12/23/2022 in #help
❔ Linux Mint .NET is installed but cmds such as run, new console, etc. are not recognised...
I am thinking of switching to Linux but cannot get .NET SDK and runtime installed correctly for some reason, even when following the official Microsoft documentation. They only provided instructions for Ubuntu and other distributions, but not Mint, however I read that Mint is based on Ubuntu so I don't see why this should not work. Any help would be appreciated! 🙂
6 replies
CC#
Created by bialasik__ on 12/7/2022 in #help
❔ Dereference of a possibly null reference.
do {
try {
choice = char.Parse(Console.ReadLine().ToUpper()); // <<< this line throws the warning

switch (choice) {
case 'P':
Console.WriteLine("Ok");
break;
case 'Q':
Environment.Exit(0);
break;
default:
Console.Write("Try again: ");
break;
}
}
catch (Exception) {
Console.Write("Try again: ");
}
}
while (choice != 'P' || choice != 'Q');
do {
try {
choice = char.Parse(Console.ReadLine().ToUpper()); // <<< this line throws the warning

switch (choice) {
case 'P':
Console.WriteLine("Ok");
break;
case 'Q':
Environment.Exit(0);
break;
default:
Console.Write("Try again: ");
break;
}
}
catch (Exception) {
Console.Write("Try again: ");
}
}
while (choice != 'P' || choice != 'Q');
21 replies
CC#
Created by bialasik__ on 11/17/2022 in #help
What is the difference between these two methods? Using params or just doing everything in one class
public static void Main(string[] args) {
int a = 2, b = 3;
int sum = Add(a, b)
}

public static int Add(int a, int b) {
return a + b;
}
//5 variables
public static void Main(string[] args) {
int a = 2, b = 3;
int sum = Add(a, b)
}

public static int Add(int a, int b) {
return a + b;
}
//5 variables
public static void Main(string[] args) {
int a = 2, b = 3;
int sum = a + b;
}
//3 variables
public static void Main(string[] args) {
int a = 2, b = 3;
int sum = a + b;
}
//3 variables
i just learned this in class and dont get why this is a thing
7 replies
CC#
Created by bialasik__ on 11/2/2022 in #help
My vscode is weird
4 replies
CC#
Created by bialasik__ on 10/29/2022 in #help
public static variable not changing
if (choice == 'H' && coinFlip == 1 || choice == 'T' && coinFlip == 2) { playerPawn = 'O'; // one instance where i want to change this variable PlayerTurn(); ValuesCheck(); } else { playerPawn = 'X'; ComputerTurn(); ValuesCheck(); } ############################################################## public static class Globals { public static char[,] values = { { ' ', ' ', ' ' }, { ' ', ' ', ' ' }, { ' ', ' ', ' ' } }; // this changes fine in the exact same class the other variable is but playerPawn does not public static char playerPawn = ' '; }
12 replies