Hilfe bei einem Kleinem Spiel --> C#

Lan_Party

BIOS-Overclocker(in)
Hey,
in unserer Klasse habe ich mit ein paar Leuten ein kleines Projekt aufgestellt.
Es soll ein Spiel werden. Das Spiel heißt "Kuhrennen" ist halt ein kleiner Insidergack. ;)
Wir müssen noch die Textboxen durch Bilder ersetzen aber wiesen nicht wie. Dazu könnte man den Code noch verkürzen oder? Dazu soll ein Ton ertönen wenn die erste "Kuh" die die Ziellinie durbrochen ist.
Eine paar Tipps und etwas Hilfe wäre schon sehr nett. :D
Ein paar verbesserungsvorschläge wären auch toll z.B. was man noch hinzufügen könnte. ^^
BTW: Es wurde alles in C# programmiert.

DL-Link: File-Upload.net - phpQ2TVnr

Code:
Kuhrennen
{
publicpartialclassForm2 : Form
{
Int32 iTipp2;
Random rndZufall;
String sKuhname2;

public Form2(Int32 iTipp, String sKuhname)
{
InitializeComponent();
iTipp2 = iTipp;
sKuhname2 = sKuhname;
rndZufall =
new System.Random();
}

privatevoid Form2_Load(object sender, EventArgs e)
{
timer1.Start();
}
privatevoid timer1_Tick(object sender, EventArgs e)
{
Int32 iBewegung;
iBewegung = rndZufall.Next(0, 2);

this.label8.Text = Convert.ToString(iTipp2);
 
//Bewegung Kuh1
if (textBox1.Location.X > 1000)
{
textBox1.Location =
newPoint(1000,this.textBox1.Location.Y);
}
this.textBox1.Location = newPoint((this.textBox1.Location.X + iBewegung), this.textBox1.Location.Y);
//Bewegung Kuh2
if (textBox2.Location.X > 1000)
{
textBox2.Location =
newPoint(1000, this.textBox2.Location.Y);
}
iBewegung = rndZufall.Next(0, 2);
this.textBox2.Location = newPoint((this.textBox2.Location.X + iBewegung), this.textBox2.Location.Y);
//Bewegung Kuh3
if (textBox3.Location.X > 1000)
{
textBox3.Location =
newPoint(1000,this.textBox3.Location.Y);
}
iBewegung = rndZufall.Next(0, 2);
this.textBox3.Location = newPoint((this.textBox3.Location.X + iBewegung), this.textBox3.Location.Y);
//Bewegung Kuh4
if (textBox4.Location.X > 1000)
{
textBox4.Location =
newPoint(1000,this.textBox4.Location.Y);
}
iBewegung = rndZufall.Next(0, 2);
this.textBox4.Location = newPoint((this.textBox4.Location.X + iBewegung), this.textBox4.Location.Y);
//Bewegung Kuh5
if (textBox5.Location.X > 1000)
{
textBox5.Location =
newPoint(1000,this.textBox5.Location.Y);
}
iBewegung = rndZufall.Next(0, 2);
this.textBox5.Location = newPoint((this.textBox5.Location.X + iBewegung), this.textBox5.Location.Y);
//Bewegung Kuh6
if (textBox6.Location.X > 1000)
{
textBox6.Location =
newPoint(1000,this.textBox6.Location.Y);
}
iBewegung = rndZufall.Next(0, 2);
this.textBox6.Location = newPoint((this.textBox6.Location.X + iBewegung), this.textBox6.Location.Y);
if (textBox1.Location.X == 999)
{
MessageBox.Show("Kuh 1 hat gewonnen");
 
Ich habe gerade keine Zeit, mir das Projekt anzusehen, aber warum definierst du für die "1000" nicht eine Klassenkonstante? Das benutzt Du ja öfter. Gewinnt immer die Kuh 1 oder gibt es noch andere MessageBoxen?
Wenn Ihr Bilder haben wollt, warum ersetzt ihr die Textboxen dann nicht mit Image?
 
Welche Klassenkonstante meinst du?
Nee insgesamt gibt es ja 6 Kühe. Es gewinnt immer eine andere.
Das mit den Images ist schon komisch. Habs mal versucht aber iwi hats nicht gefunzt. :P
Mit den Sounds komme ich überhaupt nicht klar da hatte ich keinen Durchblick mehr. :ugly:
 
Code:
public partial class Form2 :Form
{
         int konstante = 1000;
         [... bisheriger Code ... und alle 1000 durch "konstante" ersetzt ...]
}
darüber hinaus könntest du dir viel Schreibarbeit sparen, wenn du entweder die ganzen Textboxen/Images/(was auch immer du für die Spielerdarstellung nutzen möchtest) in eine Liste packst und dort nur einmal für das jeweils aktuelle Element die Aktionen durchführst:

Code:
TextBox[] _dieAnzeigesachen = new TextBox[6]; // 6 = Spielerzahl
for(int i=0;i< _dieAnzeigesachen.Length; i++)
     _dieAnzeigesachen.[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]Location = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]new[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Point[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2](([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]this[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].textBox2.Location.X + iBewegung), [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]this[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].textBox2.Location.Y); // wie auch immer dann die Bewegung machen
[/SIZE][/FONT][/SIZE][/FONT]
oder du gehtst gleich ein wenig weiter in die Objektorientierung und entwirfst dir eine kleine SpielerKlasse, deren Update-methoden du dann immer in der Tick-Methode des Timers aufrufst
Code:
class Player 
{
      TextBox _anzeigeding;
      String _name;
      static int zielkonstante = 1000;

      public Player(String pName) 
      { 
           _anzeigeding = new TextBox(); //pluss konfiguration des jeweiligen anzeigedings
           _name = pName;
      }

      public void Update()
      {
          _anzeigeding.[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]Location = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]new[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Point[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2](([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]this[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].textBox2.Location.X + iBewegung), [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]this[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].textBox2.Location.Y); // oder wie auch immer, hier dann die veränderungen zu einem Tick durchführen
       //wenn location über [/SIZE][/FONT][/SIZE][/FONT]zielkonstante [FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2], dann gewinnmeldung
    }
}
      [/SIZE][/FONT][/SIZE][/FONT]
EDIT: SOundausgabe kann dann z.B. in der Update-methode von einem Player passieren, wenn er im ziel ist. Die Methode dafür gibts glaube ich in System.Media.Soundplayer.Beep(); oder sowas ....

Editedit: siehe hier: http://dotnet-snippets.de/dns/beep-und-alarm-ausgeben-SID35.aspx
 
Kannst du vielleicht etwas hochladen, das man kompilieren kann? Außerdem wäre es noch gut zu wissen, was die Idee hinter dem Spiel ist. Ich werde aus dem Code nicht schlau.
 
Zuletzt bearbeitet:
Kannst du vielleicht etwas hochladen, das man kompilieren kann? Außerdem wäre es noch gut zu wissen, was die Idee hinter dem Spiel ist. Ich werde aus dem Code nicht schlau.

Er hat ja seinen Projektordner hochgeladen (nur die Dateiendung ist irgendwie abhanden gekommen :D ich konnts aber einfach mit 7zip entpacken)
 
Zurück