-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fishy
committed
Jan 21, 2019
0 parents
commit 258a919
Showing
31 changed files
with
3,042 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
ompiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Aaryan Prakash | ||
// 4/27/18 | ||
// Alerts.java | ||
// This is the JTextArea for telling the user what is going on in the game. | ||
|
||
import javax.swing.JTextArea; | ||
|
||
import java.awt.Font; | ||
|
||
public class Alerts extends JTextArea | ||
{ | ||
private Font sansSerif30; // Arial font, size 28 | ||
private int numAlerts; // tells number of alerts created | ||
private String[] alerts; // stores 3 previous alerts | ||
|
||
// creates JTextArea | ||
public Alerts() | ||
{ | ||
super(" Alerts:\n", 12, 35); | ||
alerts = new String[]{"", "", ""}; | ||
numAlerts = 0; | ||
sansSerif30 = new Font("Arial", Font.PLAIN, 28); | ||
setFont(sansSerif30); | ||
setEditable(false); | ||
} | ||
|
||
// adds alert to alerts array | ||
public void addAlert(String newAlert) | ||
{ | ||
numAlerts++; | ||
if (numAlerts == 1) | ||
{ | ||
alerts[0] = newAlert; | ||
} | ||
else if (numAlerts == 2) | ||
{ | ||
alerts[1] = newAlert; | ||
} | ||
else if (numAlerts == 3) | ||
{ | ||
alerts[2] = newAlert; | ||
} | ||
else | ||
{ | ||
alerts[0] = alerts[1]; | ||
alerts[1] = alerts[2]; | ||
alerts[2] = newAlert; | ||
} | ||
|
||
showAlerts(); | ||
} | ||
|
||
// shows the new alerts queue in the JTextArea | ||
public void showAlerts() | ||
{ | ||
String text = " Alerts:\n\n " + alerts[0] + "\n " + alerts[1] | ||
+ "\n " + alerts[2]; | ||
setText(text); | ||
} | ||
|
||
// resets alerts to an empty state | ||
public void resetAlerts() | ||
{ | ||
alerts[0] = ""; | ||
alerts[1] = ""; | ||
alerts[2] = ""; | ||
showAlerts(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Aaryan Prakash | ||
// 5/4/18 | ||
// AnswerChoice.java | ||
// This is the variable that represents an answer choice for a radio button. | ||
|
||
public class AnswerChoice | ||
{ | ||
private final int CORRECT = 0; // represents a correct answer | ||
private final int ALTERNATE = 1; // represents alternate answer | ||
private final int WRONG = 2; // represents wrong answer | ||
|
||
private String name; // name of the choice | ||
private int correctness; // tells if ans is right/wrong | ||
private String reason; // reason that given answer is right/wrong | ||
|
||
// gives value to field variables | ||
public AnswerChoice(String nameIn, int correctIn, String reasonIn) | ||
{ | ||
name = nameIn; | ||
correctness = correctIn; | ||
reason = reasonIn; | ||
} | ||
|
||
// returns name of answer choice | ||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
// gets int that represents correctness | ||
public int getCorrect() | ||
{ | ||
return correctness; | ||
} | ||
|
||
// returns reason | ||
public String getReason() | ||
{ | ||
return reason; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
// Aaryan Prakash | ||
// 10/24/18 | ||
// Board.java | ||
// Holds all the tiles that make up the game board. Changes the tiles | ||
// when a move made. | ||
|
||
import javax.swing.JPanel; | ||
import javax.swing.JButton; // remove later | ||
|
||
import java.awt.GridLayout; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.Color; | ||
import java.awt.Dimension; | ||
|
||
public class Board extends JPanel | ||
{ | ||
// used to tell which token to move (name changed for ease in reading) | ||
private boolean BLUE_TOKEN = true; | ||
private boolean RED_TOKEN = false; | ||
|
||
private Tile[] boardTiles; // panels for each square of the game board | ||
// indexed from 0-100, 0th tile is ignored | ||
|
||
// sets values of panel and adds game board tiles | ||
public Board() | ||
{ | ||
setLayout(new GridLayout(10, 10, 0, 0)); | ||
setPreferredSize(new Dimension(800, 800)); | ||
|
||
boardTiles = new Tile[101]; | ||
|
||
// loops over each row of board | ||
for (int i = 9; i >= 0; i--) | ||
{ | ||
if (i % 2 == 0) | ||
{ | ||
for (int j = 1; j <= 10; j++) | ||
{ | ||
addTile(10 * i + j); | ||
} | ||
} | ||
else | ||
{ | ||
for (int j = 10; j > 0; j--) | ||
{ | ||
addTile(10 * i + j); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// method to create tile, add to array, and add to panel | ||
public void addTile(int pos) | ||
{ | ||
Tile tileToAdd = new Tile(pos); | ||
boardTiles[pos] = tileToAdd; | ||
add(tileToAdd); | ||
} | ||
|
||
// moves the token forward | ||
public void moveForward(boolean whichToken, int originalPos, int stepsForward) | ||
{ | ||
int newPos = Math.min(originalPos + stepsForward, 100); | ||
|
||
if (whichToken == BLUE_TOKEN) | ||
{ | ||
boardTiles[originalPos].blueTokenOn(false); | ||
boardTiles[originalPos].repaint(); | ||
boardTiles[newPos].blueTokenOn(true); | ||
boardTiles[newPos].repaint(); | ||
} | ||
else | ||
{ | ||
boardTiles[originalPos].redTokenOn(false); | ||
boardTiles[originalPos].repaint(); | ||
boardTiles[newPos].redTokenOn(true); | ||
boardTiles[newPos].repaint(); | ||
} | ||
} | ||
|
||
// resets board to initial condition | ||
public void reset(int curBluePos, int curRedPos) | ||
{ | ||
boardTiles[curBluePos].blueTokenOn(false); | ||
boardTiles[curBluePos].repaint(); | ||
|
||
boardTiles[curRedPos].redTokenOn(false); | ||
boardTiles[curRedPos].repaint(); | ||
|
||
boardTiles[1].blueTokenOn(true); | ||
boardTiles[1].redTokenOn(true); | ||
boardTiles[1].repaint(); | ||
} | ||
|
||
// JPanel class for each tile of the gameboard | ||
class Tile extends JPanel | ||
{ | ||
private int tileNum; // number shown on tile | ||
private boolean hasBlue; // tells if blue token is on it | ||
private boolean hasRed; // tells if red token is on it | ||
|
||
// sets number and color | ||
// if it is the first tile, tells blue and red tokens are on it | ||
public Tile(int num) | ||
{ | ||
tileNum = num; | ||
|
||
if (num == 1) | ||
{ | ||
hasBlue = true; | ||
hasRed = true; | ||
} | ||
else | ||
{ | ||
hasBlue = false; | ||
hasRed = false; | ||
} | ||
|
||
// the below statement checks if it is a odd or even diagonal | ||
if (num % 2 == 0) | ||
{ | ||
setBackground(Color.WHITE); | ||
} | ||
else | ||
{ | ||
setBackground(Color.BLACK); | ||
} | ||
} | ||
|
||
// draws number and tokens | ||
public void paintComponent(Graphics g) | ||
{ | ||
super.paintComponent(g); | ||
|
||
if (tileNum % 2 == 0) | ||
{ | ||
g.setColor(Color.BLACK); | ||
} | ||
else | ||
{ | ||
g.setColor(Color.WHITE); | ||
} | ||
|
||
g.drawString(tileNum + "", 10, 10); | ||
|
||
if (hasBlue) | ||
{ | ||
drawBlueToken(g); | ||
} | ||
|
||
if (hasRed) | ||
{ | ||
drawRedToken(g); | ||
} | ||
} | ||
|
||
// draws blue token on the board | ||
public void drawBlueToken(Graphics g) | ||
{ | ||
g.setColor(Color.BLUE); | ||
g.drawOval(40, 10, 35, 35); | ||
g.fillOval(40, 10, 35, 35); | ||
} | ||
|
||
// draws red token on the board | ||
public void drawRedToken(Graphics g) | ||
{ | ||
g.setColor(Color.RED); | ||
g.drawOval(10, 40, 35, 35); | ||
g.fillOval(10, 40, 35, 35); | ||
} | ||
|
||
// changes if blue token is on tile or not | ||
public void blueTokenOn(boolean isOn) | ||
{ | ||
hasBlue = isOn; | ||
} | ||
|
||
// changes if red token is on tile or not | ||
public void redTokenOn(boolean isOn) | ||
{ | ||
hasRed = isOn; | ||
} | ||
} | ||
} |
Oops, something went wrong.