@ -0,0 +1,73 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!-- You may freely edit this file. See commented blocks below for --> | |||||
<!-- some examples of how to customize the build. --> | |||||
<!-- (If you delete it and reopen the project it will be recreated.) --> | |||||
<!-- By default, only the Clean and Build commands use this build script. --> | |||||
<!-- Commands such as Run, Debug, and Test only use this build script if --> | |||||
<!-- the Compile on Save feature is turned off for the project. --> | |||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting --> | |||||
<!-- in the project's Project Properties dialog box.--> | |||||
<project name="SetGame" default="default" basedir="."> | |||||
<description>Builds, tests, and runs the project SetGame.</description> | |||||
<import file="nbproject/build-impl.xml"/> | |||||
<!-- | |||||
There exist several targets which are by default empty and which can be | |||||
used for execution of your tasks. These targets are usually executed | |||||
before and after some main targets. They are: | |||||
-pre-init: called before initialization of project properties | |||||
-post-init: called after initialization of project properties | |||||
-pre-compile: called before javac compilation | |||||
-post-compile: called after javac compilation | |||||
-pre-compile-single: called before javac compilation of single file | |||||
-post-compile-single: called after javac compilation of single file | |||||
-pre-compile-test: called before javac compilation of JUnit tests | |||||
-post-compile-test: called after javac compilation of JUnit tests | |||||
-pre-compile-test-single: called before javac compilation of single JUnit test | |||||
-post-compile-test-single: called after javac compilation of single JUunit test | |||||
-pre-jar: called before JAR building | |||||
-post-jar: called after JAR building | |||||
-post-clean: called after cleaning build products | |||||
(Targets beginning with '-' are not intended to be called on their own.) | |||||
Example of inserting an obfuscator after compilation could look like this: | |||||
<target name="-post-compile"> | |||||
<obfuscate> | |||||
<fileset dir="${build.classes.dir}"/> | |||||
</obfuscate> | |||||
</target> | |||||
For list of available properties check the imported | |||||
nbproject/build-impl.xml file. | |||||
Another way to customize the build is by overriding existing main targets. | |||||
The targets of interest are: | |||||
-init-macrodef-javac: defines macro for javac compilation | |||||
-init-macrodef-junit: defines macro for junit execution | |||||
-init-macrodef-debug: defines macro for class debugging | |||||
-init-macrodef-java: defines macro for class execution | |||||
-do-jar: JAR building | |||||
run: execution of project | |||||
-javadoc-build: Javadoc generation | |||||
test-report: JUnit report generation | |||||
An example of overriding the target for project execution could look like this: | |||||
<target name="run" depends="SetGame-impl.jar"> | |||||
<exec dir="bin" executable="launcher.exe"> | |||||
<arg file="${dist.jar}"/> | |||||
</exec> | |||||
</target> | |||||
Notice that the overridden target depends on the jar target and not only on | |||||
the compile target as the regular run target does. Again, for a list of available | |||||
properties which you can use, check the target you are overriding in the | |||||
nbproject/build-impl.xml file. | |||||
--> | |||||
</project> |
@ -0,0 +1,3 @@ | |||||
Manifest-Version: 1.0 | |||||
X-COMMENT: Main-Class will be added automatically by build | |||||
@ -0,0 +1,8 @@ | |||||
build.xml.data.CRC32=5fcd4e03 | |||||
build.xml.script.CRC32=c8cda4df | |||||
build.xml.stylesheet.CRC32=8064a381@1.75.2.48 | |||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. | |||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. | |||||
nbproject/build-impl.xml.data.CRC32=5fcd4e03 | |||||
nbproject/build-impl.xml.script.CRC32=10cbaf2b | |||||
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 |
@ -0,0 +1,74 @@ | |||||
annotation.processing.enabled=true | |||||
annotation.processing.enabled.in.editor=false | |||||
annotation.processing.processor.options= | |||||
annotation.processing.processors.list= | |||||
annotation.processing.run.all.processors=true | |||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output | |||||
build.classes.dir=${build.dir}/classes | |||||
build.classes.excludes=**/*.java,**/*.form | |||||
# This directory is removed when the project is cleaned: | |||||
build.dir=build | |||||
build.generated.dir=${build.dir}/generated | |||||
build.generated.sources.dir=${build.dir}/generated-sources | |||||
# Only compile against the classpath explicitly listed here: | |||||
build.sysclasspath=ignore | |||||
build.test.classes.dir=${build.dir}/test/classes | |||||
build.test.results.dir=${build.dir}/test/results | |||||
# Uncomment to specify the preferred debugger connection transport: | |||||
#debug.transport=dt_socket | |||||
debug.classpath=\ | |||||
${run.classpath} | |||||
debug.test.classpath=\ | |||||
${run.test.classpath} | |||||
# Files in build.classes.dir which should be excluded from distribution jar | |||||
dist.archive.excludes= | |||||
# This directory is removed when the project is cleaned: | |||||
dist.dir=dist | |||||
dist.jar=${dist.dir}/SetGame.jar | |||||
dist.javadoc.dir=${dist.dir}/javadoc | |||||
excludes= | |||||
includes=** | |||||
jar.compress=false | |||||
javac.classpath=\ | |||||
${libs.absolutelayout.classpath} | |||||
# Space-separated list of extra javac options | |||||
javac.compilerargs= | |||||
javac.deprecation=false | |||||
javac.processorpath=\ | |||||
${javac.classpath} | |||||
javac.source=1.8 | |||||
javac.target=1.8 | |||||
javac.test.classpath=\ | |||||
${javac.classpath}:\ | |||||
${build.classes.dir} | |||||
javac.test.processorpath=\ | |||||
${javac.test.classpath} | |||||
javadoc.additionalparam= | |||||
javadoc.author=false | |||||
javadoc.encoding=${source.encoding} | |||||
javadoc.noindex=false | |||||
javadoc.nonavbar=false | |||||
javadoc.notree=false | |||||
javadoc.private=false | |||||
javadoc.splitindex=true | |||||
javadoc.use=true | |||||
javadoc.version=false | |||||
javadoc.windowtitle= | |||||
main.class= | |||||
manifest.file=manifest.mf | |||||
meta.inf.dir=${src.dir}/META-INF | |||||
mkdist.disabled=false | |||||
platform.active=default_platform | |||||
run.classpath=\ | |||||
${javac.classpath}:\ | |||||
${build.classes.dir} | |||||
# Space-separated list of JVM arguments used when running the project. | |||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. | |||||
# To set system properties for unit tests define test-sys-prop.name=value: | |||||
run.jvmargs= | |||||
run.test.classpath=\ | |||||
${javac.test.classpath}:\ | |||||
${build.test.classes.dir} | |||||
source.encoding=UTF-8 | |||||
src.dir=src | |||||
test.src.dir=test |
@ -0,0 +1,15 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<project xmlns="http://www.netbeans.org/ns/project/1"> | |||||
<type>org.netbeans.modules.java.j2seproject</type> | |||||
<configuration> | |||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3"> | |||||
<name>SetGame</name> | |||||
<source-roots> | |||||
<root id="src.dir"/> | |||||
</source-roots> | |||||
<test-roots> | |||||
<root id="test.src.dir"/> | |||||
</test-roots> | |||||
</data> | |||||
</configuration> | |||||
</project> |
@ -0,0 +1,158 @@ | |||||
package net.jrtechs.setgame; | |||||
public class Card | |||||
{ | |||||
//color,number, shape, shading | |||||
private final int number; //0,1,2 | |||||
private final int color; //0-red,1-blue,2-green | |||||
private final int shape; //0-square,1-triangle,2-circle | |||||
private final int shading; //0-solid, 1-striped, 2-clear | |||||
private boolean inUse = true; | |||||
//constructor | |||||
Card(int num, int col, int shap, int shad) | |||||
{ | |||||
number = num; | |||||
color = col; | |||||
shape = shap; | |||||
shading = shad; | |||||
} | |||||
public int getNumber() | |||||
{ | |||||
return number; | |||||
} | |||||
public int getColor() | |||||
{ | |||||
return color; | |||||
} | |||||
public int getShape() | |||||
{ | |||||
return shape; | |||||
} | |||||
public int getShading() | |||||
{ | |||||
return shading; | |||||
} | |||||
public boolean getInUse() | |||||
{ | |||||
return inUse; | |||||
} | |||||
public void setInUse(boolean change) | |||||
{ | |||||
inUse = change; | |||||
} | |||||
public String toString() | |||||
{ | |||||
String dis = new String(); | |||||
switch(number) | |||||
{ | |||||
case 0: dis = "1"; | |||||
break; | |||||
case 1: dis = "2"; | |||||
break; | |||||
case 2: dis = "3"; | |||||
} | |||||
switch(color) | |||||
{ | |||||
case 0: dis += " red"; | |||||
break; | |||||
case 1: dis += " blue"; | |||||
break; | |||||
case 2: dis += " green"; | |||||
} | |||||
switch(shape) | |||||
{ | |||||
case 0: dis += " square"; | |||||
break; | |||||
case 1: dis += " triangle"; | |||||
break; | |||||
case 2: dis += " circle"; | |||||
} | |||||
switch(shading) | |||||
{ | |||||
case 0: dis += " solid"; | |||||
break; | |||||
case 1: dis += " striped"; | |||||
break; | |||||
case 2: dis += " clear"; | |||||
} | |||||
return dis; | |||||
} | |||||
public boolean equals(Card check) | |||||
{ | |||||
if(check.shape == this.shape && check.color == this.color && check.number == this.number && check.shading == this.shading) | |||||
{ | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
public static boolean equals(Card one, Card two, Card three) | |||||
{ | |||||
if(one.equals(two) || one.equals(three) || two.equals(three)) | |||||
{ | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
//compares the colors of three cards | |||||
public static boolean compare_color(Card one, Card two, Card three) | |||||
{ | |||||
if(one.color == two.color && one.color == three.color) | |||||
{ | |||||
return true; | |||||
} | |||||
else if(one.color != two.color && one.color != three.color && two.color != three.color) | |||||
{ | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
//compares the number of three cards | |||||
public static boolean compare_number(Card one, Card two, Card three) | |||||
{ | |||||
if(one.number == two.number && one.number == three.number) | |||||
{ | |||||
return true; | |||||
} | |||||
else if(one.number != two.number && one.number != three.number && two.number != three.number) | |||||
{ | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
//compares the shading of the three cards | |||||
public static boolean compare_shading(Card one, Card two, Card three) | |||||
{ | |||||
if(one.shading == two.shading && one.shading == three.shading) | |||||
{ | |||||
return true; | |||||
} | |||||
else if(one.shading != two.shading && one.shading != three.shading && two.shading != three.shading) | |||||
{ | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
//checks to see if three cards have the same shale | |||||
public static boolean compare_shape(Card one, Card two, Card three) | |||||
{ | |||||
if(one.shape == two.shape && one.shape == three.shape) | |||||
{ | |||||
return true; | |||||
} | |||||
else if(one.shape != two.shape && one.shape != three.shape && two.shape != three.shape) | |||||
{ | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
//checks to see if three cards are a set | |||||
public static boolean isSet(Card one, Card two, Card three) | |||||
{ | |||||
if(Card.compare_color(one, two, three) && Card.compare_number(one, two, three) && Card.compare_shading(one, two, three) && Card.compare_shape(one, two, three)) | |||||
{ | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
} |
@ -0,0 +1,58 @@ | |||||
package net.jrtechs.setgame; | |||||
import java.util.ArrayList; | |||||
public class Deck | |||||
{ | |||||
private ArrayList<Card> deck; | |||||
//constructor | |||||
Deck() | |||||
{ | |||||
deck=new ArrayList<Card>(81); | |||||
//color,number, shape, shading | |||||
for(int c = 0; c < 3; c++) | |||||
for(int n = 0; n < 3; n++) | |||||
for(int s = 0; s < 3; s++) | |||||
for(int sa = 0; sa < 3; sa++) | |||||
deck.add(new Card(c,n,s,sa)); | |||||
} | |||||
public void shuffle() | |||||
{ | |||||
int elem1, elem2; | |||||
for (int i=0; i<300; i++) | |||||
{ | |||||
elem1=(int)(Math.random()*deck.size()); | |||||
elem2=(int)(Math.random()*deck.size()); | |||||
Card temp=deck.get(elem1); | |||||
deck.set(elem1, deck.get(elem2)); | |||||
deck.set(elem2, temp); | |||||
} | |||||
} | |||||
public void display() | |||||
{ | |||||
System.out.println(deck.size()); | |||||
for(int i = 0; i < deck.size(); i++) | |||||
{ | |||||
System.out.println(deck.get(i)); | |||||
} | |||||
} | |||||
public Card[] dealMany(int num) | |||||
{ | |||||
Card[] temp=new Card[num]; | |||||
for (int i=0; i<num; i++) | |||||
{ | |||||
temp[i]=deck.remove(0); | |||||
} | |||||
return temp; | |||||
} | |||||
public Card deal() | |||||
{ | |||||
return deck.remove(0); | |||||
} | |||||
public int cardsLeft() | |||||
{ | |||||
return deck.size(); | |||||
} | |||||
} |
@ -0,0 +1,216 @@ | |||||
/* | |||||
jeffery r | |||||
12-26-15 | |||||
Game class keeps track of the score hand and deck | |||||
*/ | |||||
package net.jrtechs.setgame; | |||||
import java.awt.Color;//for colors of the buttons | |||||
import java.util.ArrayList; //for the arraylist | |||||
public class Game | |||||
{ | |||||
//properties | |||||
private Deck deck; | |||||
private Hand hand; | |||||
private int sets; | |||||
private int score; | |||||
private int setsLeft; | |||||
private int currentDisplay = 12; | |||||
private int time; | |||||
private int timeOnSet; | |||||
//constructor | |||||
Game() | |||||
{ | |||||
deck = new Deck(); | |||||
deck.shuffle(); | |||||
hand = new Hand(deck.dealMany(12)); | |||||
setsLeft = hand.setsLeft(); | |||||
sets = 0; | |||||
time = 0; | |||||
score = 0; | |||||
currentDisplay = 12; | |||||
timeOnSet = 0; | |||||
} | |||||
public void timerTic() | |||||
{ | |||||
time++; | |||||
timeOnSet++; | |||||
} | |||||
public Card[] getHand() | |||||
{ | |||||
return hand.getHand(); | |||||
} | |||||
public void clicked(SetButton[] cards) | |||||
{ | |||||
ArrayList<Card> sel; | |||||
sel = selected(cards); | |||||
if(sel.size() == 3) | |||||
{ | |||||
//there is a set selected | |||||
if(Card.isSet(sel.get(0),sel.get(1), sel.get(2))) | |||||
{ | |||||
sets++; | |||||
//calculates score to be given baised on time took and cards on board | |||||
if(currentDisplay ==12) | |||||
{ | |||||
int temp = 100 - timeOnSet; | |||||
if(temp > 0) | |||||
{ | |||||
score +=temp; | |||||
} | |||||
} | |||||
score += 50; //base score | |||||
timeOnSet = 0; | |||||
Card[] remove = {sel.get(0),sel.get(1), sel.get(2)}; | |||||
if(deck.cardsLeft() > 2) | |||||
{ | |||||
hand.removePair(remove, deck); | |||||
if(currentDisplay > 12) | |||||
{ | |||||
currentDisplay -= 3; | |||||
hand.resize(currentDisplay, deck); | |||||
for(int i = 12; i < 15; i ++) | |||||
{ | |||||
cards[i].setVisible(false); | |||||
} | |||||
} | |||||
updateBoard(cards); | |||||
} | |||||
else | |||||
{ | |||||
for(SetButton elem : cards) | |||||
{ | |||||
if(elem.getPressed()) | |||||
{ | |||||
hand.disableCard(elem.getCard()); | |||||
elem.setEnabled(false); | |||||
elem.setBackground(Color.black); | |||||
} | |||||
} | |||||
} | |||||
if(deck.cardsLeft() < 3) | |||||
{ | |||||
setsLeft = 0; | |||||
} | |||||
else | |||||
{ | |||||
setsLeft= hand.setsLeft(); | |||||
} | |||||
} | |||||
diselectCards(cards); | |||||
} | |||||
} | |||||
public void openThree(SetButton[] cards) | |||||
{ | |||||
if(currentDisplay == 12) | |||||
{ | |||||
currentDisplay += 3; | |||||
hand.resize(currentDisplay, deck); | |||||
//hand.display(); | |||||
for(int i = 12; i < cards.length; i++) | |||||
{ | |||||
cards[i].setVisible(true); | |||||
} | |||||
this.updateBoard(cards); | |||||
} | |||||
else | |||||
{ | |||||
} | |||||
} | |||||
public void updateBoard(SetButton[] cards) | |||||
{ | |||||
int count = 0; | |||||
for(Card elem : hand.getHand()) | |||||
{ | |||||
if(count >= currentDisplay) | |||||
{ | |||||
} | |||||
else | |||||
{ | |||||
cards[count].setCard(elem); | |||||
count ++; | |||||
} | |||||
} | |||||
for(SetButton elem : cards) | |||||
{ | |||||
elem.update(); | |||||
elem.setBackground(Color.white); | |||||
elem.setSelected(false); | |||||
elem.setEnabled(true); | |||||
} | |||||
} | |||||
public void findSet(SetButton[] cards) | |||||
{ | |||||
Card[] set = hand.findSet(); | |||||
for(Card elem : set) | |||||
{ | |||||
int loc = hand.location(elem); | |||||
//row * (4) + col | |||||
cards[loc].setBackground(Color.PINK); | |||||
} | |||||
} | |||||
public int getTime() | |||||
{ | |||||
return time; | |||||
} | |||||
public int getNumSets() | |||||
{ | |||||
return sets; | |||||
} | |||||
public int getScore() | |||||
{ | |||||
return score; | |||||
} | |||||
public int modScore(int change) | |||||
{ | |||||
score +=change; | |||||
return score; | |||||
} | |||||
public Deck getDeck() | |||||
{ | |||||
return deck; | |||||
} | |||||
public int getSetsLeft() | |||||
{ | |||||
setsLeft = hand.setsLeft(); | |||||
return setsLeft; | |||||
} | |||||
public void setScore(int newScore) | |||||
{ | |||||
score = newScore; | |||||
} | |||||
private void diselectCards(SetButton[] cards) | |||||
{ | |||||
for(SetButton elem : cards) | |||||
{ | |||||
if(elem.getPressed()) | |||||
{ | |||||
elem.setBackground(Color.white); | |||||
elem.setPressed(false); | |||||
} | |||||
} | |||||
} | |||||
private ArrayList<Card> selected(SetButton[] cards) | |||||
{ | |||||
ArrayList<Card> selectedCards = new ArrayList<Card>(); | |||||
for(SetButton elem : cards) | |||||
{ | |||||
if(elem.getPressed()) | |||||
{ | |||||
selectedCards.add(elem.getCard()); | |||||
} | |||||
} | |||||
return selectedCards; | |||||
} | |||||
} |
@ -0,0 +1,134 @@ | |||||
package net.jrtechs.setgame; | |||||
public class Hand | |||||
{ | |||||
private Card[] hand; | |||||
Hand(Card[] temp) | |||||
{ | |||||
hand= temp; | |||||
} | |||||
public void resize(int newSize, Deck deckT) | |||||
{ | |||||
Card[] transfer = new Card[newSize]; | |||||
int count = 0; | |||||
for(Card c: hand) | |||||
{ | |||||
if(c == null) | |||||
{ | |||||
//skip the null cards | |||||
} | |||||
else | |||||
{ | |||||
transfer[count] = c; | |||||
count++; | |||||
} | |||||
} | |||||
for(int i = count; i < newSize; i++) | |||||
{ | |||||
transfer[i] = deckT.deal(); | |||||
} | |||||
hand = transfer; | |||||
} | |||||
public Card getCard(int e) | |||||
{ | |||||
return hand[e]; | |||||
} | |||||
public void display() | |||||
{ | |||||
for(Card elem : hand) | |||||
System.out.print(elem + " "); | |||||
System.out.println(""); | |||||
} | |||||
public Card[] getHand() | |||||
{ | |||||
return hand; | |||||
} | |||||
public Card[] findSet() | |||||
{ | |||||
Card[] match = new Card[3]; | |||||
//checks each possible combination of three on the hand to find a set | |||||
for(Card one: hand) | |||||
for(Card two: hand) | |||||
for(Card three : hand) | |||||
if(Card.isSet(one, two, three) && Card.equals(one, two, three)) | |||||
if(one.getInUse() && two.getInUse() && three.getInUse()) | |||||
{ | |||||
match[0] = one; | |||||
match[1] = two; | |||||
match[2] = three; | |||||
return match; | |||||
} | |||||
return match; | |||||
} | |||||
public int setsLeft() | |||||
{ | |||||
int count = 0; | |||||
for(Card one: hand) | |||||
for(Card two: hand) | |||||
for(Card three : hand) | |||||
if(Card.isSet(one, two, three) && Card.equals(one, two, three)) | |||||
if(one.getInUse() && two.getInUse() && three.getInUse()) | |||||
count++; | |||||
//gets rid of all permutations | |||||
return count/6; | |||||
} | |||||
public int location(Card find) | |||||
{ | |||||
for(int i = 0; i < hand.length; i++) | |||||
{ | |||||
if(hand[i] == null) | |||||
{ | |||||
} | |||||
else if(find.equals(hand[i])) | |||||
{ | |||||
return i; | |||||
} | |||||
} | |||||
return -1; | |||||
} | |||||
public void removePair(Card[] remove, Deck deckT) | |||||
{ | |||||
if(deckT.cardsLeft() < 2) | |||||
{ | |||||
//not enough cards in deck to replace w/ new cards | |||||
for(Card c : remove) | |||||
{ | |||||
hand[this.location(c)] = null; | |||||
} | |||||
} | |||||
else if(hand.length > 12) | |||||
{ | |||||
for(Card c : remove) | |||||
{ | |||||
hand[location(c)] = null; | |||||
} | |||||
//condense the deck | |||||
this.resize(hand.length -3, deckT); | |||||
} | |||||
else | |||||
{ | |||||
//removes a set and replaces it with new cards | |||||
int i = 0; | |||||
Card[] replace = deckT.dealMany(remove.length); | |||||
for(Card c : remove) | |||||
{ | |||||
hand[this.location(c)] = replace[i]; | |||||
i++; | |||||
} | |||||
} | |||||
} | |||||
public void disableCard(Card c) | |||||
{ | |||||
hand[this.location(c)].setInUse(false); | |||||
} | |||||
} |
@ -0,0 +1,70 @@ | |||||
package net.jrtechs.setgame; | |||||
import java.awt.Color; | |||||
import javax.swing.JButton; | |||||
public class SetButton extends JButton | |||||
{ | |||||
private boolean pressed; | |||||
private Card card; | |||||
private int loc; | |||||
SetButton() | |||||
{ | |||||
pressed = false; | |||||
} | |||||
SetButton(int x) | |||||
{ | |||||
pressed = false; | |||||
loc = x; | |||||
} | |||||
public void clicked() | |||||
{ | |||||
if(pressed) | |||||
{ | |||||
pressed = false; | |||||
this.setBackground(Color.WHITE); | |||||
} | |||||
else | |||||
{ | |||||
this.setBackground(Color.gray); | |||||
pressed = true; | |||||
} | |||||
} | |||||
public void update() | |||||
{ | |||||
if(card == null) | |||||
{ | |||||
//do nothing | |||||
} | |||||
else | |||||
{ | |||||
//sets the image of the button baised on its properties | |||||
//images located in the /src folder, file are named as a 4 digit number | |||||
//each digit represents a property of the image(shape, number, color, shading) | |||||
String src = "/net/jrtechs/setgame/img/" + card.getShape() + card.getNumber() + card.getColor() + card.getShading() + ".png"; | |||||
//this.setText(card.toString()); | |||||
this.setIcon(new javax.swing.ImageIcon(getClass().getResource(src))); | |||||
} | |||||
} | |||||
public Card getCard() | |||||
{ | |||||
return card; | |||||
} | |||||
public void setCard(Card newCard) | |||||
{ | |||||
card = newCard; | |||||
} | |||||
public int getLoc() | |||||
{ | |||||
return loc; | |||||
} | |||||
public boolean getPressed() | |||||
{ | |||||
return pressed; | |||||
} | |||||
public void setPressed(boolean sel) | |||||
{ | |||||
pressed = sel; | |||||
} | |||||
} |
@ -0,0 +1,140 @@ | |||||
<?xml version="1.0" encoding="UTF-8" ?> | |||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | |||||
<Properties> | |||||
<Property name="defaultCloseOperation" type="int" value="3"/> | |||||
<Property name="title" type="java.lang.String" value="Set Game"/> | |||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> | |||||
<Dimension value="[670, 500]"/> | |||||
</Property> | |||||
</Properties> | |||||
<SyntheticProperties> | |||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> | |||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> | |||||
</SyntheticProperties> | |||||
<AuxValues> | |||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> | |||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> | |||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> | |||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> | |||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> | |||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> | |||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | |||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | |||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | |||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-61,0,0,2,107"/> | |||||
</AuxValues> | |||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> | |||||
<Property name="useNullLayout" type="boolean" value="false"/> | |||||
</Layout> | |||||
<SubComponents> | |||||
<Component class="javax.swing.JButton" name="cmdPlay"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Play"/> | |||||
</Properties> | |||||
<Events> | |||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmdPlayActionPerformed"/> | |||||
</Events> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> | |||||
<AbsoluteConstraints x="10" y="343" width="95" height="38"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Component class="javax.swing.JLabel" name="lblScore"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Score"/> | |||||
</Properties> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> | |||||
<AbsoluteConstraints x="390" y="350" width="-1" height="-1"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Component class="javax.swing.JLabel" name="lblSets"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Sets"/> | |||||
</Properties> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> | |||||
<AbsoluteConstraints x="260" y="350" width="-1" height="-1"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Component class="javax.swing.JLabel" name="lblCardsLeft"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Cards Left in Deck"/> | |||||
</Properties> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> | |||||
<AbsoluteConstraints x="390" y="380" width="-1" height="-1"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Component class="javax.swing.JLabel" name="lblSetsOnBoard"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Sets on board"/> | |||||
</Properties> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> | |||||
<AbsoluteConstraints x="260" y="380" width="-1" height="-1"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Component class="javax.swing.JButton" name="cmdExit"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Exit"/> | |||||
</Properties> | |||||
<Events> | |||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmdExitActionPerformed"/> | |||||
</Events> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> | |||||
<AbsoluteConstraints x="124" y="400" width="95" height="38"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Component class="javax.swing.JButton" name="cmdFindSet"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Find a Set"/> | |||||
<Property name="actionCommand" type="java.lang.String" value="cmdFindaSet"/> | |||||
</Properties> | |||||
<Events> | |||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmdFindSetActionPerformed"/> | |||||
</Events> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> | |||||
<AbsoluteConstraints x="124" y="343" width="95" height="40"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Component class="javax.swing.JButton" name="cmdOpen3"> | |||||
<Properties> | |||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> | |||||
<Font name="Tahoma" size="10" style="0"/> | |||||
</Property> | |||||
<Property name="text" type="java.lang.String" value="Open 3 Cards"/> | |||||
<Property name="toolTipText" type="java.lang.String" value=""/> | |||||
</Properties> | |||||
<Events> | |||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmdOpen3ActionPerformed"/> | |||||
</Events> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> | |||||
<AbsoluteConstraints x="10" y="400" width="95" height="38"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Component class="javax.swing.JLabel" name="lblTime"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Time"/> | |||||
</Properties> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> | |||||
<AbsoluteConstraints x="260" y="410" width="-1" height="-1"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
</SubComponents> | |||||
</Form> |
@ -0,0 +1,276 @@ | |||||
package net.jrtechs.setgame; | |||||
import javax.swing.JOptionPane; | |||||
import java.awt.event.*; | |||||
import javax.swing.Timer; | |||||
/* | |||||
jeffery R | |||||
12-26-15 | |||||
gui component for set | |||||
*/ | |||||
public class SetGame extends javax.swing.JFrame implements ActionListener | |||||
{ | |||||
private SetButton[] cards = new SetButton[15]; | |||||
private Game game; | |||||
public SetGame() | |||||
{ | |||||
initComponents(); | |||||
initSetButtons(); | |||||
showButtons(false); | |||||
cmdFindSet.setEnabled(false); | |||||
cmdOpen3.setEnabled(false); | |||||
//creates an event listener for the timer | |||||
ActionListener actTimer = new ActionListener() | |||||
{ | |||||
public void actionPerformed(ActionEvent e) | |||||
{ | |||||
if(game == null) | |||||
{ | |||||
} | |||||
else | |||||
{ | |||||
game.timerTic(); | |||||
lblTime.setText("Time " + game.getTime()); | |||||
} | |||||
} | |||||
}; | |||||
Timer timer = new Timer(1000, actTimer); | |||||
timer.start(); | |||||
} | |||||
public void showButtons(Boolean set) | |||||
{ | |||||
for(int i = 0; i < 12; i++) | |||||
{ | |||||
cards[i].setVisible(set); | |||||
} | |||||
} | |||||
private void initSetButtons() | |||||
{ | |||||
//fills the array with new SetButtons and ands action listeners | |||||
for(int i = 0; i < cards.length; i++) | |||||
{ | |||||
cards[i] = new SetButton(i); | |||||
cards[i].addActionListener(this); | |||||
} | |||||
//sets the location of each of the buttons on the absolute layout | |||||
getContentPane().add(cards[0], new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 11, 146, 84)); | |||||
getContentPane().add(cards[1], new org.netbeans.lib.awtextra.AbsoluteConstraints(172, 11, 146, 84)); | |||||
getContentPane().add(cards[2], new org.netbeans.lib.awtextra.AbsoluteConstraints(336, 11, 146, 84)); | |||||
getContentPane().add(cards[3], new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 11, 146, 84)); | |||||
getContentPane().add(cards[4], new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 121, 146, 84)); | |||||
getContentPane().add(cards[5], new org.netbeans.lib.awtextra.AbsoluteConstraints(172, 121, 146, 84)); | |||||
getContentPane().add(cards[6], new org.netbeans.lib.awtextra.AbsoluteConstraints(336, 121, 146, 84)); | |||||
getContentPane().add(cards[7], new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 121, 146, 84)); | |||||
getContentPane().add(cards[8], new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 233, 146, 84)); | |||||
getContentPane().add(cards[9], new org.netbeans.lib.awtextra.AbsoluteConstraints(172, 233, 146, 84)); | |||||
getContentPane().add(cards[10], new org.netbeans.lib.awtextra.AbsoluteConstraints(336, 233, 146, 84)); | |||||
getContentPane().add(cards[11], new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 233, 146, 84)); | |||||
getContentPane().add(cards[12], new org.netbeans.lib.awtextra.AbsoluteConstraints(664, 11, 146, 84)); | |||||
getContentPane().add(cards[13], new org.netbeans.lib.awtextra.AbsoluteConstraints(664, 121, 146, 84)); | |||||
getContentPane().add(cards[14], new org.netbeans.lib.awtextra.AbsoluteConstraints(664, 233, 146, 84)); | |||||
for(int i = 12; i < 15; i++) | |||||
{ | |||||
cards[i].setVisible(false); | |||||
} | |||||
} | |||||
public void actionPerformed(ActionEvent e) | |||||
{ | |||||
//System.out.println(e); | |||||
//casts the object of e to a setButton then calls the getLoc to find its index location in the cards "setButtons" array | |||||
SetButton clicked = (SetButton)e.getSource(); | |||||
cards[clicked.getLoc()].clicked(); | |||||
game.clicked(cards); | |||||
updateBoard(); | |||||
} | |||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents | |||||
private void initComponents() { | |||||
cmdPlay = new javax.swing.JButton(); | |||||
lblScore = new javax.swing.JLabel(); | |||||
lblSets = new javax.swing.JLabel(); | |||||
lblCardsLeft = new javax.swing.JLabel(); | |||||
lblSetsOnBoard = new javax.swing.JLabel(); | |||||
cmdExit = new javax.swing.JButton(); | |||||
cmdFindSet = new javax.swing.JButton(); | |||||
cmdOpen3 = new javax.swing.JButton(); | |||||
lblTime = new javax.swing.JLabel(); | |||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |||||
setTitle("Set Game"); | |||||
setPreferredSize(new java.awt.Dimension(670, 500)); | |||||
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); | |||||
cmdPlay.setText("Play"); | |||||
cmdPlay.addActionListener(new java.awt.event.ActionListener() { | |||||
public void actionPerformed(java.awt.event.ActionEvent evt) { | |||||
cmdPlayActionPerformed(evt); | |||||
} | |||||
}); | |||||
getContentPane().add(cmdPlay, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 343, 95, 38)); | |||||
lblScore.setText("Score"); | |||||
getContentPane().add(lblScore, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 350, -1, -1)); | |||||
lblSets.setText("Sets"); | |||||
getContentPane().add(lblSets, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 350, -1, -1)); | |||||
lblCardsLeft.setText("Cards Left in Deck"); | |||||
getContentPane().add(lblCardsLeft, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 380, -1, -1)); | |||||
lblSetsOnBoard.setText("Sets on board"); | |||||
getContentPane().add(lblSetsOnBoard, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 380, -1, -1)); | |||||
cmdExit.setText("Exit"); | |||||
cmdExit.addActionListener(new java.awt.event.ActionListener() { | |||||
public void actionPerformed(java.awt.event.ActionEvent evt) { | |||||
cmdExitActionPerformed(evt); | |||||
} | |||||
}); | |||||
getContentPane().add(cmdExit, new org.netbeans.lib.awtextra.AbsoluteConstraints(124, 400, 95, 38)); | |||||
cmdFindSet.setText("Find a Set"); | |||||
cmdFindSet.setActionCommand("cmdFindaSet"); | |||||
cmdFindSet.addActionListener(new java.awt.event.ActionListener() { | |||||
public void actionPerformed(java.awt.event.ActionEvent evt) { | |||||
cmdFindSetActionPerformed(evt); | |||||
} | |||||
}); | |||||
getContentPane().add(cmdFindSet, new org.netbeans.lib.awtextra.AbsoluteConstraints(124, 343, 95, 40)); | |||||
cmdOpen3.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N | |||||
cmdOpen3.setText("Open 3 Cards"); | |||||
cmdOpen3.setToolTipText(""); | |||||
cmdOpen3.addActionListener(new java.awt.event.ActionListener() { | |||||
public void actionPerformed(java.awt.event.ActionEvent evt) { | |||||
cmdOpen3ActionPerformed(evt); | |||||
} | |||||
}); | |||||
getContentPane().add(cmdOpen3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 400, 95, 38)); | |||||
lblTime.setText("Time"); | |||||
getContentPane().add(lblTime, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 410, -1, -1)); | |||||
pack(); | |||||
}// </editor-fold>//GEN-END:initComponents | |||||
private void cmdPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdPlayActionPerformed | |||||
cmdFindSet.setEnabled(true); | |||||
cmdOpen3.setEnabled(true); | |||||
game = new Game(); | |||||
showButtons(true); | |||||
for(int i = 12; i < 15; i++) | |||||
{ | |||||
cards[i].setVisible(false); | |||||
} | |||||
cmdPlay.setText("New Game"); | |||||
game.updateBoard(cards); | |||||
this.updateBoard(); | |||||
}//GEN-LAST:event_cmdPlayActionPerformed | |||||
private void updateBoard() | |||||
{ | |||||
lblScore.setText("Score " + game.getScore()); | |||||
lblSets.setText("Sets " + game.getNumSets()); | |||||
lblCardsLeft.setText("Cards Left in Deck " + game.getDeck().cardsLeft()); | |||||
lblSetsOnBoard.setText("Sets on board " + game.getSetsLeft()); | |||||
if(game.getSetsLeft() == 0) | |||||
{ | |||||
cmdFindSet.setEnabled(false); | |||||
endGame(); | |||||
} | |||||
else if(game.getHand().length==12 && game.getDeck().cardsLeft() > 2) | |||||
{ | |||||
cmdOpen3.setEnabled(true); | |||||
} | |||||
} | |||||
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExitActionPerformed | |||||
System.exit(-1); | |||||
}//GEN-LAST:event_cmdExitActionPerformed | |||||
private void endGame() | |||||
{ | |||||
if(game.getHand().length ==12 && game.getDeck().cardsLeft() > 3) | |||||
{ | |||||
JOptionPane.showMessageDialog(null,"There are no more sets left on the board. However, you can still open three cards.","",JOptionPane.WARNING_MESSAGE); | |||||
} | |||||
else | |||||
{ | |||||
game = null; | |||||
cmdOpen3.setEnabled(false); | |||||
JOptionPane.showMessageDialog(null,"There are no more sets left on the board.","End of Game",JOptionPane.WARNING_MESSAGE); | |||||
} | |||||
} | |||||
private void cmdFindSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdFindSetActionPerformed | |||||
game.findSet(cards); | |||||
lblScore.setText("Score " + game.modScore(-150)); | |||||
}//GEN-LAST:event_cmdFindSetActionPerformed | |||||
private void cmdOpen3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdOpen3ActionPerformed | |||||
game.openThree(cards); | |||||
cmdOpen3.setEnabled(false); | |||||
updateBoard(); | |||||
this.setBounds(0,0, 830, 480); | |||||
if(game.getSetsLeft() == 0) | |||||
{ | |||||
//end of game | |||||
endGame(); | |||||
} | |||||
else | |||||
{ | |||||
//keep on playing game | |||||
cmdFindSet.setEnabled(true); | |||||
} | |||||
}//GEN-LAST:event_cmdOpen3ActionPerformed | |||||
public static void main(String args[]) { | |||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |||||
*/ | |||||
try { | |||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | |||||
if ("Nimbus".equals(info.getName())) { | |||||
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |||||
break; | |||||
} | |||||
} | |||||
} catch (ClassNotFoundException ex) { | |||||
java.util.logging.Logger.getLogger(SetGame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} catch (InstantiationException ex) { | |||||
java.util.logging.Logger.getLogger(SetGame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} catch (IllegalAccessException ex) { | |||||
java.util.logging.Logger.getLogger(SetGame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |||||
java.util.logging.Logger.getLogger(SetGame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} | |||||
//</editor-fold> | |||||
java.awt.EventQueue.invokeLater(new Runnable() { | |||||
public void run() { | |||||
new SetGame().setVisible(true); | |||||
} | |||||
}); | |||||
} | |||||
// Variables declaration - do not modify//GEN-BEGIN:variables | |||||
private javax.swing.JButton cmdExit; | |||||
private javax.swing.JButton cmdFindSet; | |||||
private javax.swing.JButton cmdOpen3; | |||||
private javax.swing.JButton cmdPlay; | |||||
private javax.swing.JLabel lblCardsLeft; | |||||
private javax.swing.JLabel lblScore; | |||||
private javax.swing.JLabel lblSets; | |||||
private javax.swing.JLabel lblSetsOnBoard; | |||||
private javax.swing.JLabel lblTime; | |||||
// End of variables declaration//GEN-END:variables | |||||
} |