Wie verwaltet man mehrere if-Anweisungen?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie verwaltet man mehrere if-Anweisungen?

Post by Anonymous »

Ich programmiere derzeit ein Projekt mit vielen if-Anweisungen, um bestimmte Werte zu überprüfen. Ich habe das Gefühl, dass all diese Anweisungen in meinem Programm ineffizient und zeitaufwändig erscheinen. Wie kann ich das irgendwie optimieren oder verwalten?
Hinweis: Ich habe keine Erfahrung mit C# und verstehe möglicherweise viele Konzepte nicht.
Beispiel in Raylib C#:

Code: Select all

if (Raylib.IsGamepadAvailable(0) == true)
{
// looking around on gamepad
rotationV.X = Raylib.GetGamepadAxisMovement(0,GamepadAxis.RightX) * rotationS;
rotationV.Y = Raylib.GetGamepadAxisMovement(0,GamepadAxis.RightY) * rotationS;

// move on gamepad left joystick
if (Raylib.GetGamepadAxisMovement(0, GamepadAxis.LeftX) < 0)
movementV.X *= movementS;

if (Raylib.GetGamepadAxisMovement(0, GamepadAxis.LeftX) > 0)
movementV.X *= movementS;

if (Raylib.GetGamepadAxisMovement(0, GamepadAxis.LeftY) < 0)
movementV.Y *= movementS;

if (Raylib.GetGamepadAxisMovement(0, GamepadAxis.LeftY) < 0)
movementV.Y *= movementS;
}
else
{
// rotation on mouse
rotationV.X = Raylib.GetMouseDelta().X * rotationS/10;
rotationV.Y = Raylib.GetMouseDelta().Y * rotationS/10;

// move on normal controls WASD
if (Raylib.IsKeyDown(KeyboardKey.W))
movementV.Y *= movementS;

if (Raylib.IsKeyDown(KeyboardKey.S))
movementV.Y *= movementS;

if (Raylib.IsKeyDown(KeyboardKey.A))
movementV.X *= movementS;

if (Raylib.IsKeyDown(KeyboardKey.D))
movementV.X *= movementS;

movementV.X *= 0.1f;
movementV.X *= 0.1f;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post