עבור לתוכן

תוכנה בC# עובדת רק בXP ולא בויסטה

Featured Replies

פורסם

בניתי תוכנה שמדמה את מערכת השמש וכשאני מפעיל אותה רואים את הכוכבים ושאומרים להם לזוז הם נעלמים.

בXP הם זזים בצורה הנכונה.

מה הבעיה?

פורסם

קצת קשה לומר בלי לדעת שום דבר על התוכנה שלך.

פורסם
  • מחבר

מה אתה צריך שאני אשים כאן?

קוד?

פורסם

קוד, חבילות שאתה משתמש בהן, גרסאות דוטנט שמותקנות על שתי מערכות ההפעלה.

פורסם
  • מחבר

אני לא חושב שאני משתמש בשום חבילות זה ציור עם System.drawing

drawellipse

ובנוגע ל.net

איך אני בודק את הגרסא?

אני כבר אעלה את הקוד

פורסם
  • מחבר

הויסטה מעודכנת ל3.5

והאקס פי אני חושב 2.0 אני כמעט בטוח

פורסם

אז יש סיכוי שמדובר בפונקציה שמתנהגת שונה בשתי הגרסאות (בגלל באג או תיקון באג). חפש ב-msdn על הפונקציות/חבילות שבהן אתה משתמש ותראה אם אומרים משהו על זה.

פורסם
  • מחבר

קוד:

הויסטה מעודכנת ל3.5

והאקס פי אני חושב 2.0 אני כמעט בטוח

קוד:

program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
//הוספה ידנית
using System.Drawing;

namespace SolarSystem
{
static class Program
{
// יצירת כוכבי לכת ומערכת השמש
//----------------------------------------------------------------------------------------------------------------------------
// radius color x y Mass Vx Vy
//--------------------------------------------------------------------------------------------------------------------------------
public static Planets sun = new Planets( 3.0e+9f, Color.Yellow, 0 , 0, 1.989e+30f ,0.000e+00f ,0.000e+00f,0,0,0,0 );
public static Planets mars = new Planets( 1.3e+9f, Color.Red, 2.279e+11f, 0, 6.419e+23f, 0.000e+00f, 2.410e+04f, 0, 0, 0, 0);
public static Planets earth = new Planets( 2.0e+9f, Color.Blue, 1.490e+11f, 0, 5.974e+24f, 0.000e+00f, 2.98e+04f, 0, 0, 0, 0);
public static Planets mercury = new Planets(1.0e+9f, Color.White, 5.79e+10f, 0, 3.302e+23f, 0.000e+00f, 4.79e+04f, 0, 0, 0, 0);
public static Planets venus = new Planets( 1.7e+9f, Color.Green, 1.082e+11f, 0, 4.869e+24f, 0.000e+00f, 3.500e+04f, 0, 0, 0, 0);
private static Planets[] planetsArray = { sun, mercury, venus, earth, mars };
public static SolarSystem mySolarSystem = new SolarSystem(planetsArray);
public static SolidBrush myBrush = new SolidBrush(Color.White);
public static Pen myPen = new Pen(Color.White, 1);
public static Graphics Paint;
public static float xCenter = 350;
public static float yCenter = 350;
public static float zoomDistance = 1.0e-9f;
public static float zoomPlanets = 2.0e-9f;
public static float dt = 300000;



/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

solarsystem.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace SolarSystem
{
public class SolarSystem
{
private Planets[] myPlanets;
private float G = 6.67428e-11f;
public float xt1;
public float yt1;

public SolarSystem(Planets[] _myPlanets)
{
MyPlanets = _myPlanets;
}



public Planets[] MyPlanets
{
get
{
return myPlanets;
}
set
{
myPlanets = value;
}
}

public void drawMyPlanets()
{

foreach (Planets p in MyPlanets)
{
p.drawMe();
}
}



public void drawMyPlanetsBlack()
{
foreach (Planets p in MyPlanets)
{
p.drawMeBlack();
}
}



public void CalculateForces()
{

for (int i = 0; i < myPlanets.Length; i++)
{
for (int j = 0; j < myPlanets.Length; j++)
{
if(i!=j)
{
float r2=(float)(Math.Pow((myPlanets[i].X-myPlanets[j].X),2)+Math.Pow((myPlanets[i].Y-myPlanets[j].Y),2));
float F=G*((myPlanets[i].Mass)*(myPlanets[j].Mass)/r2);
float Fx=(float)(F*(myPlanets[j].X-myPlanets[i].X)/Math.Sqrt(r2));
float Fy=(float)(F*(myPlanets[j].Y-myPlanets[i].Y)/Math.Sqrt(r2));
myPlanets[i].forceX += Fx;
myPlanets[i].forceY += Fy;

}
}
}



}

public void ZeroForces()
{
for (int i = 0; i < myPlanets.Length; i++)
{
myPlanets[i].forceX = 0;
myPlanets[i].forceY = 0;
}
}
}
}

Planets.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace SolarSystem
{
public class Planets
{
public System.Drawing.Color color;
public float radius;
public float x;
public float y;
public float mass;
public float AccelerationX;
public float AccelerationY;
public float velocityX;
public float forceX = 0;
public float forceY = 0;
public float velocityY;
public float xt1;
public float yt1;

/// <summary>
/// </summary>
public float Raduis
{
get
{
return radius;
}
set
{
radius = value;
}
}

public float X
{
get
{
return x;
}
set
{
x = value;
}
}

public float Y
{
get
{
return y;
}
set
{
y = value;
}
}

/// <summary>
/// </summary>
public System.Drawing.Color Color
{
get
{
return color;
}
set
{
color = value;
}
}

public float Mass
{
get
{
return mass;
}
set
{
mass = value;
}
}




public float ForceX
{
get
{
return forceX;
}
set
{
forceX = value;
}
}

public float ForceY
{
get
{
return forceY;
}
set
{
forceY = value;
}
}

public float VelocityX
{
get
{
return velocityX;
}
set
{
velocityX = value;
}
}

public float VelocityY
{
get
{
return velocityY;
}
set
{
velocityY = value;
}
}

public float Xt1
{
get
{
return xt1;
}
set
{
xt1 = value;
}
}

public float Yt1
{
get
{
return yt1;
}
set
{
yt1 = value;
}
}

/// <summary>
/// שיטה המציירת כוכב לכת על המסך
/// </summary>
public void drawMe()
{

//שינוי צבע של כלי ציור
Program.myPen.Color = Color;
Program.myBrush.Color = Color;

//צייר כוכב הלכת
Program.Paint.DrawEllipse(Program.myPen,
Program.xCenter + X * Program.zoomDistance,//x
Program.yCenter + Y * Program.zoomDistance,//y
Raduis * 2 * Program.zoomPlanets,//גובה
Raduis * 2 * Program.zoomPlanets);//רוחב

Program.Paint.FillEllipse(Program.myBrush,
Program.xCenter + X * Program.zoomDistance,//x
Program.yCenter + Y * Program.zoomDistance,//y
Raduis * 2 * Program.zoomPlanets,//גובה
Raduis * 2 * Program.zoomPlanets);//רוחב
}

public void drawMeBlack()
{
//שינוי צבע של כלי ציור
Program.myPen.Color = System.Drawing.Color.Black;
Program.myBrush.Color = System.Drawing.Color.Black;

//צייר כוכב הלכת
Program.Paint.DrawEllipse(Program.myPen,
Program.xCenter + X * Program.zoomDistance,//x
Program.yCenter + Y * Program.zoomDistance,//y
Raduis * 2 * Program.zoomPlanets,//גובה
Raduis * 2 * Program.zoomPlanets);//רוחב

Program.Paint.FillEllipse(Program.myBrush,
Program.xCenter + X * Program.zoomDistance,//x
Program.yCenter + Y * Program.zoomDistance,//y
Raduis * 2 * Program.zoomPlanets,//גובה
Raduis * 2 * Program.zoomPlanets);//רוחב
}

public void newPosition(float dt)
{

CalculateAcceleration(dt);
CalculateVelocity(dt);

X = X + velocityX * dt;

Y = Y + velocityY * dt;

}


public void CalculateAcceleration(float dt)
{
AccelerationX = ForceX / mass;
AccelerationY = forceY / mass;
}

public void CalculateVelocity(float dt)
{
velocityX = velocityX + AccelerationX * dt;
velocityY = velocityY + AccelerationY * dt;
}

public Planets(float r, System.Drawing.Color c, float _x, float _y, float m, float FX, float FY,float VX,float VY, float xt, float yt )
{
Raduis=r;
Color=c;
X=_x;
Y=_y;
Mass = m;
ForceX = FX;
ForceY = FY;
VelocityX = VX;
VelocityY = VY;
Xt1 = xt;
Yt1 = yt;


}
}
}

form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SolarSystem
{
public partial class Form1 : Form
{
public void nextStep()
{
Program.mySolarSystem.CalculateForces();

foreach (Planets p in Program.mySolarSystem.MyPlanets)
{
p.newPosition(Program.dt);
}
Program.mySolarSystem.ZeroForces();
}

public Form1()
{
InitializeComponent();
//יצירת אובייקט צייר של הטופס
Program.Paint = this.CreateGraphics();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
Program.mySolarSystem.drawMyPlanets();


}

private void button2_Click(object sender, EventArgs e)
{
Program.mySolarSystem.drawMyPlanetsBlack();
nextStep();
Program.mySolarSystem.drawMyPlanets();
}
}
}

כשאתה אומר פונקציה, למה בדיוק אתה מתכוון בתוכנה?

לפונקציה פונקציה או System.Somthing?

פורסם

פונקציה זה פונקציה, מה זה עוד יכול להיות?

אני מתכוון לפונקציות המובנות, לא לאלה שאתה כתבת.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים