Xonix C#

DANILIN

Active member
Joined
Oct 19, 2018
Messages
44
Programming Experience
10+
I program movement of XONIX
view through an array of parameters and coordinates
and main thing is that it is unclear: how to set colors
avoiding names of colors like "Red"?

Now
C#:
dav.DrawEllipse(new Pen(Color.Red, 12),x[i],y[i],f[i],f[i]);

As less than
C#:
dav.DrawEllipse(new Pen(Color.FromArgb(0,0,255,0),12), x[i]-dx[i],y[i]-dy[i],f[i],f[i]);


Plus if I set "int w=400, h=300;" window size:
"Width = w; Height = h;"
how to transfer variables to flight boundaries?

Run: inside
C:\Windows\Microsoft.NET\Framework64\v4.0.30319

xonixmult.bat
csc.exe /target:winexe xonixmult.cs
pause


xonixmult.gif
120 kB

C#:
using System; using System.Drawing; // xonixmult.cs
using System.Windows.Forms; class xonix: Form

{ public static void Main()
  { Application.Run(new xonix());}
    public xonix()

  { Text = "XONIX"; int w=400, h=300;
  BackColor = System.Drawing.Color.Blue;
  ForeColor = System.Drawing.Color.Magenta; 
  ResizeRedraw = true; Width = w; Height = h;
  }

protected override void OnPaint(PaintEventArgs and)

{ Graphics dav = and.Graphics; int n=13, a=380, b=240; 
Random rand = new Random(); int[] f = new int[n]; 
int[] x = new int[n]; int[] y = new int[n];
int[] dx = new int[n]; int[] dy = new int[n]; 
int[] c = new int[n];

for (int i=1; i<n; i++) 
{ f[i] = (2+rand.Next(3))*5; c[i] = 1+rand.Next(3);  
x[i] = rand.Next(a); y[i] = rand.Next(b); 
dx[i] = rand.Next(5)-2; dy[i] = rand.Next(5)-3; 
}

for (int k=1; k <700; k++)
for (int i=1; i<n; i++) 

{ dav.DrawEllipse(new Pen(Color.Green,12), x[i]-dx[i],y[i]-dy[i],f[i],f[i]);
 
if (1==c[i]) dav.DrawEllipse(new Pen(Color.Magenta, 12),x[i],y[i],f[i],f[i]);
if (2==c[i]) dav.DrawEllipse(new Pen(Color.Yellow, 12),x[i],y[i],f[i],f[i]);
if (3==c[i]) dav.DrawEllipse(new Pen(Color.Red, 12),x[i],y[i],f[i],f[i]);

System.Threading.Thread.Sleep(1);

if ((x[i] + dx[i] < 1) || (x[i] + dx[i] > a)) dx[i] = -dx[i];
if ((y[i] + dy[i] < 1) || (y[i] + dy[i] > b)) dy[i] = -dy[i];
x[i] += dx[i]; y[i] += dy[i];
}}}

// dav.DrawEllipse(new Pen(Color.FromArgb(0,0,255,0),12), x[i]-dx[i],y[i]-dy[i],f[i],f[i]);
 
how to set colors
avoiding names of colors like "Red"?
It looks like you already figured out how to not use the enumerated color names by specifying the RGB component values directly. What's wrong with what you came up with?

Plus if I set "int w=400, h=300;" window size:
"Width = w; Height = h;"
how to transfer variables to flight boundaries?
Your Paint() method should still have access to the form's Width and Height properties since your Paint() is still within the same class and instance of that class.
 
As an aside, I highly, highly recommend that you use the Allman indentation style for writing C# code. You're current application of 70's and 80's style BASIC of trying to pack as many statements into a line is not really appropriate anymore for modern programming.
 
Window size via single variables:
string helped strangely
C#:
public int w=550, h=330;

Added suddenly after
C#:
Width = w; Height = h;
inside its { }

And later
C#:
int n=13, a=w-40, b=h-40;

I'll post a new version of Xonix program later
in case something else changes

My indentations style: Horstmann or Pico
and exist this option inside c# develop
 
Last edited:
My indentations style: Horstmann or Pico
and exist this option inside c# develop
Yes, the option may exist in your editor but here's the recommendations:
 
It is particularly unclear why programs overload computer
starting from development environment and via bat
 
I thought that batch file was your creation. Was it from someone else? Hopefully to they have an explanation.
 

Latest posts

Back
Top Bottom