Re: A new project
Date: September 13, 2010 10:22PM
As expted I haven´t had a lot of time for coding, but I´m going to post the classes I´ve been working on here anyway to show at least some progress. ;) And yes the few classes I coded are far from done. The code for a lobby System I made somewhere in the past just need to get it from my other pc.
-----------------------------------------------------------------
MainGame Class(Yes I used a lot from my faircongame program saved me hella lot of typing)
-----------------------------------------------------------------
import javax.swing.*;
/**
* Created by IntelliJ IDEA.
* User: Paars
* Date: 7-sep-2010
* Time: 10:23:23
* To change this template use File | Settings | File Templates.
*/
public class MainGame extends JFrame
{
JFrame jFrame = new JFrame();
public MainGame(boolean setup, Player[] playerArray)
{
buildNeighbors();
if(setup) // If the game has to be created still
{
for(int i=0;i < allCountriesArray.length;i++)
{
allCountriesArray.buildLocals(); // setup local countries
}
for(int i=0;i < playerArray.length;i++)
{
playerArray.getCapitalCountry().buildCapital();
}
}
jFrame.setBounds(0,0,1000,1000);
jFrame.setVisible(true);
jFrame.setLayout(null);
jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
// Creating all the Countries, naming them
private 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.
Country allCountriesArray[] =
{
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
public void buildNeighbors()
{
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, Lithuania, Prussia});
Livonia.addNeighbors(new Country[]{Lithuania, Muscovy});
Grenada.addNeighbors(new Country[]{Tangiers, Portugal, Leon, Castile, Aragon});
}
}
-------------------------------------------------------------------------------
Country Class
-------------------------------------------------------------------------------
import java.util.Random;
/* Country Class, will obviously be put in a seperate class/file */
class Country
{
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;
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 buildCapital()
{
population = 3;
Random r = new Random();
soldiers = r.nextInt(3)+1;
}
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;
}
}
--------------------------------------------------------------------------------
Player Class(Multiple constructors easier for joining into the game
--------------------------------------------------------------------------------
import java.util.Vector;
import java.util.Random;
/**
* Created by IntelliJ IDEA.
* User: Paars
* Date: 7-sep-2010
* Time: 9:51:31
* To change this template use File | Settings | File Templates.
*/
public class Player
{
// login - retrieve database player information
Player player;
String playerName;
Country capitalCountry;
Vector countryVector;
int gold;
public Player(String playerName)
{
this.playerName = playerName;
}
public Player(String playerName, Country capitalCountry)
{
this.playerName = playerName;
this.capitalCountry = capitalCountry;
this.countryVector.add(capitalCountry);
Random r = new Random();
gold = r.nextInt(6) + 8;
}
public void addCountry(Country country)
{
countryVector.add(country);
}
public void removeCountry(Country country)
{
countryVector.remove(country);
}
public void setGold(int gold)
{
this.gold += gold;
}
public String getPlayerName()
{
return playerName;
}
public Country getCapitalCountry()
{
return capitalCountry;
}
public Vector getCapitalVector()
{
return countryVector;
}
}
--------------------------------------------------------------------------------
Battle Class so far, really not near done.
--------------------------------------------------------------------------------
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.
}
}
--------------------------------------------------------------------------------
MoveOrder class at least its a start
--------------------------------------------------------------------------------
/**
* Created by IntelliJ IDEA.
* User: Paars
* Date: 7-sep-2010
* Time: 9:39:38
* To change this template use File | Settings | File Templates.
*/
public class MoveOrder
{
int sendSoldiers;
Country c1, c2;
public MoveOrder(Country c1, Country c2, int sendSoldiers)
{
this.sendSoldiers = sendSoldiers;
this.c1 = c1;
this.c2 = c2;
}
public int getSendSoldiers()
{
return sendSoldiers;
}
public Country getAttackingCountry()
{
return c1;
}
public Country getDefendingCountry()
{
return c2;
}
}
----------------------------------------------------------------------------------
Also created a turnOrder class but really not worth posting it yet.
Paars