Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package SpaceBattle;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.util.Random;
- //import javax.smartcardio.Card;
- import javax.swing.*;
- public class spacebattle2 extends JFrame {
- JLabel[] tilelabel = new JLabel[31];
- JLabel[] hexlabel = new JLabel[31];
- ImageIcon tileicon, hexicon;
- int rownum, colnum;
- int c, r, xloc, yloc, hexctr, tilectr;
- int energy, ore, capacity;
- String labelname;
- String type;
- int numtiles = 31;
- int deckctr = 26;
- String[] tiledeck = new String[numtiles];
- int[] tilexloc = new int[numtiles];
- int[] tileyloc = new int[numtiles];
- int tileenergy[] = new int[numtiles];
- int tileore[] = new int[numtiles];
- int tilecapacity[] = new int[numtiles];
- String tiletype[] = new String[numtiles];
- String tilename[] = new String[numtiles];
- int tilemeeple[] = new int[numtiles];
- String[] hexnum = new String[numtiles];
- int[] hexxloc = new int[numtiles];
- int[] hexyloc = new int[numtiles];
- String[] hexempty = new String[numtiles];
- int hexenergy[] = new int[numtiles];
- int hexore[] = new int[numtiles];
- int hexcapacity[] = new int[numtiles];
- String hextype[] = new String[numtiles];
- String hexname[] = new String[numtiles];
- String hexplayer[] = new String[numtiles];
- String[] players = new String[6];
- String playerturn;
- int startingplanets = 2;
- int bluemaxplanet = startingplanets;
- int redmaxplanet = startingplanets;
- int numplanets = 7;
- int numspace = 24;
- int nonplayertiles = numplanets + numspace;
- String planetCode;
- String planetselected = "none";
- //selectPlanet
- String player = "Red";
- int i;
- public spacebattle2() {
- setLayout(null);
- createDeck();
- shuffleDeck();
- drawBoard();
- //selectPlanet();
- }
- private void selectPlanet() {
- // TODO Auto-generated method stub
- for(i = 0; i < numtiles; i++) {
- tilelabel[i].addMouseListener(new MouseListener() {
- public void mouseClicked(MouseEvent e) {
- System.out.println(i);
- }
- public void mouseEntered(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- public void mouseExited(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- public void mousePressed(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- public void mouseReleased(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- });
- }
- }
- private void shuffleDeck() {
- // TODO Auto-generated method stub
- System.out.println("shuffling deck...");
- Random r = new Random();
- int swapIndex;
- String temp;
- for(int startIndex = 0; startIndex < numtiles; startIndex++) {
- System.out.println(startIndex + " startIndex " + tiledeck[startIndex]);
- swapIndex = r.nextInt(numtiles);
- System.out.println(swapIndex + " swapIndex " + tiledeck[swapIndex]);
- if(swapIndex != startIndex) {
- temp = tiledeck[swapIndex];
- tiledeck[swapIndex] = tiledeck[startIndex];
- System.out.println("Moving " + startIndex + " " + tiledeck[startIndex] + " startIndex to " + swapIndex + " swapIndex");
- tiledeck[startIndex] = temp;
- System.out.println("Moving " + temp + " temp to " + startIndex + " startIndex");
- }
- }
- }
- private void createDeck() {
- // TODO Auto-generated method stub
- int s, p, xloc = 667, yloc = 10;
- /*******************************
- *
- * Create Space tiles
- *
- ******************************/
- System.out.println("creating space tiles...");
- tilectr = 0;
- for(s= 0; s < numspace; s++) {
- tiledeck[tilectr] = "000";
- System.out.println(tilectr + " " + tiledeck[tilectr]);
- tilectr++;
- }
- /**************************
- *
- * Create Planet tiles
- *
- *************************/
- System.out.println("creating planet tiles...");
- for(p = 0; p < numplanets; p++) {
- energy = (int) (Math.random()*3 + 1);
- ore = (int) (Math.random()*3 +1);
- capacity = (int) (Math.random()*3 +1);
- StringBuffer stringBuffer = new StringBuffer();
- stringBuffer.append("");
- stringBuffer.append(energy);
- stringBuffer.append(ore);
- stringBuffer.append(capacity);
- String planetCode = stringBuffer.toString();
- tiledeck[tilectr] = planetCode;
- System.out.println(tilectr + " " + tiledeck[tilectr]);
- tilectr++;
- }
- }
- private void drawBoard() {
- // TODO Auto-generated method stub
- int xloc = 10;
- int yloc = 61;
- int hexctr = 0;
- int colnum = 7;
- int rownum = 4;
- xloc = 10;
- yloc = 61;
- hexctr = 0;
- colnum = 7;
- rownum = 4;
- int row = 0, col = 0, numtiles = 31;
- for(int c = 0; c < numtiles; c ++) {
- if(tiledeck[c] == "000") {
- System.out.println(c + " " + tiledeck[c] + " tile is space");
- tileenergy[c] = 0;
- tileore[c] = 0;
- tilecapacity[c] = 0;
- tiletype[c] = "space";
- tilename[c] = "space";
- tileicon = new ImageIcon(getClass().getResource("/000.png"));
- tilelabel[c] = new JLabel();
- tilelabel[c].setIcon(tileicon);
- tilelabel[c].setBounds(xloc, yloc, 115, 100);
- add(tilelabel[c]);
- yloc = yloc + 102;
- row++;
- if(row == rownum) {
- xloc = xloc + 88;
- row = 0;
- col++;
- if(col % 2 == 0) {
- yloc = 61;
- rownum = rownum - 1;
- }
- else {
- yloc = 10;
- rownum = rownum + 1;
- }
- }
- }
- else {
- System.out.println(c + " " + tiledeck[c] + " tile is planet");
- tileenergy[c] = Integer.parseInt(tiledeck[c].substring(0, 1));
- tileore[c] = Integer.parseInt(tiledeck[c].substring(1, 2));
- tilecapacity[c] = Integer.parseInt(tiledeck[c].substring(2, 3));
- tiletype[c] = "planet";
- tilemeeple[c] = 0;
- tileicon = new ImageIcon(getClass().getResource("/" + tiledeck[c] + ".png"));
- tilelabel[c] = new JLabel();
- tilelabel[c].setIcon(tileicon);
- tilelabel[c].setBounds(xloc, yloc, 115, 100);
- add(tilelabel[c]);
- yloc = yloc + 102;
- row++;
- if(row == rownum) {
- xloc = xloc + 88;
- row = 0;
- col++;
- if(col % 2 == 0) {
- yloc = 61;
- rownum = rownum - 1;
- }
- else {
- yloc = 10;
- rownum = rownum + 1;
- }
- }
- }
- }
- }
- private Object i(int numtiles2, int i) {
- // TODO Auto-generated method stub
- return null;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- spacebattle2 board = new spacebattle2();
- board.setSize(900, 600);
- board.setResizable(false);
- board.setTitle("Space Battle");
- board.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- board.setVisible(true);
- }//End void main
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement