Brandon/Solitaire

From ggc

Jump to: navigation, search

001 package Brandon;
002 
003 import wiki.Wiki;
004 import fang.*;
005 import java.awt.*;
006 import java.awt.geom.*;
007 
008 public class Solitaire extends GameLoop
009 {
010   private OvalSprite[][] circles = new OvalSprite[9][9];
011   private RectangleSprite[][] squares = new RectangleSprite[9][9];
012   SolitaireLogic logic = new SolitaireLogic();
013   private boolean[][] choice = new boolean[9][9];
014   private boolean first = true;
015 
016   public void startGame()
017   {
018 
019     setHelpText("Eliminate circles by 'hopping' over them <br><br> Try to remove all but one circle <br><br> R to Restart");
020     for(int = 0; i < 9; i++)
021     {
022       for(int = 0; u < 9; u++)
023       {
024         squares[i][u] = new RectangleSprite(11);
025         squares[i][u].setScale(0.1);
026         squares[i][u].setColor(Color.WHITE);
027         squares[i][u].setLocation((0.11 (+ 1)) 0.051(0.11 (+ 1)) 0.051);
028 
029         circles[i][u] = new OvalSprite(11);
030         circles[i][u].setScale(0.09);
031         circles[i][u].setColor(Color.BLUE);
032         circles[i][u].setVisible(true);
033         circles[i][u].setLocation((0.11 (+ 1)) 0.051(0.11 (+ 1)) 0.051);
034 
035         canvas.addSprite(squares[i][u], circles[i][u]);
036 
037         choice[i][u] = false;
038       }
039     }
040 
041     squares[4][4].setColor(Color.RED);
042     circles[4][4].setVisible(false);
043     logic.restart();
044   }
045 
046   public void advanceFrame(double timePassed)
047   {
048     Point2D.Double click = getPlayer().getMouse().getClickLocation();
049 
050     for(int = 0; i < 9; i++)
051     {
052       for(int = 0; u < 9; u++)
053       {
054         if(click != null && circles[i][u].intersects(click))
055         {
056           if(first)
057           {
058             if(logic.check(i, u))
059             {
060               choice[i][u] = true;
061               squares[i][u].setColor(Color.GRAY);
062               first = false;
063             }
064           }
065           else
066           {
067             if(!logic.check(i, u))
068             {
069               if((i - 2>= && choice[i - 2][u] == true)
070               {
071                 logic.trigger(i, u);
072                 logic.trigger(i - 1, u);
073                 trig(i - 2, u);
074               }
075               else if((+ 2<= && choice[+ 2][u] == true)
076               {
077                 logic.trigger(i, u);
078                 logic.trigger(+ 1, u);
079                 trig(+ 2, u);
080               }
081               else if((u - 2>= && choice[i][u - 2] == true)
082               {
083                 logic.trigger(i, u);
084                 logic.trigger(i, u - 1);
085                 trig(i, u - 2);
086               }
087               else if((+ 2<= && choice[i][+ 2] == true)
088               {
089                 logic.trigger(i, u);
090                 logic.trigger(i, u + 1);
091                 trig(i, u + 2);
092               }
093               else
094               {
095                 choice[i][u] = false;
096                 clear();
097                 first = true;
098               }
099             }
100             else
101             {
102               choice[i][u] = false;
103               clear();
104               first = true;
105             }
106 
107           }
108         }
109 
110         circles[i][u].setVisible(logic.check(i, u));
111       }
112     }
113 
114     if(getPlayer().getKeyboard().getLastKey() == 'r')
115       logic.restart();
116   }
117 
118   private void trig(int a, int b)
119   {
120     logic.trigger(a, b);
121     first = true;
122     choice[a][b] = false;
123     squares[a][b].setColor(Color.WHITE);
124   }
125 
126   private void clear()
127   {
128     for(int = 0; i < 9; i++)
129     {
130       for(int = 0; u < 9; u++)
131         squares[i][u].setColor(Color.WHITE);
132     }
133 
134     squares[4][4].setColor(Color.RED);
135   }
136 }


Download/View Brandon/Solitaire.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter