2009-11-09 13 views
0

Je construis un jeu de BlackJack et la classe principale a un problème. Ceci est mon code:"Le modificateur de membre 'statique' doit précéder le type de membre et le nom" Erreur C#

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public class blackjack 
    { 

     static string[] playercards = new string[11]; 
     static string hitstay = ""; 
     static int total = 0, count = 1, dealertotal = 0; 
     static Random cardshuffler = new Random(); 
     static Form1 f1 = new Form1(); 
     Form1.ControlCollection 



     static void start() 
     { 
      dealertotal = cardshuffler.Next(15, 22); 
      playercards[0] = deal(); 
      playercards[1] = deal(); 

      bj(); 
     } 


     private static void hit() 
     { 

      count += 1; 
      playercards[count] = deal(); 
      f1.textBox2("you were dealed a(n) " + playercards[count] + ".your new total is " + total + "."); 
      if (total.Equals(21)) 
      { 
       f1.textBox2("you got blackjack! the dealer's total was " + dealertotal + ".would you like to play again?"); 
       playagain(); 
      } 
      else if (total > 21) 
      { 
       f1.textBox2("you busted, therefore you lost. sorry. the dealer's total was " + dealertotal + ".would you like to play again? y/n"); 
       playagain(); 
      } 
      else if (total < 21) 
      { 
       do 
       { 
        f1.textBox2("would you like to hit or stay?"); 
        hitstay = Console.ReadLine(); 
       } while (!hitstay.Equals("hit") && !hitstay.Equals("stay")); 
       bj(); 
      } 
     } 

     private static string deal() 
     { 
      string Card = ""; 
      int cards = cardshuffler.Next(1, 14); 
      switch (cards) 
      { 
       case 1: Card = "Two"; total += 2; 
        break; 
       case 2: Card = "Three"; total += 3; 
        break; 
       case 3: Card = "Four"; total += 4; 
        break; 
       case 4: Card = "Five"; total += 5; 
        break; 
       case 5: Card = "Six"; total += 6; 
        break; 
       case 6: Card = "Seven"; total += 7; 
        break; 
       case 7: Card = "Eight"; total += 8; 
        break; 
       case 8: Card = "Nine"; total += 9; 
        break; 
       case 9: Card = "Ten"; total += 10; 
        break; 
       case 10: Card = "Jack"; total += 10; 
        break; 
       case 11: Card = "Queen"; total += 10; 
        break; 
       case 12: Card = "King"; total += 10; 
        break; 
       case 13: Card = "Ace"; total += 11; 
        break; 

      } 
      return Card; 
     } 

     static void bj() 
     { 
      if (hitstay.Equals("hit")) 
      { 
       hit(); 
      } 
      else if (hitstay.Equals("stay")) 
      { 
       if (total > dealertotal && total <= 21) 
       { 
        Form1.textBox2.show("you won! the dealer busted with " + dealertotal + " as their total" + "your total was " + total); 
        playagain(); 
       } 
       else if (total < dealertotal) 
       { 
        Form1.textBox2.show("sorry, you lost! the dealer's total was " + dealertotal); 
        playagain(); 
       } 

      } 
     } 

     private static void playagain() 
     { 



     } 
    } 
} 

L'erreur est dans la ligne 21, colonne 9.

+0

Quelqu'un, veuillez corriger le balisage du code. – okutane

+0

Quelle ligne est la ligne 21? Il peut être préférable de n'afficher que l'extrait de code pertinent à l'origine du problème. – Andy

+0

Pouvez-vous corriger votre code (certains d'entre eux ne sont pas indentés correctement) et mettre en évidence la ligne où l'erreur s'est produite s'il vous plaît? Vous ne vous attendez pas vraiment à ce que les gens comptent :) –

Répondre

4

L'erreur est en fait sur la ligne 17 - cet identifiant est mis à sécher:

Form1.ControlCollection 

Soit vous vouliez déclarer un champ ou ce code ne devrait pas être là. Ce code provoque une erreur plus tard puisque l'analyseur cherche un nom de champ pour aller avec le type que vous avez mis là et suppose que votre méthode static Main est l'identifiant qui va avec.

+3

C'est l'erreur, mais le problème est beaucoup plus grand: ( – leppie

+0

merci, mais maintenant je semble avoir un autre problème. Je reçois maintenant six erreurs qui ressemblent à ceci: Membre non invocable 'WindowsFormsApplication1.Form1.textBox2' J'en ai 4. Le membre non invocable 'WindowsFormsApplication1.Form1.textBox2' ne peut pas être utilisé comme une méthode J'en ai 2. – David

1
static Form1 f1 = new Form1(); 
    Form1.ControlCollection // What is this? You forgot to write something there? 



    static void start() 

Le compilateur pense qu'il ya une déclaration qui commence par « Form1.ControlCollection » et se poursuit avec « début static void() ».

Questions connexes