| | |
Penny Pitch Game
A JOptionPane version of the game of Penny Pitch. Uses numerical values spread on a board, and computer picks randomly chosen spot to place a penny and at the end of a run adds up the total score.
*Two separate programs, PennyPitchGame and Square (Square Class)*
*Two separate programs, PennyPitchGame and Square (Square Class)*
// Arman Majumder // Penny Pitch Game // Requires Square Class <Square.java> Included in bottom import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.util.Random; public class PennyPitchGame { public static void main(String[] args) { Random gen = new Random(); int totalScore = 0; int played = 0; while(true) { Square[][] PennyBoard= {{new Square(1), new Square(1), new Square(1), new Square(1), new Square(1)}, {new Square(1), new Square(2), new Square(2), new Square(2), new Square(1)}, {new Square(1), new Square(2), new Square(3), new Square(2), new Square(1)}, {new Square(1), new Square(2), new Square(2), new Square(2), new Square(1)}, {new Square(1), new Square(1), new Square(1), new Square(1), new Square(1)}}; int round = 0; int row = 0; int col = 0; int attempt = 0; String str = ""; int score = 0; boolean playAgain = true; int boardTotal = 0; while(playAgain && round < 5) { int random = gen.nextInt(25) + 1; attempt = gen.nextInt(25) + 1; row = (attempt - 1) / 5; col = (attempt - 1) % 5; str = ""; while(!PennyBoard[row][col].pennyLanded()) { if(playAgain && round == 0) { for(int row2 = 0; row2 < PennyBoard.length; row2++) { for(int col2 = 0; col2 < PennyBoard.length; col2++) { str += PennyBoard[row2][col2] + " "; } str += "\n"; } JOptionPane.showMessageDialog(null,"The Original Board: \n " + str); str = ""; } score += PennyBoard[row][col].getNumber(); PennyBoard[row][col].setPennyLanded(); round++; boardTotal++; for(int row2 = 0; row2 < PennyBoard.length; row2++) { for(int col2 = 0; col2 < PennyBoard.length; col2++) { str += PennyBoard[row2][col2] + " "; } str += "\n"; } JOptionPane.showMessageDialog(null, "The Board: \t" + boardTotal + " out of 5 \n" + str); } } totalScore += score; played++; JOptionPane.showMessageDialog(null,"Score for this round is " + score + " points"); JOptionPane.showMessageDialog(null,"Total is " + totalScore + " points"); int option = JOptionPane.showConfirmDialog(null, "¿Quitar?", "Select Option", JOptionPane.YES_NO_OPTION); if (option == 0) break; } JOptionPane.showMessageDialog(null, "Total Status: " + totalScore + " points, in " + played + " rounds."); } } ////////////////////////////////////////////////////////////////////////////////// //Square Class //New Program ///////////////////////////////////////////////////////////////////////////////// //Arman Majumder // Corresponds with Penny Pitch Game <PennyPitchGame.java> // Represents a square public class Square extends Object { private int number; private boolean pennyLanded; public Square(int n) { number = n; pennyLanded = false; } public boolean pennyLanded() { return pennyLanded; } public void setPennyLanded() { pennyLanded = true; } public int getNumber() { return number; } public String toString() { if (pennyLanded) return "P"; else return "" + number; } }
0
•
•
•
•
this is so amazing work yaar !!!!!!!
can u send me some source codes of java games?
my e mail id is nikhil_kpm83@rediffmail.com
can u send me some source codes of java games?
my e mail id is nikhil_kpm83@rediffmail.com
| Thread Tools | Search this Thread |
6 actuate android api applet application applications array arrays automation balls bank binary bluetooth bold business c++ chat class clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse educational error file formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide ideas image infinite ingres input integer intersect invokingapacheantprogrammatically j2me java javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans nextline openjavafx parameter php problem program project recursion recursive repositories scanner scrollbar server set sms sort sorting sql sqlserver state storm string sun superclass swing swt threads tree websites windows



