Results 1 to 7 of 7
  1. #1
    Manikyr is offline Member
    Join Date
    Jan 2009
    Posts
    17
    Rep Power
    0

    Default Help with my game!

    I can´t puzzle my blackjack game together!
    Can someone help me? I have no idea why it's not working!

    Java Code:
    // Filen Manniska.java
     import java.awt.*;
     import javax.swing.*;
    
     public class Manniska extends Spelare {
       Frame parent;
    
       public Manniska(Kortbunt k, Frame f) {
         super(k);
         parent = f;
       }
    
       public void spela() {
         boolean nyttKortÖnskas = true;
         nyttSpel();
         while (p < 21 && nyttKortÖnskas) {
           String meddelande = "Du fick " + nyttKort() +
                               " och har " + p + " poäng.";
           if (p < 21) {
             meddelande = meddelande + "\nEtt kort till?";
             JNDialog d = new JNDialog(parent, meddelande);
             d.show();
             nyttKortÖnskas = d.getAnswer().equals("Ja");
           }
           else {
             if (p == 21)
               meddelande = meddelande + "\nDu vann!";
             else
               meddelande = meddelande + "\nDu förlorade!";
             (new OKDialog(parent, meddelande)).show();
           }
         }
       }
       
     public class Dator extends Spelare {
       private Spelare motspelare;
       private Frame parent;
       public MessageDialog dial;
    
       public Dator(Kortbunt k, Spelare mot, Frame f) {
         super(k);
         motspelare = mot;
         parent = f;
       }
    
       public void spela() {
         nyttSpel();
         String medd = "";
         while (p < 21 && p < motspelare.poäng()) {
           medd += "Datorn fick " + nyttKort() + '\n';
         }
         dial = new MessageDialog(parent, medd, false);
         dial.setLocation(200, 0);
         dial.show();
       }
    
        
     }
     public abstract class Spelare {
       protected Kortbunt leken;
       protected Kortbunt hand = new Kortbunt();
       protected int p;            // aktuell poäng
       protected String symboler;  // kortens symboler
    
       public Spelare(Kortbunt k) {
         leken = k;
       }
    
       public abstract void spela();
    
       public void nyttSpel() {
         hand.slängKorten();
         p = 0;
         symboler = "";
       }
    
       public Kort nyttKort() {
         Kort k = leken.taBortÖversta();
         hand.läggÖverst(k);
         symboler += k.toSymbol() + "  ";
         // Beräkna ny poäng
         int antalEss = 0;
         p = 0;
         for (int i=0; i<hand.antalKort(); i++) {
           KortSlag s = hand.tittaPå(i).slag();
           p += s.valör;
           if (s == KortSlag.ESS)
             antalEss++;
         }
         for (int j=1; j<=antalEss && p>21; j++)
           p -= 13;  // räkna ett ess som 1
         return k;   // returnera det nya kortet
       }
    
       public int poäng() {
         return p;
       }
     }
    
     }
    Java Code:
     // Filen Tjugoett.java
     import java.awt.*;
    
     public class Tjugoett extends ExtendedFrame {
       Kortbunt lek = new Kortbunt();
       Manniska du  = new Manniska(lek, this);
       Dator    jag = new Dator(lek, du, this);
       public static void main(String[] arg) {
         Tjugoett tj = new Tjugoett();
         System.exit(0);
       }
      public enum KortSlag {
        TVÅ("2"),   TRE("3"),  FYRA("4"), FEM("5"), SEX("6"),
        SJU("7"),   ÅTTA("8"), NIO("9"),  TIO("10"),
        KNEKT("J"), DAM("Q"),  KUNG("K"), ESS("A");
        public final int valör = ordinal() + 2;
        public final String symbol;
        KortSlag(String sym) {symbol = sym;}   // konstruktor
      }
    
     public enum KortFarg {
       KLÖVER('\u2663'),  RUTER('\u2666'),
       HJÄRTER('\u2665'), SPADER('\u2660');
       public final char symbol;
       KortFarg(char c) {symbol=c;}   // konstruktor
     }
    
       // Konstruktor
       Tjugoett() {
         String s = "";
         boolean nyttPartiÖnskas = true;
         while (nyttPartiÖnskas) {
           JNDialog d = new JNDialog(this ,"");  // kompilatorn kräver initiering
           lek.nyKortlek();
           lek.blanda();
           du.spela();
           if (du.poäng() > 21)
             d = new JNDialog(this, "Nytt parti?");
           else if (du.poäng() == 21)
             d = new JNDialog(this, "Nytt parti?");
           if (du.poäng() < 21) { // datorn måste spela
             jag.spela();
             if (jag.poäng() <= 21 && jag.poäng() >= du.poäng())
               s = ". \nDu förlorade!";
             else
               s = ". \nDu vann!";
             d = new JNDialog(this, "Du fick " + du.poäng() +
                                     " och datorn " + jag.poäng() + s +
                                     "\nNytt parti?");
           }
         }
       }
            public class Kort {
       private KortFarg f;
       private KortSlag s;
    
       public Kort(KortFarg färg, KortSlag ks) {
         f = färg;
         s = ks;
       }
    
       public KortFarg färg() {
         return f;
       }
    
       public KortSlag slag() {
         return s;
       }
    
       public String toString() {
         return f.toString() + " " + s.toString();
       }
    
       public String toSymbol() {
         return f.symbol + s.symbol;
       }
     }
    
    
           d.show();
           jag.dial.setVisible(false);
           nyttPartiÖnskas = d.getAnswer().equals("Ja");
         
     }

    Java Code:
    import java.util.*;
    
     public class Kortbunt {
       private List<Kort> bunten = new LinkedList<Kort>();
       public void läggÖverst(Kort k) {
         bunten.add(0, k);
       }
    
       public  Kort taBortÖversta() {
         Kort k = bunten.get(0);
         bunten.remove(0);
         return k;
       }
    
       public int antalKort() {
         return bunten.size();
       }
    
       public void slängKorten() {
         bunten.clear();
       }
    
       public Kort tittaPå(int nr) {
         return bunten.get(nr);
       }
    
       public Kort taBort(int nr) {
         Kort k = bunten.get(nr);
         bunten.remove(nr);
         return k;
       }
    
       public int sök(KortFarg f, KortSlag s) {
         int i = 0;
         for (Kort k : bunten)
           if (k.färg()==f && k.slag()==s)
             return i;
           else
             i++;
         return -1;
       }
    
       public void nyKortlek() {
         bunten.clear();
         for (KortFarg f : KortFarg.values())
           for (KortSlag s : KortSlag.values())
             bunten.add(new Kort(f, s));
       }
    
       public void blanda() {
         Collections.shuffle(bunten);
       }
     }

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default So what's wrong?

    What problem are you having? Your code (classes, methods, variables) has words from another language and that makes it difficult to understand, so any additional information you can provide would help the people on the forum to understand your problem.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Manikyr is offline Member
    Join Date
    Jan 2009
    Posts
    17
    Rep Power
    0

    Default

    It's diffcult to describe the problem, but I can try!

    From my javabook I got pieces of the code, and now when I tried to puzzle them together it doesn't work at all. I'm afraid to touch the code to much because the book schould be right!
    So I don't know how to continue this.
    My editor tells me that some packages doesnt exist, although they does, and "cannot find symbol". I import awt, util and further, and the editors says that it's an unused import.

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Exact errors

    I think it would be best if you show the exact errors (copy & paste) that you are getting (unless it's not in English).

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    Manikyr is offline Member
    Join Date
    Jan 2009
    Posts
    17
    Rep Power
    0

    Default

    I can coby the text from a debug.
    "run:
    java.lang.ClassFormatError: Method "<error>" in class Tjugoett has illegal signature "Ld$show;"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :621)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader. java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
    Could not find the main class: Tjugoett. Program will exit.
    Exception in thread "main"
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    "

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Where does this code belong?
    Java Code:
           d.show();
           jag.dial.setVisible(false);
           nyttPartiÖnskas = d.getAnswer().equals("Ja");
    It doesn't appear to be inside of a method, and may not even be inside of a class. Instead it looks to be hanging somewhere.

  7. #7
    Manikyr is offline Member
    Join Date
    Jan 2009
    Posts
    17
    Rep Power
    0

    Default

    Now setNext and deal cannot be found!

    Java Code:
       public void startGame() {
          over = false;
          bust = false;
          deck.shuffle();  // may want to continue with existing deck until a
                           // certain number of cards are gone
          house.emptyHand();
          you.emptyHand();
          house.setNext(deck.deal());
          house.setNext(deck.deal());
          you.setNext(deck.deal());
          you.setNext(deck.deal());
          houseSum = sum(house);
          youSum = sum(you);
       }
    Here is the debug:
    debug:
    java.lang.UnsupportedOperationException: Not yet implemented
    at Hand.<init>(Hand.java:14)
    at TwentyOne.init(TwentyOne.java:98)
    at sun.applet.AppletPanel.run(AppletPanel.java:424)
    at java.lang.Thread.run(Thread.java:619)
    BUILD SUCCESSFUL (total time: 5 seconds)

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  2. Game 21
    By aRTx in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2009, 12:33 AM
  3. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM
  4. Tic Tac Game
    By loggen in forum New To Java
    Replies: 1
    Last Post: 12-12-2008, 07:36 AM
  5. game
    By amith in forum AWT / Swing
    Replies: 0
    Last Post: 05-19-2008, 05:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •