Re: A new project
Date: January 15, 2011 04:01AM
So here we go, posting all the code so far so it doesn't look like I've been doing nothing all day long, as I tend to do.
import javax.swing.*;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.*;
/**
* Created by IntelliJ IDEA.
* User: Paars
* Date: 7-sep-2010
* Time: 9:31:38
* To change this template use File | Settings | File Templates.
*/
public class Battle extends JFrame implements KeyListener, MouseListener
{
JFrame moveScreen = new JFrame();
JTextField jtfArmyNumber = new JTextField();
JLabel jlMaxArmyNumber = new JLabel();
JButton jbAccept = new JButton("Accept"), jbCancel = new JButton("Cancel");
public Battle(Country c1, Country c2 )
{
moveScreen.setBounds(400,400,300,300);
moveScreen.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
moveScreen.setVisible(true);
moveScreen.setLayout(new FlowLayout()); // Temporarely, will later be positioned absolute
moveScreen.add(jtfArmyNumber);
moveScreen.add(jlMaxArmyNumber);
jlMaxArmyNumber.setText("Max Armies \n"+ c1.getSoldiers() );
moveScreen.add(jbAccept);
moveScreen.add(jbCancel);
}
public void keyTyped(KeyEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void keyPressed(KeyEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void keyReleased(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_ENTER)
{
// if possible, accept, add moveOrder to MoveOrderList
}
}
public void mouseClicked(MouseEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void mousePressed(MouseEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void mouseReleased(MouseEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void mouseEntered(MouseEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void mouseExited(MouseEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
/**
* Created by IntelliJ IDEA.
* User: Paars
* Date: 15-jan-2011
* Time: 13:59:21
* To change this template use File | Settings | File Templates.
*/
public class ClientPreGame
{
String[] playerArray,countryArray;
int gameId, amountPlayers;
String gameName;
int[] colors = new int[16];
public ClientPreGame(int gameId, String gameName, int amountPlayers)
{
this.gameId = gameId;
this.gameName = gameName;
this.amountPlayers = amountPlayers;
playerArray = new String[amountPlayers];
countryArray = new String[amountPlayers];
colors[0] = 0xFF0033CC; // blue
colors[1] = 0xFFFF0000; // red
colors[2] = 0xFF00CC00; // green
colors[3] = 0xFFFFFF00; // yellow
colors[4] = 0xFF660099; // Purple
colors[5] = 0xFFFF6600; // Orange
colors[6] = 0xFFFE80DF; // Pink
colors[7] = 0xFF009999; // Teal
colors[8] = 0xFF009999; // Lime
colors[9] = 0xFFB24700; // Brown
colors[10] = 0xFFFEFF80; // light Yellow
colors[11] = 0xFF98F1F2; // light blue
colors[12] = 0xFF205D72; // Dark blue/teal
colors[13] = 0xFFF2DF60; // orange brown
colors[14] = 0xFFBD6E9B; // red purple
colors[15] = 0xFF66490C; // dark Brown
}
public String[] getPlayerList()
{
return playerArray;
}
public void addPlayer(String player)
{
for(int i=0; i < amountPlayers; i++)
{
if(playerArray == null)
{
playerArray = player;
break;
}
}
}
public void removePlayer(String player)
{
for(int i =0;i< amountPlayers;i++)
if(playerArray.equals(player))
{
playerArray = null;
break;
}
}
public int[] getColorList()
{
return colors;
}
public String[] getCountryList()
{
return countryArray;
}
}
import java.util.Random;
import java.awt.*;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
/* Country Class, will obviously be put in a seperate class/file */
class Country implements MouseListener, MouseMotionListener
{
Player player;
String capital;
String name;
Country[] neighborArray;
int population; // will be number *times* 10000
int culture; // 1,2,3 == primitive, developped, advanced respectively
int neighborCount; // starts at 0 just works as pointer for the neighborArray
int soldiers;
int[] testInt;
int nonClickRGB,nonClickRGB2;
Images countryImage;
Color countryColor;
public Country(String name, boolean setup) //When Creating a new country a name has to be given, also the amount of neighbors, constructor creates local country values as well
{
this.name = name;
}
public Country(String name)
{
this.name=name;
}
public Country(String name, String capital)
{
this.name=name;
this.capital = capital;
}
public void buildLocals()
{
Random r = new Random();
soldiers =(r.nextInt(4)+1);
population = (r.nextInt(4)+1);
culture = (r.nextInt(10)+1);
if(culture < 8)
culture = 1;
else
culture = 2;
}
public void displayCountry(int xPos, int yPos)
{
System.out.println("Trying to read file " +name+".png");
//countryImage = new Images(name+".png");
countryImage = new Images("plaatje10.png");
countryImage.setDrawingX(countryImage.getThisWidth()/2);
countryImage.setDrawingY(countryImage.getThisHeight()/2);
//countryImage.setSize(countryImage.getWidth(),countryImage.getHeight());
countryImage.setBounds(xPos,yPos,50,50);
countryImage.setOpaque(false);
countryImage.addMouseListener(this);
countryImage.addMouseMotionListener(this);
testInt = countryImage.getPixelArray();
}
public void buildCapital()
{
population = 3;
Random r = new Random();
soldiers = r.nextInt(3)+1;
}
public String getCountryName()
{
return name;
}
public void addPlayer(Player player)
{
this.player = player;
}
public Player getPlayer()
{
return player;
}
public void setCapital(String playerName)
{
capital = playerName;
}
public String getCapital()
{
return capital;
}
public void addNeighbors(Country[] neighbors)
{
neighborArray = neighbors; // at this place in the array at a neighbor
}
public Country[] getNeighborArray()
{
return neighborArray;
}
public Country getCountry()
{
return this;
}
public void buildPopulation() // increase population
{
population++;
}
public int getPopulation()
{
return population;
}
public void buildCulture()
{
culture++;
}
public int getCulture()
{
return culture;
}
public void setSoldiers(int soldiers)
{
this.soldiers = soldiers;
}
public int getSoldiers()
{
return soldiers;
}
public Images getCountryImage()
{
return countryImage;
}
public void mouseClicked(MouseEvent e)
{
if(e.getSource() == countryImage)
{
if(countryImage.getOnePixel(e.getX(),e.getY())!=nonClickRGB && countryImage.getOnePixel(e.getX(),e.getY())!=0)
{
System.out.println(name);
MainGame.infoArea.setText("");
MainGame.infoArea.append(getCountryName() +"\n");
MainGame.infoArea.append("Culture: "+getCulture() +"\n");
MainGame.infoArea.append("Population: "+getPopulation() +"\n");
for(int i=0;i < testInt.length;i++)
{
if(testInt == -1291845632)
{
if(player == null)
{
testInt = 0XFF0000;
}
else
{
testInt = player.getPlayerColor();
System.out.println(player.getPlayerName() +":"+player.getPlayerColor());
}
}
}
countryImage.setTest(testInt);
}
else
{
System.out.println("clicked Background");
}
}
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseDragged(MouseEvent e)
{
}
public void mouseMoved(MouseEvent e)
{
}
}
/*
Author: Paars
Writing into class file pretty much the idea how to make a cap choser,
haven´t seen the shockwave conquerorgame game coding, nor do I use shockwave coding so I ll do it in Java.
Once again I can use most of the fairCongame code I created before.
*/
import javax.swing.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Vector;
public class createNewGame implements MouseListener// This Constructor would at least need the amount of Players given, probably some extra info too I don't know about
{
JFrame jFrame; // our Frame to build on
JLabel jlPlayerAmount, jlGameName;
JButton cancelButton, resetButton ,acceptButton;
JComboBox[] jComboBoxArray; // ScrollBars, will be filled up with CountryNames
JPanel[] jPanelArray;
JTextField errorTextField, gameName; // In case of Errors, lets write them down to screen for the host to see
String[] countryNameString; // We need this Array for filling up the Scrollbars
int amountCountries =6; // temporary
boolean gameCreated,nameSet;
JLabel[] jLabelArray;
//JTextArea jtaPeopleInGame = new JTextArea();
JTextArea jtaPeopleInGame = new JTextArea();
Vector playerVector;
/*
Temporary button and textfield since Conquerorgame provide its own ones
*/
JButton tempButton=new JButton("Start");
JTextField tempField=new JTextField("2");
class Country // I just created a nested class into my Main file
{
String countryName;
Country[] neighborArray; // Using an Array, Arraylist or a Vector could be used as well.
public Country(String countryName) // Countries constructor, all we need is a Countryname at Creating
{
this.countryName = countryName;
}
public void addNeighbors(Country[] neighborArray) // function to add the Countryneighbors, send in an array
{
this.neighborArray = neighborArray;
}
public String getCountry() // Get CountryName
{
return countryName;
}
public Country[] getNeighbors() // getNeighborArray
{
return neighborArray;
}
}
Country[] allCountriesArray;
Country[] neighborArray;
String name;
public createNewGame(String name) // Dunno what the class is when pressing create new game is, but after that i'd suggest a new or extra Option screen with this as constructor
{
/*
Temporarily Player Number selection, for conquerorgame has its own for that
*/
this.name = name;
playerVector = new Vector();
playerVector.add(name);
jFrame = new JFrame();
jFrame.setBounds(300,300,400,400);
jFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
jFrame.setLayout(null);
jFrame.setTitle("create game");
jFrame.setVisible(true);
tempButton.addMouseListener(this);
jlPlayerAmount = new JLabel("How much players");
jlPlayerAmount.setBounds(125,160,125,25);
jFrame.add(jlPlayerAmount);
tempButton.setBounds(125,200,125,25);
tempField.setBounds(125,250,125,25);
jFrame.add(tempField);
jFrame.add(tempButton);
}
public void buildRealScreen()
{
Country Morocco=new Country("Morocco");Country Tangiers=new Country("Tangiers");Country Algiers=new Country("Algiers");Country Tunis=new Country("Tunis");Country Tripoli=new Country("Tripoli");Country Cyrenaica=new Country("Cyrenaica");Country Egypt=new Country("Egypt");Country Palestine=new Country("Palestine");Country Syria=new Country("Syria");Country Cyprus=new Country("Cyprus");
Country Natolia=new Country("Natolia");Country Nicaea=new Country("Nicaea");Country Crete=new Country("Crete");Country Greece=new Country("Greece");Country Macedonia=new Country("Macedonia");Country Byzantium=new Country("Byzantium");Country Bulgaria=new Country("Bulgaria");Country Moldavia=new Country("Moldavia");Country Crimea=new Country("Crimea");Country Ukraine=new Country("Ukraine");
Country Muscovy=new Country("Muscovy");Country Finland=new Country("Finland");Country Sweden=new Country("Sweden");Country Norway=new Country("Norway");Country Scotland=new Country("Scotland");Country Ulster=new Country("Ulster");Country Eire=new Country("Eire");Country Wales=new Country("Wales");Country Northumberland=new Country("Northumberland");Country England=new Country("England");
Country Brittany=new Country("Brittany");Country Gascony=new Country("Gascony");Country Castile=new Country("Castile");Country Leon=new Country("Leon");Country Portugal=new Country("Portugal");Country Aragon=new Country("Aragon");Country Aquataine=new Country("Aquataine");Country Iledefrance=new Country("Iledefrance");Country Normandy=new Country("Normandy");
Country Flanders=new Country("Flanders");Country Holland=new Country("Holland");Country Luxembourg=new Country("Luxembourg");Country Burgundy=new Country("Burgundy");Country Provence=new Country("Provence");Country Corsica=new Country("Corsica");Country Sardinia=new Country("Sardinia");Country Sicilia=new Country("Sicilia");Country Napoli=new Country("Napoli");
Country Roma=new Country("Roma");Country Genoa=new Country("Genoa");Country Helvetica=new Country("Helvetica");Country Rhineland=new Country("Rhineland");Country Saxony=new Country("Saxony");Country Hannover=new Country("Hannover");Country Denmark=new Country("Denmark");Country Brandenburg=new Country("Brandenburg");Country Bohemia=new Country("Bohemia");
Country Austria=new Country("Austria");Country Venetia=new Country("Venetia");Country Dalmatia=new Country("Dalmatia");Country Hungary=new Country("Hungary");Country Poland=new Country("Poland");Country Transylvania=new Country("Transylvania");Country Serbia=new Country("Serbia");Country Wallachia=new Country("Wallachia");Country Prussia=new Country("Prussia");
Country Podolia=new Country("Podolia");Country Lithuania=new Country("Lithuania");Country Livonia=new Country("Livonia");Country Grenada=new Country("Grenada");
// Adding all the countries in an array, easier to loop through.
allCountriesArray = new Country[]
{
Morocco,Tangiers,Algiers,Tunis,Tripoli,Cyrenaica,Egypt,Palestine,Syria,
Cyprus,Natolia,Nicaea,Crete,Greece,Macedonia,Byzantium,Bulgaria,Moldavia,Crimea,Ukraine,Muscovy,Finland,
Sweden,Norway,Scotland,Ulster,Eire,Wales,Northumberland,England,Brittany,Gascony,Castile,
Leon,Portugal,Aragon,Aquataine,Iledefrance,Normandy,Flanders,Holland,Luxembourg,Burgundy,
Provence,Corsica,Sardinia,Sicilia,Napoli,Roma,Genoa,Rhineland,Helvetica,Saxony,Hannover,Denmark,Brandenburg,
Bohemia,Austria,Venetia,Dalmatia,Hungary,Poland,Transylvania,Serbia,Wallachia,Prussia,Podolia,Lithuania,Livonia,
Grenada
};
// Adding all the neighbors to all Countries
Morocco.addNeighbors(new Country[]{Tangiers});
Tangiers.addNeighbors(new Country[]{Morocco, Grenada, Algiers});
Algiers.addNeighbors(new Country[]{Tangiers, Tunis});
Tunis.addNeighbors(new Country[]{Algiers, Tripoli, Sicilia, Sardinia});
Tripoli.addNeighbors(new Country[]{Tunis, Cyrenaica});
Cyrenaica.addNeighbors(new Country[]{Tunis, Egypt});
Egypt.addNeighbors(new Country[]{Cyrenaica, Palestine});
Palestine.addNeighbors(new Country[]{Egypt, Syria, Cyprus});
Syria.addNeighbors(new Country[]{Palestine, Cyprus, Natolia});
Cyprus.addNeighbors(new Country[]{Palestine, Syria, Natolia});
Natolia.addNeighbors(new Country[]{Cyprus, Syria, Nicaea});
Nicaea.addNeighbors(new Country[]{Natolia, Crete, Greece, Byzantium});
Crete.addNeighbors(new Country[]{Greece, Nicaea});
Greece.addNeighbors(new Country[]{Crete, Nicaea, Macedonia});
Macedonia.addNeighbors(new Country[]{Crete, Nicaea, Byzantium, Bulgaria, Napoli, Dalmatia, Serbia});
Byzantium.addNeighbors(new Country[]{Macedonia, Nicaea, Bulgaria,});
Bulgaria.addNeighbors(new Country[]{Byzantium, Macedonia, Serbia, Wallachia, Moldavia});
Moldavia.addNeighbors(new Country[]{Byzantium, Wallachia, Transylvania, Poland, Podolia, Ukraine, Crimea});
Crimea.addNeighbors(new Country[]{Moldavia, Ukraine});
Ukraine.addNeighbors(new Country[]{Crimea, Moldavia, Lithuania, Muscovy, Podolia});
Muscovy.addNeighbors(new Country[]{Ukraine, Lithuania, Livonia, Finland});
Finland.addNeighbors(new Country[]{Muscovy, Sweden});
Sweden.addNeighbors(new Country[]{Finland, Denmark, Norway});
Norway.addNeighbors(new Country[]{Sweden, Denmark, Scotland});
Scotland.addNeighbors(new Country[]{Norway, Ulster, Northumberland});
Ulster.addNeighbors(new Country[]{Scotland, Eire, Wales, Northumberland});
Eire.addNeighbors(new Country[]{Ulster, Wales});
Wales.addNeighbors(new Country[]{Eire, Ulster, Northumberland, England});
Northumberland.addNeighbors(new Country[]{Wales, Scotland, Ulster, England});
England.addNeighbors(new Country[]{Northumberland, Wales, Brittany, Normandy, Flanders, Holland});
Brittany.addNeighbors(new Country[]{England, Gascony, Iledefrance, Normandy});
Gascony.addNeighbors(new Country[]{Brittany, Aquataine, Iledefrance, Aragon, Castile});
Castile.addNeighbors(new Country[]{Gascony, Leon, Aragon, Grenada});
Leon.addNeighbors(new Country[]{Castile, Grenada, Portugal});
Portugal.addNeighbors(new Country[]{Leon, Grenada});
Aragon.addNeighbors(new Country[]{Grenada, Castile, Gascony, Aquataine});
Aquataine.addNeighbors(new Country[]{Aragon, Gascony, Iledefrance, Provence});
Iledefrance.addNeighbors(new Country[]{Aquataine, Brittany, Normandy, Burgundy, Provence, Gascony});
Normandy.addNeighbors(new Country[]{Iledefrance, England, Brittany, Flanders, Burgundy, Luxembourg});
Flanders.addNeighbors(new Country[]{Normandy, England, Holland, Luxembourg});
Holland.addNeighbors(new Country[]{Flanders, England, Hannover, Saxony});
Luxembourg.addNeighbors(new Country[]{Holland, Normandy, Flanders, Saxony, Burgundy, Rhineland, Helvetica});
Burgundy.addNeighbors(new Country[]{Luxembourg, Iledefrance, Provence, Helvetica, Genoa, Normandy});
Provence.addNeighbors(new Country[]{Burgundy, Aquataine, Iledefrance, Genoa, Corsica});
Corsica.addNeighbors(new Country[]{Provence, Genoa, Roma, Sardinia});
Sardinia.addNeighbors(new Country[]{Corsica, Tunis});
Sicilia.addNeighbors(new Country[]{Tunis, Napoli});
Napoli.addNeighbors(new Country[]{Sicilia, Roma, Macedonia});
Roma.addNeighbors(new Country[]{Napoli, Corsica, Genoa, Venetia});
Genoa.addNeighbors(new Country[]{Roma, Corsica, Provence, Burgundy, Helvetica, Venetia});
Helvetica.addNeighbors(new Country[]{Genoa, Burgundy, Luxembourg, Rhineland, Austria, Venetia});
Rhineland.addNeighbors(new Country[]{Helvetica, Luxembourg, Saxony, Bohemia, Austria});
Saxony.addNeighbors(new Country[]{Rhineland, Luxembourg, Holland, Hannover, Brandenburg, Bohemia});
Hannover.addNeighbors(new Country[]{Saxony, Holland, Denmark, Brandenburg});
Denmark.addNeighbors(new Country[]{Hannover, Norway, Sweden});
Brandenburg.addNeighbors(new Country[]{Hannover, Saxony, Bohemia, Poland});
Bohemia.addNeighbors(new Country[]{Brandenburg, Saxony, Rhineland, Austria, Poland, Hungary});
Austria.addNeighbors(new Country[]{Bohemia, Rhineland, Helvetica, Venetia, Hungary, Dalmatia});
Venetia.addNeighbors(new Country[]{Austria, Genoa, Roma, Dalmatia, Helvetica});
Dalmatia.addNeighbors(new Country[]{Venetia, Austria, Hungary, Serbia, Macedonia});
Hungary.addNeighbors(new Country[]{Dalmatia, Austria, Poland, Transylvania, Serbia, Bohemia});
Poland.addNeighbors(new Country[]{Hungary, Brandenburg, Moldavia, Podolia, Prussia, Transylvania, Bohemia});
Transylvania.addNeighbors(new Country[]{Poland, Hungary, Serbia, Wallachia, Moldavia});
Serbia.addNeighbors(new Country[]{Transylvania, Wallachia, Bulgaria, Macedonia, Dalmatia, Hungary});
Wallachia.addNeighbors(new Country[]{Serbia, Transylvania, Moldavia, Bulgaria});
Prussia.addNeighbors(new Country[]{Poland, Podolia, Lithuania});
Podolia.addNeighbors(new Country[]{Prussia, Poland, Moldavia, Lithuania, Ukraine});
Lithuania.addNeighbors(new Country[]{Podolia, Livonia, Muscovy, Ukraine , Prussia});
Livonia.addNeighbors(new Country[]{Lithuania, Muscovy});
Grenada.addNeighbors(new Country[]{Tangiers, Portugal, Leon, Castile, Aragon});
// Coding for the standard Frame
jComboBoxArray = new JComboBox[amountCountries]; // Create the right amount of dropdownmenu's
jPanelArray = new JPanel[amountCountries];
int[] colors = new int[16];
colors[0] = 0xFF0033CC; // blue
colors[1] = 0xFFFF0000; // red
colors[2] = 0xFF00CC00; // green
colors[3] = 0xFFFFFF00; // yellow
colors[4] = 0xFF660099; // Purple
colors[5] = 0xFFFF6600; // Orange
colors[6] = 0xFFFE80DF; // Pink
colors[7] = 0xFF009999; // Teal
colors[8] = 0xFF009999; // Lime
colors[9] = 0xFFB24700; // Brown
colors[10] = 0xFFFEFF80; // light Yellow
colors[11] = 0xFF98F1F2; // light blue
colors[12] = 0xFF205D72; // Dark blue/teal
colors[13] = 0xFFF2DF60; // orange brown
colors[14] = 0xFFBD6E9B; // red purple
colors[15] = 0xFF66490C; // dark Brown
jFrame=new JFrame();
jFrame.setBounds(0,0,800,600); // setFrameSize 0 px from top and 0 px from left with width 1000px, height 800px,function getScreenSize could be used too
jFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // must be able to close it
jFrame.setLayout(null); // no layout, we will be positioning absolute ourselves.
jlGameName=new JLabel("Game name");
jlGameName.setBounds(25,50,75,25);
gameName=new JTextField("Your game name");
gameName.setBounds(125,50,150,25);
jLabelArray = new JLabel[amountCountries];
jFrame.add(jlGameName);
jFrame.add(gameName);
// Lets add the ScrollbarArray, using a loop to add them to the JFrame.
// First fill Up the CountryNameArray using a loop so it can be used for the scrollbars
countryNameString =new String[allCountriesArray.length]; // Make sure the arrays are the same size
for(int i=0;i < allCountriesArray.length;i++)
{
countryNameString = allCountriesArray.getCountry(); //
}
int j=0; // just an extra into to place the Scrollbars next to each other
for(int i=0;i < amountCountries; i++) // loop from 0 to obviously chosenCountriesAmount
{
jComboBoxArray = new JComboBox(countryNameString);
jPanelArray = new JPanel();
jLabelArray = new JLabel("AI(Unavailable) ");
jLabelArray.setSize(150,25);
jPanelArray.setForeground(new Color(colors));
jPanelArray.setBackground(new Color(colors));
jPanelArray.setSize(40,25);
jComboBoxArray.setSelectedIndex(allCountriesArray.length-1);
jComboBoxArray.addMouseListener(this);
jComboBoxArray.setSize(125,25);
if(i<8)
{
jLabelArray.setLocation(50,95+i*70);
jComboBoxArray.setLocation(50,125+i*70);
jPanelArray.setLocation(200,125+i*70);
}
else
{
jLabelArray.setLocation(260,95+j*70);
jComboBoxArray.setLocation(260,125+j*70);
jPanelArray.setLocation(410,125+j*70);
j++;
}
jFrame.add(jLabelArray);
jFrame.add(jPanelArray);
jFrame.add(jComboBoxArray);
}
jFrame.repaint();
// adding the buttons
acceptButton = new JButton("accept"); // continue
resetButton = new JButton("reset"); // Reset The scrollBars, kinda unnessecary but I had a diffrent plan first
cancelButton = new JButton("Cancel"); // return
acceptButton.setBounds(100,450,150,30);
resetButton.setBounds(300,450,150,30);
cancelButton.setBounds(500,450,150,30);
acceptButton.addMouseListener(this);
resetButton.addMouseListener(this);
cancelButton.addMouseListener(this);
jFrame.add(acceptButton);
jFrame.add(resetButton);
jFrame.add(cancelButton);
errorTextField=new JTextField("Status field::");
errorTextField.setBounds(50,500,700,30);
errorTextField.setEditable(false);
jFrame.add(errorTextField); // Is actually statusfield
jFrame.setTitle("Create game");
jFrame.setVisible(true);
}
public void mouseClicked(MouseEvent e)
{
// Since I implemented MouseListener, I'm forced to also create/implements all its functions
}
public void mousePressed(MouseEvent e)
{
// Since I implemented MouseListener, I'm forced to also create/implements all its functions
}
public void mouseReleased(MouseEvent e)
{
if(e.getSource() == acceptButton)
{
boolean done=false;
Country[] chosenCapitalArray = new Country[amountCountries];
Country[] tempNeighbors=null;
for(int i=0;i < amountCountries;i++)
{
for(int j=0;j < allCountriesArray.length;j++)
{
if(jComboBoxArray.getSelectedItem().equals(allCountriesArray[j].getCountry()) && i != j)
{
chosenCapitalArray = allCountriesArray[j];
System.out.println("ChosenCap Found at pos: "+chosenCapitalArray.getCountry()+":"+i +": And "+allCountriesArray[j].getCountry()+":"+j );
}
}
}
for(int i=0;i < amountCountries;i++)
{
tempNeighbors = chosenCapitalArray.getNeighbors();
for(int j=0;j < amountCountries;j++)
{
if(chosenCapitalArray.getCountry().equals(chosenCapitalArray[j].getCountry()) && i != j )
{
errorTextField.setText("Error: Double capitals " + chosenCapitalArray.getCountry() + " Is chosen twice");
done=true;
break;
}
for(int k=0;k < tempNeighbors.length;k++)
{
if(chosenCapitalArray[j].getCountry().equals(tempNeighbors[k].getCountry()))
{
errorTextField.setText("Status Field: "+chosenCapitalArray.getCountry() + " to close to "+ tempNeighbors[k].getCountry());
done=true;
break;
}
}
}
}
if(!done)
{
errorTextField.setText("Status field: You've accepted, Do error Checking, gather info and continue");
//jFrame.dispose();
//jFrame=new JFrame();
jFrame.setBounds(0,0,800,600); // setFrameSize 0 px from top and 0 px from left with width 1000px, height 800px,function getScreenSize could be used too
//jFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // must be able to close it
//jFrame.setLayout(null); // no layout, we will be positioning absolute ourselves.
// jFrame.setVisible(true);
Main2.inGame =true;
gameCreated=true;
Main2.socketClient.sendData("creategame"+":"+0+":"+gameName.getText()+":"+ amountCountries +":"+name);
acceptButton.setVisible(false);
resetButton.setVisible(false);
//cancelButton.setVisible(false);
gameName.setEditable(false);
for(int i=0;i<amountCountries;i++)
{
jComboBoxArray.setEditable(false);
jPanelArray.addMouseListener(this);
jPanelArray.setName(""+i);
}
}
}
if(e.getSource() == resetButton)
{
errorTextField.setText("Status field: Reset button, not nessecary");
}
if(e.getSource() == cancelButton)
{
closeScreen();
}
if(e.getSource() == tempButton)
{
try
{
int playerNumber =Integer.parseInt(tempField.getText());
if(playerNumber < 17 && playerNumber > 1)
{
amountCountries = playerNumber;
jFrame.dispose();
buildRealScreen();
}
}
catch(Exception exc)
{
//because I have to throw an Exception
};
}
if(e.getSource() instanceof JPanel)
{
JPanel jp = (JPanel)e.getSource();
//for(int i=0;i< amountCountries;i++)
//System.out.println(jp.getName());
if(!nameSet)
{
System.out.println("here 1");
for(int i=0;i<amountCountries;i++)
{
if(Integer.valueOf(jp.getName()) == i)
{
jLabelArray.setText(name);
nameSet =true;
jFrame.repaint();
System.out.println(i);
break;
}
}
}
}
}
public void mouseEntered(MouseEvent e)
{
// Since I implemented MouseListener, I'm forced to also create/implements all its functions
}
public void mouseExited(MouseEvent e)
{
// Since I implemented MouseListener, I'm forced to also create/implements all its functions
}
public int closeScreen()
{
Main2.inGame=false;
if(gameCreated)
{
Main2.socketClient.sendData("removeGame:"+Main2.gameId);
}
jFrame.dispose();
return 1;
}
// public static void main is the standard Java function to run a program, in conquerorGame needs to be switched since its not the file to run.
}
public class Game
{
int gameId,playerCount,spectators=5,allowedPlayerAmount;
String[] playerArray,spectatorArray;
String gameName,password;
public Game(int gameId,String player,int allowedPlayerAmount)
{
this.gameId = gameId;
this.allowedPlayerAmount = allowedPlayerAmount;
playerArray = new String[allowedPlayerAmount];
playerArray[0] = player;
playerCount ++;
}
public void addPlayerToGame(String player)
{
playerCount++;
for(int i=0;i < allowedPlayerAmount;i++)
if(playerArray == null && allowedPlayerAmount > playerCount)
playerArray = player;
}
public int removePlayerFromGame(String player)
{
System.out.println("function removePlayerFromGame here 1: "+gameId);
for(int i=0;i < allowedPlayerAmount;i++)
try
{
if(playerArray !=null && playerArray.equals(player))
{
playerCount--;
System.out.println("function removePlayerFromGame here 2: "+gameId);
playerArray = null;
break;
}
}
catch(Exception exc)
{
}
if(playerCount ==0)
{
//MultipleLoginsClass.removeGame(gameId);
return gameId;
}
return-1;
}
public void SendToPlayersInGame(String data)
{
for(int i=0;i<allowedPlayerAmount;i++)
if(playerArray!= null)
MultipleLoginsClass.sendToPlayer(playerArray,data);
}
}
import javax.swing.*;
import javax.imageio.*;
import java.awt.image.*;
import java.io.*;
import java.awt.*;
// Klasse Images handelt het inladen van plaatjes af ze op te zetten op een JPanel en een functie om plaatjes te roteren
public class Images extends JPanel
{
BufferedImage image;
int drawingX, drawingY,imgPosX,imgPosY;
int fWidth,fHeight;
int[] pixelArray2;
public Images(String imgName)
{
try
{
image = ImageIO.read(new File(imgName));
System.out.println("Files ingeladen");
}
catch(IOException ioe)
{
ioe.getMessage();
}
fWidth = image.getWidth();
fHeight = image.getHeight();
pixelArray2 = new int[fWidth * fHeight];
}
public void paint(Graphics g)
{
super.paint(g);
Graphics2D gc =(Graphics2D) g;
gc.drawImage(image, imgPosX, imgPosY ,this);
}
public void setDrawingX(int drawingX)
{
this.drawingX = drawingX;
}
public void setDrawingY(int drawingY)
{
this.drawingY = drawingY;
}
public int getDrawingX()
{
return drawingX;
}
public int getDrawingY()
{
return drawingY;
}
public int getThisWidth()
{
return image.getWidth();
}
public int getThisHeight()
{
return image.getHeight();
}
public void setImgPosX(int x)
{
imgPosX = x;
}
public void setImgPosY(int y)
{
imgPosY = y;
}
public int[] getPixelArray()
{
return image.getRGB(0,0,fWidth,fHeight,pixelArray2,0,fWidth);
}
public void setTest(int[] r)
{
image.setRGB(0,0,fWidth,fHeight,r,0,fWidth);
repaint();
}
public int getOnePixel(int a,int b)
{
try
{
return(image.getRGB(a,b));
}
catch(ArrayIndexOutOfBoundsException e)
{
return 0;
}
}
}
import javax.swing.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.net.Socket;
import java.net.ServerSocket;
import java.util.Vector;
public class Main implements KeyListener, Runnable
{
public static int players=0,playersOnline=0,playerId=0;
public static boolean[] gameSpaceArray = new boolean[25];
public static int chatIndexRemoval=0, gameRoomIndexRemoval=0;
private JFrame jf = new JFrame();
private JTextArea jtaChat = new JTextArea(), jtaPeopleOnline = new JTextArea();
private JTextField jtfChatBar = new JTextField();
SocketServer socketServer;
String input;
public String output;
int whatever =0;
public static Vector chatVector = new Vector();
public static Vector peopleOnline = new Vector();
public static Vector gameRooms = new Vector();
public static Vector multipleClientsVector = new Vector();
public static Vector outputStreamVector = new Vector();
public Main()
{
jf.setTitle("Main Frame - Server Beta 0.10");
jf.setBounds(350,300,325,325);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jf.setLayout(null);
jtaChat.setBounds(10,10,200,200);
jtaPeopleOnline.setBounds(220,10,80,200);
jtfChatBar.setBounds(10,235, 275,25);
jtfChatBar.addKeyListener(this);
jf.add(jtfChatBar);
jf.add(jtaPeopleOnline);
jf.add(jtaChat);
jf.setVisible(true);
socketServer = new SocketServer();
new Thread(this).start();
}
public static void main(String[]args)
{
new Main();
//new Main2();
}
public void keyTyped(KeyEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void keyPressed(KeyEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void keyReleased(KeyEvent e)
{
if(e.getSource() == jtfChatBar)
{
if(e.getKeyCode() == KeyEvent.VK_ENTER)
{
// socketServer.sendData("Server: "+jtfChatBar.getText());
output = "Server: "+jtfChatBar.getText();
jtaChat.append("Server:" +jtfChatBar.getText() + "\n");
jtfChatBar.setText("");
}
}
}
public void run()
{
while(true)
{
multipleClientsVector.add(new MultipleLoginsClass(socketServer.getData()));
System.out.println("new Socket Made");
}
}
public static void removeFromPlayersVector(String s)
{
for(int i=0; i < peopleOnline.capacity();i++)
{
try
{
if(s.equals(peopleOnline.get(i)))
{
peopleOnline.remove(i);
System.out.println("Player removed");
}
}
catch(Exception e)
{
}
}
}
public static String getPlayer(String s)
{
for(int i=0; i < peopleOnline.capacity();i++)
{
try
{
if(s.equals(peopleOnline.get(i)))
{
return s;
}
}
catch(Exception e)
{
}
}
return null;
}
}
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.IOException;
public class Main2 implements KeyListener, MouseListener, Runnable
{
/*
* Still in testing fase
*
* */
JLabel[] jLabelArray = new JLabel[25];
static boolean inGame;
// ending current testing fase
JFrame jf = new JFrame(),jf2 = new JFrame(),jfOption=new JFrame();
static int gameId=0;
int playerId=-1,selectedGameId;
JTextArea jtaChat = new JTextArea(), jtaPeopleOnline=new JTextArea();
// jtaLoginName = new JTextArea(),
JButton testGameButton = new JButton("Create game"), testGameButton2 = new JButton("Create it!"),joinButton = new JButton("Join");
JTextField testGameField = new JTextField("Game name "+gameId);
//JLabel jlchatAreaPosX,jlChatAreaPosY,jlChatAreaXSize, jlChatAreaYSize,jlTextBarPosX,jlTextBarPosY,jlTextBarSizeX,jlTextBarSizeY,jlPeopleOnlinePosX,jlPeopleOnlinePosY,
//jlPeopleOnlineSizeX,jlPeopleOnlineSizeY,jlGameButtonsPosX,jlGameButtonsPosY,jlGameButtonsSizeX,jlGameButtonsSizeY;
JLabel jlChatArea = new JLabel("Chat Area"), jlChatbar= new JLabel("Chatbar"), jlPeopleOnline=new JLabel("People Online"), jlGameButtons=new JLabel("Game Buttons");
JLabel[] jlOptionArray;
JTextField[] jtfOptionArray;
JButton jbRepositionButton, jbUpdateOptions;
JTextField jtfChatBar = new JTextField(),jtaLoginName=new JTextField();
JButton jbLogin = new JButton("login"),jbOption = new JButton("options");
static SocketClient socketClient;
String name,input;
Thread myThread = new Thread();
JScrollPane gag;
int[] playerColors;
int jlChatAreaPosX=150,jlChatAreaPosY=50,jlChatAreaXSize=500, jlChatAreaYSize=550,jlTextBarPosX=150,jlTextBarPosY=625,jlTextBarSizeX=700,jlTextBarSizeY=30,jlPeopleOnlinePosX=675
,jlPeopleOnlinePosY=50,jlPeopleOnlineSizeX=175,jlPeopleOnlineSizeY=550,jlGameButtonsPosX,jlGameButtonsPosY,jlGameButtonsSizeX,jlGameButtonsSizeY;
public Main2()
{
jf.setTitle("Client Beta 0.10");
jf.setBounds(250,200,400,400);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jf.setLayout(null);
jtaLoginName.setBounds(100,100,200,30);
jtaLoginName.setText("your name");
jtaLoginName.setBackground(Color.LIGHT_GRAY);
jbLogin.setBounds(125,150,100,30);
jbLogin.addMouseListener(this);
jtfChatBar.setBounds(150,625,700,30);
jtaChat.setBounds(150,50,500,550);
jtaChat.setLineWrap(true);
jtaChat.setEditable(false);
//jtaChat.setCaretPosition(0);
jtaChat.setWrapStyleWord(true);
jtaPeopleOnline.setAutoscrolls(true);
jtaPeopleOnline.setBounds(675,50,175,550);
jtaPeopleOnline.setEditable(false);
testGameButton.setBounds(15,15,100,25);
testGameButton.addMouseListener(this);
joinButton.setBounds(125,15,100,25);
joinButton.addMouseListener(this);
joinButton.setEnabled(false);
jbOption.setBounds(240,15,100,25);
jbOption.addMouseListener(this);
gag = new JScrollPane(jtaChat);
gag.setBounds(jtaChat.getBounds());
jtfChatBar.addKeyListener(this);
jf.add(jbLogin);
//jf.add(jbOption);
jtaLoginName.setSelectionStart(0);
jtaLoginName.setSelectionEnd(jtaLoginName.getText().length());
jtaLoginName.requestFocus();
jf.add(jtaLoginName);
jf.add(jtaPeopleOnline);
//jf.add(testGameButton);
jf.setVisible(true);
jf.addWindowListener( new WindowAdapter() {
public void windowOpened( WindowEvent e ){
jtaLoginName.requestFocus();
}
} );
}
public void keyTyped(KeyEvent e)
{
}
public void keyPressed(KeyEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void keyReleased(KeyEvent e)
{
if(e.getSource() == jtfChatBar)
{
if(e.getKeyCode() == KeyEvent.VK_ENTER)
{
if(jtfChatBar.getText() !="")
{
String stringTemp = jtfChatBar.getText();
System.out.println("stringtemp1.0: "+stringTemp);
if(stringTemp.charAt(0)=='#')
{
for(int i=0;i < stringTemp.length();i++)
if(stringTemp.charAt(i) ==' ')
{
System.out.println("here 1.1");
char[] charArray = stringTemp.toCharArray();
stringTemp ="";
charArray = '¡';
for(int j=0;j < charArray.length;j++)
stringTemp+=charArray[j];
//stringTemp = charArray.toString();
System.out.print("stringtemp 1.2: "+stringTemp);
break;
}
}
stringTemp = stringTemp.replace(':',';');
System.out.println("here");
socketClient.sendData(name+":"+stringTemp);
jtfChatBar.setText("");
}
}
}
}
public static void main(String[]args)
{
new Main2();
}
public void mouseClicked(MouseEvent e)
{
if(e.getSource()==jbLogin)
{
if(!jtaLoginName.getText().equals(""))
{
socketClient = new SocketClient("77.251.246.20");
//socketClient = new SocketClient("192.168.1.102");
//socketClient = new SocketClient("192.168.1.102");
jf.setBounds(100,25,950,700);
jf.add(testGameButton);
jf.add(joinButton);
jf.add(jtfChatBar);
jf.add(jbOption);
jtaLoginName.setVisible(false);
jbLogin.setVisible(false);
jf.add(gag);
socketClient.sendData("login:"+jtaLoginName.getText());
socketClient.sendData(jtaLoginName.getText() + ": logged in.");
name = jtaLoginName.getText();
new Thread(this).start();
}
}
if(e.getSource()==testGameButton && inGame == false)
{
new createNewGame(name);
//jf2.setBounds(100,100,700,600);
//jf2.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// jf2.setLayout(null);
//testGameField.setBounds(100,100,150,25);
// testGameButton2.setBounds(110,150,75,25);
// jf2.add(testGameField);
// jf2.add(testGameButton2);
// jf2.setVisible(true);
// testGameButton2.addMouseListener(this);
// playerColors=new int[3];
// playerColors[0] = 0xFF00FF00;
// playerColors[1] = 0XFF000000;
// playerColors[2] = 0XFF0000;
}
if(e.getSource()==jbOption)
{
jfOption = new JFrame();
jfOption.setTitle("Option Screen");
jfOption.setBounds(80,15,600,600);
jfOption.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
jfOption.setLayout(null);
jlOptionArray = new JLabel[16];
jtfOptionArray = new JTextField[16];
int x=0,y=25;
String strJLabelString="Pos X";
jlChatArea.setBounds(5,55,100,25);
jlChatbar.setBounds(5,115,100,25);
jlPeopleOnline.setBounds(5,85,100,25);
jfOption.add(jlChatArea);
jfOption.add(jlChatbar);
jfOption.add(jlPeopleOnline);
for(int i=0;i < jlOptionArray.length;i++)
{
if(x % 4 == 0)
{
y+=30;
x=0;
strJLabelString="Pos X";
}
else if(x % 4 == 1)
strJLabelString="Pos Y";
else if(x % 4 == 2)
strJLabelString = "Size X";
else if(x % 4 == 3)
strJLabelString="Size Y";
jlOptionArray = new JLabel(strJLabelString);
jtfOptionArray = new JTextField();
if(i==0)
{
jtfOptionArray = new JTextField(""+jlChatAreaPosX);
}
else if(i==1)
{
jtfOptionArray = new JTextField(""+jlChatAreaPosY);
}
else if(i==2)
{
jtfOptionArray = new JTextField(""+jlChatAreaXSize);
}
else if(i==3)
{
jtfOptionArray = new JTextField(""+jlChatAreaYSize);
}
else if(i==4)
{
jtfOptionArray = new JTextField(""+jlTextBarPosX);
}
else if(i==5)
{
jtfOptionArray = new JTextField(""+jlTextBarPosY);
}
else if(i==6)
{
jtfOptionArray = new JTextField(""+jlTextBarSizeX);
}
else if(i==7)
{
jtfOptionArray = new JTextField(""+jlTextBarSizeY);
}
else if(i==8)
{
jtfOptionArray = new JTextField(""+jlPeopleOnlinePosX);
}
else if(i==9)
{
jtfOptionArray = new JTextField(""+jlPeopleOnlinePosY);
}
else if(i==10)
{
jtfOptionArray = new JTextField(""+jlPeopleOnlineSizeX);
}
else if(i==11)
{
jtfOptionArray = new JTextField(""+jlPeopleOnlineSizeY);
}
jlOptionArray.setBounds(90+x*120,y,50,25);
jtfOptionArray.setBounds(150+x*120,y,50,25);
x++;
jfOption.add(jlOptionArray);
jfOption.add(jtfOptionArray);
}
jfOption.setVisible(true);
jbUpdateOptions = new JButton("Update Options");
jbUpdateOptions.setBounds(180,200,100,25);
jbUpdateOptions.addMouseListener(this);
jfOption.add(jbUpdateOptions);
}
if(e.getSource()==jbUpdateOptions)
{
System.out.println("here");
int getTextFieldValue;
try
{
for(int i=0;i< 12;i++)
{
getTextFieldValue = Integer.valueOf(jtfOptionArray.getText());
if(i==0)
{
jlChatAreaPosX=getTextFieldValue;
}
else if(i==1)
{
jlChatAreaPosY=getTextFieldValue;
}
else if(i==2)
{
jlChatAreaXSize=getTextFieldValue;
}
else if(i==3)
{
jlChatAreaYSize=getTextFieldValue;
}
else if(i==4)
{
jlTextBarPosX=getTextFieldValue;
}
else if(i==5)
{
jlTextBarPosY=getTextFieldValue;
}
else if(i==6)
{
jlTextBarSizeX=getTextFieldValue;
}
else if(i==7)
{
jlTextBarSizeY=getTextFieldValue;
}
else if(i==8)
{
jlPeopleOnlinePosX=getTextFieldValue;
}
else if(i==9)
{
jlPeopleOnlinePosY=getTextFieldValue;
}
else if(i==10)
{
jlPeopleOnlineSizeX=getTextFieldValue;
}
else if(i==11)
{
jlPeopleOnlineSizeY=getTextFieldValue;
}
}
System.out.println("JTACHATBOUNDS SET TO: "+jlChatAreaPosX+":"+jlChatAreaPosY+":"+jlChatAreaXSize+":"+jlChatAreaYSize );
jtaChat.setBounds(jlChatAreaPosX,jlChatAreaPosY,jlChatAreaXSize,jlChatAreaYSize);
jtfChatBar.setBounds(jlTextBarPosX,jlTextBarPosY,jlTextBarSizeX,jlTextBarSizeY);
jtaPeopleOnline.setBounds(jlPeopleOnlinePosX,jlPeopleOnlinePosY,jlPeopleOnlineSizeX,jlPeopleOnlineSizeY);
jfOption.dispose();
jf2.repaint();
}
catch(Exception exc)
{
}
}
if(e.getSource()==testGameButton2)
{
// Testing Fase
socketClient.sendData("creategame"+":"+playerId+":"+testGameField.getText()+":4:"+name);
// Ending Testing Fase
}
if(e.getSource() instanceof JLabel)
{
System.out.println("Hit a Jpanel");
JLabel tempLabel = (JLabel) e.getSource();
selectedGameId = Integer.valueOf((tempLabel.getName()));
joinButton.setEnabled(true);
}
if(e.getSource() == joinButton)
{
socketClient.sendData("joinGame:"+selectedGameId);
}
}
public void setIngame(boolean inGameboolean)
{
inGame = inGameboolean;
}
public void mousePressed(MouseEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void mouseReleased(MouseEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void mouseEntered(MouseEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void mouseExited(MouseEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void listenSocket()
{
if(socketClient != null)
{
try
{
while((input = socketClient.in.readLine())!=null)
{
System.out.println("input received:"+input);
// TESTINGFASE
if(getCreateGame(input))
{
String[] gameCreation = input.split(":");
try
{
System.out.println(input);
int gameId = Integer.parseInt(gameCreation[1]);
jLabelArray[gameId] = new JLabel(gameCreation[1] + "("+gameCreation[2]+")"+" (" + gameCreation[3] +")");
jLabelArray[gameId].addMouseListener(this);
jLabelArray[gameId].setBounds(5,50+gameId*25,140,24);
jLabelArray[gameId].setOpaque(true);
jLabelArray[gameId].setBackground(Color.black);
jLabelArray[gameId].setForeground(Color.red);
jLabelArray[gameId].setName(""+gameId);
jf.add(jLabelArray[gameId]);
jf2.dispose();
System.out.println("added label");
jf.repaint();
gag.getVerticalScrollBar().setValue(gag.getVerticalScrollBar().getMaximum());
}
catch(NumberFormatException nfe)
{
}
} // testing Fase - client + server 0.10
else if(getPlayerId(input))
{
String[] playerIdStringArray = input.split(":");
if(playerId < 0)
playerId = Integer.parseInt(playerIdStringArray[1]);
socketClient.sendData("playerId"+ playerId + ":" + "logged in");
//jtaChat.append("your id is: "+playerId);
gag.getVerticalScrollBar().setValue(gag.getVerticalScrollBar().getMaximum());
}
else if(getWhisper(input))
{
gag.getVerticalScrollBar().setValue(gag.getVerticalScrollBar().getMaximum());
}
// testing fase - client + server 0.10 DONE
// TESTINGFASE done
else if(getIngame(input))
{
}
else if(getRemoveGame(input))
{
jf.repaint();
System.out.println("repainted");
socketClient.sendData("requireGameUpdate");
}
else if(!getLogin(input))
{
jtaChat.append(input+"\n");
gag.getVerticalScrollBar().setValue(gag.getVerticalScrollBar().getMaximum());
}
else
{
jtaPeopleOnline.setText("");
String[] loggedOnPeople = getLoginAppend(input);
for(int i=0; i < loggedOnPeople.length;i++)
{
jtaPeopleOnline.append(loggedOnPeople +"\n");
}
}
}
}
catch(IOException e)
{
System.out.println("Error");
System.exit(1);
}
}
}
public void run()
{
while(true)
{
listenSocket();
}
}
public boolean getRemoveGame(String s)
{
String[] repaintString = s.split(":");
if(repaintString[0].equals("removeGame"))
{
int tempGameId = Integer.valueOf(repaintString[1]);
System.out.println("tempGameId: "+tempGameId);
try
{
jLabelArray[tempGameId].setVisible(false);
}
catch(Exception exc)
{
}
jLabelArray[tempGameId] = null;
jf.repaint();
return true;
}
return false;
}
public boolean getLogin(String s)
{
String[] loginString = s.split(":");
{
if(loginString[0].equals("login"))
{
return true;
}
}
return false;
}
public boolean getWhisper(String s)
{
try{
String[] tempArray = s.split(":");
if(tempArray[0].equals("private") && tempArray[1].equals("whisper"))
{
jtaChat.append(tempArray[2] +" whispers "+tempArray[3] +": "+tempArray[4]+"\n");
return true;
}
}
catch(Exception exc)
{
}
return false;
}
public String[] getLoginAppend(String s)
{
String[] myString = s.split(":");
String[] MyString2 = myString[1].split(",");
return MyString2;
}
public boolean getPlayerId(String s)
{
String[] playerIdArrayString = s.split(":");
if(playerIdArrayString[0].equals("playerId"))
return true;
return false;
}
// testing fase part
public boolean getIngame(String s)
{
String[] myArray;
myArray = s.split(":");
if(myArray[0].equals("private"))
{
if(myArray[1].equals("inGame"))
{
if(myArray[2].equals("true"))
setIngame(true);
else
setIngame(false);
return true;
}
}
return false;
}
public boolean getCreateGame(String s)
{
String[] createGameString = s.split(":");
if(createGameString[0].equals("creategame"))
{
//socketClient.sendData("requireGameUpdate");
return true;
}
return false;
}
// ending testing fase part
}
edit:
Will post rest later, cuz the code's to big to fit into 1 message.
Edited 2 time(s). Last edit at 01/15/2011 04:08AM by Paars.