Gamers' Lounge :  forum
Arrange meeting times for new games, discuss past games and strategies, socialize with other players. 
The FairConGame code (pls don't post in here)
Posted by: Paars ()
Date: June 07, 2009 01:06AM

As mention in the title please do not post in this topic, instead post comments about the code as well in the faircongame improvement topics, thanks.

I'm to use 2 classes for this project the Main class which will do all the calculating etc, as well as the building of the (J)Frame and components.
And the Countries class which is just the description of the countries.
What I've created so far are just the basic objects and variables I'm going to work with.


The Main class:

/*
Main class, will do all the calculating + build the Frame and components and display output on those frame and components
*/

public class Main
{

// initialize all the countries, class Countries needs a String (name) in the constructor (public Countries)
Countries
Morocco=new Countries("Morocco"),Tangiers=new Countries("Tangiers"),Algiers=new Countries("Algiers"),Tunis=new Countries("Tunis"),Tripoli=new Countries("Tripoli"),Cyrenaica=new Countries("Cyrenaica"),Egypt=new Countries("Egypt"),Palestine=new Countries("Palestine"),Syria=new Countries("Syria"),Cyprus=new Countries("Cyprus"),
Natolia=new Countries("Natolia"),Nicaea=new Countries("Nicaea"),Crete=new Countries("Crete"),Greece=new Countries("Greece"),Macedonia=new Countries("Macedonia"),Byzantium=new Countries("Byzantium"),Bulgaria=new Countries("Bulgaria"),Moldavia=new Countries("Moldavia"),Crimea=new Countries("Crimea"),Ukraine=new Countries("Ukraine"),
Muscovy=new Countries("Muscovy"),Finland=new Countries("Finland"),Sweden=new Countries("Sweden"),Norway=new Countries("Norway"),Scotland=new Countries("Scotland"),Ulster=new Countries("Ulster"),Eire=new Countries("Eire"),Wales=new Countries("Wales"),Northumberland=new Countries("Northumberland"),England=new Countries("England"),
Brittany=new Countries("Brittany"),Gascony=new Countries("Gascony"),Castile=new Countries("Castile"),Leon=new Countries("Leon"),Portugal=new Countries("Portugal"),Aragon=new Countries("Aragon"),Aquataine=new Countries("Aquataine"),Iledefrance=new Countries("Iledefrance"),Normandy=new Countries("Normandy"),
Flanders=new Countries("Flanders"),Holland=new Countries("Holland"),Luxembourg=new Countries("Luxembourg"),Burgundy=new Countries("Burgundy"),Provence=new Countries("Provence"),Corsica=new Countries("Corsica"),Sardinia=new Countries("Sardinia"),Sicilia=new Countries("Sicilia"),Napoli=new Countries("Napoli"),
Roma=new Countries("Roma"),Genoa=new Countries("Genoa"),Helvetica=new Countries("Helvetica"),Rhineland=new Countries("Rhineland"),Saxony=new Countries("Saxony"),Hannover=new Countries("Hannover"),Denmark=new Countries("Denmark"),Brandenburg=new Countries("Brandenburg"),Bohemia=new Countries("Bohemia"),
Austria=new Countries("Austria"),Venetia=new Countries("Venetia"),Dalmatia=new Countries("Dalmatia"),Hungary=new Countries("Hungary"),Poland=new Countries("Poland"),Transylvania=new Countries("Transylvania"),Serbia=new Countries("Serbia"),Wallachia=new Countries("Wallachia"),Prussia=new Countries("Prussia"),
Podolia=new Countries("Podolia"),Lithuania=new Countries("Lithuania"),Livonia=new Countries("Livonia"),Grenada=new Countries("Grenada");


// Adding all the countries to an array of Countries, so we can calculate easier with it with loops etc.
Countries 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
};

// constructor of Main, when Main object is created, this will deal with the building functions etc
public Main()
{
buildNeighbors();
}

// Adding all the neigbhors to the countries, addNeighbors function requires an array of Countries
public void buildNeighbors()
{
Morocco.addNeighbors(new Countries[]{Tangiers});
Tangiers.addNeighbors(new Countries[]{Morocco,Grenada,Algiers});
Algiers.addNeighbors(new Countries[]{Tangiers,Tunis});
Tunis.addNeighbors(new Countries[]{Algiers,Tripoli,Sicilia,Sardinia});
Tripoli.addNeighbors(new Countries[]{Tunis,Cyrenaica});
Cyrenaica.addNeighbors(new Countries[]{Tunis,Egypt});
Egypt.addNeighbors(new Countries[]{Cyrenaica,Palestine});
Palestine.addNeighbors(new Countries[]{Egypt,Syria,Cyprus});
Syria.addNeighbors(new Countries[]{Palestine,Cyprus,Natolia});
Cyprus.addNeighbors(new Countries[]{Palestine,Syria,Natolia});
Natolia.addNeighbors(new Countries[]{Cyprus,Syria,Nicaea});
Nicaea.addNeighbors(new Countries[]{Natolia,Crete,Greece,Byzantium});
Crete.addNeighbors(new Countries[]{Greece,Nicaea});
Greece.addNeighbors(new Countries[]{Crete,Nicaea,Macedonia});
Macedonia.addNeighbors(new Countries[]{Crete,Nicaea,Byzantium,Bulgaria,Napoli,Dalmatia,Serbia});
Byzantium.addNeighbors(new Countries[]{Macedonia,Nicaea,Bulgaria,});
Bulgaria.addNeighbors(new Countries[]{Byzantium,Macedonia,Serbia,Wallachia,Moldavia});
Moldavia.addNeighbors(new Countries[]{Byzantium,Wallachia,Transylvania,Poland,Podolia,Ukraine,Crimea});
Crimea.addNeighbors(new Countries[]{Moldavia,Ukraine});
Ukraine.addNeighbors(new Countries[]{Crimea,Moldavia,Lithuania,Muscovy,Podolia});
Muscovy.addNeighbors(new Countries[]{Ukraine,Lithuania,Livonia,Finland});
Finland.addNeighbors(new Countries[]{Muscovy,Sweden});
Sweden.addNeighbors(new Countries[]{Finland,Denmark,Norway});
Norway.addNeighbors(new Countries[]{Sweden,Denmark,Scotland});
Scotland.addNeighbors(new Countries[]{Norway,Ulster,Northumberland});
Ulster.addNeighbors(new Countries[]{Scotland,Eire,Wales,Northumberland});
Eire.addNeighbors(new Countries[]{Ulster,Wales});
Wales.addNeighbors(new Countries[]{Eire,Ulster,Northumberland,England});
Northumberland.addNeighbors(new Countries[]{Wales,Scotland,Ulster,England});
England.addNeighbors(new Countries[]{Northumberland,Wales,Brittany,Normandy,Flanders,Holland});
Brittany.addNeighbors(new Countries[]{England,Gascony,Iledefrance,Normandy});
Gascony.addNeighbors(new Countries[]{Brittany,Aquataine,Iledefrance,Aragon,Castile});
Castile.addNeighbors(new Countries[]{Gascony,Leon,Aragon,Grenada});
Leon.addNeighbors(new Countries[]{Castile,Grenada,Portugal});
Portugal.addNeighbors(new Countries[]{Leon,Grenada});
Aragon.addNeighbors(new Countries[]{Grenada,Castile,Gascony,Aquataine});
Aquataine.addNeighbors(new Countries[]{Aragon,Gascony,Iledefrance,Provence});
Iledefrance.addNeighbors(new Countries[]{Aquataine,Brittany,Normandy,Burgundy,Provence,Gascony});
Normandy.addNeighbors(new Countries[]{Iledefrance,England,Brittany,Flanders,Burgundy,Luxembourg});
Flanders.addNeighbors(new Countries[]{Normandy,England,Holland,Luxembourg});
Holland.addNeighbors(new Countries[]{Flanders,England,Hannover,Saxony});
Luxembourg.addNeighbors(new Countries[]{Holland,Normandy,Flanders,Saxony,Burgundy,Rhineland,Helvetica});
Burgundy.addNeighbors(new Countries[]{Luxembourg,Iledefrance,Provence,Helvetica,Genoa,Normandy});
Provence.addNeighbors(new Countries[]{Burgundy,Aquataine,Iledefrance,Genoa,Corsica});
Corsica.addNeighbors(new Countries[]{Provence,Genoa,Roma,Sardinia});
Sardinia.addNeighbors(new Countries[]{Corsica,Tunis});
Sicilia.addNeighbors(new Countries[]{Tunis,Napoli});
Napoli.addNeighbors(new Countries[]{Sicilia,Roma,Macedonia});
Roma.addNeighbors(new Countries[]{Napoli,Corsica,Genoa,Venetia});
Genoa.addNeighbors(new Countries[]{Roma,Corsica,Provence,Burgundy,Helvetica,Venetia});
Helvetica.addNeighbors(new Countries[]{Genoa,Burgundy,Luxembourg,Rhineland,Austria,Venetia});
Rhineland.addNeighbors(new Countries[]{Helvetica,Luxembourg,Saxony,Bohemia,Austria});
Saxony.addNeighbors(new Countries[]{Rhineland,Luxembourg,Holland,Hannover,Brandenburg,Bohemia});
Hannover.addNeighbors(new Countries[]{Saxony,Holland,Denmark,Brandenburg});
Denmark.addNeighbors(new Countries[]{Hannover,Norway,Sweden});
Brandenburg.addNeighbors(new Countries[]{Hannover,Saxony,Bohemia,Poland});
Bohemia.addNeighbors(new Countries[]{Brandenburg,Saxony,Rhineland,Austria,Poland,Hungary});
Austria.addNeighbors(new Countries[]{Bohemia,Rhineland,Helvetica,Venetia,Hungary,Dalmatia});
Venetia.addNeighbors(new Countries[]{Austria,Genoa,Roma,Dalmatia,Helvetica});
Dalmatia.addNeighbors(new Countries[]{Venetia,Austria,Hungary,Serbia,Macedonia});
Hungary.addNeighbors(new Countries[]{Dalmatia,Austria,Poland,Transylvania,Serbia,Bohemia});
Poland.addNeighbors(new Countries[]{Hungary,Brandenburg,Moldavia,Podolia,Prussia,Transylvania,Bohemia});
Transylvania.addNeighbors(new Countries[]{Poland,Hungary,Serbia,Wallachia,Moldavia});
Serbia.addNeighbors(new Countries[]{Transylvania,Wallachia,Bulgaria,Macedonia,Dalmatia,Hungary});
Wallachia.addNeighbors(new Countries[]{Serbia,Transylvania,Moldavia,Bulgaria});
Prussia.addNeighbors(new Countries[]{Poland,Podolia,Lithuania});
Podolia.addNeighbors(new Countries[]{Prussia,Poland,Moldavia,Lithuania,Ukraine});
Lithuania.addNeighbors(new Countries[]{Podolia,Livonia,Muscovy,Lithuania,Prussia});
Livonia.addNeighbors(new Countries[]{Lithuania,Muscovy});
Grenada.addNeighbors(new Countries[]{Tangiers,Portugal,Leon,Castile,Aragon});
}



/*
public static void main, this is the main function the program runs when its started.
Will just make a new object of Main class
*/

public static void main(String[] args)
{
new Main();
System.out.println("Program working so far..."); // when this is printed to screen, program's working so far.
}

}

____________________________________________________________________________

The Countries class:

public class Countries
{
private Countries[] neighbor;
private String name;

public Countries(String name)
{
this.name = name;
}

public void addNeighbors(Countries[] n)
{
neighbor = n;
}

public String getName()
{
return name;
}

public Countries[] getNeighbors()
{
return neighbor;
}
}



____________________________________________________________________________

here the link to the files:
[77.251.112.110]

the rar is just the both files put together.

EDIT:
Conquerorgame forum unfortunately doesn't use my tabs for {} so to have a better overview of the code I suggest downloading the files...



Edited 1 time(s). Last edit at 06/07/2009 01:08AM by Paars.

Options: ReplyQuote
Re: The FairConGame code (pls don't post in here)
Posted by: Paars ()
Date: June 08, 2009 10:49AM

Added the screen in the code to be able to pick the number of players for each team.
Updated it all on my webserver as well for downloading and I made an executeble jar file of what's possible so far.
link: [77.251.112.110]



/*
Main class, will do all the calculating + build the Frame and components and display output on those frame and components
*/
import javax.swing.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

public class Main implements MouseListener
{

// initialize all the countries, class Countries needs a String (name) in the constructor (public Countries)
Countries
Morocco=new Countries("Morocco"),Tangiers=new Countries("Tangiers"),Algiers=new Countries("Algiers"),Tunis=new Countries("Tunis"),Tripoli=new Countries("Tripoli"),Cyrenaica=new Countries("Cyrenaica"),Egypt=new Countries("Egypt"),Palestine=new Countries("Palestine"),Syria=new Countries("Syria"),Cyprus=new Countries("Cyprus"),
Natolia=new Countries("Natolia"),Nicaea=new Countries("Nicaea"),Crete=new Countries("Crete"),Greece=new Countries("Greece"),Macedonia=new Countries("Macedonia"),Byzantium=new Countries("Byzantium"),Bulgaria=new Countries("Bulgaria"),Moldavia=new Countries("Moldavia"),Crimea=new Countries("Crimea"),Ukraine=new Countries("Ukraine"),
Muscovy=new Countries("Muscovy"),Finland=new Countries("Finland"),Sweden=new Countries("Sweden"),Norway=new Countries("Norway"),Scotland=new Countries("Scotland"),Ulster=new Countries("Ulster"),Eire=new Countries("Eire"),Wales=new Countries("Wales"),Northumberland=new Countries("Northumberland"),England=new Countries("England"),
Brittany=new Countries("Brittany"),Gascony=new Countries("Gascony"),Castile=new Countries("Castile"),Leon=new Countries("Leon"),Portugal=new Countries("Portugal"),Aragon=new Countries("Aragon"),Aquataine=new Countries("Aquataine"),Iledefrance=new Countries("Iledefrance"),Normandy=new Countries("Normandy"),
Flanders=new Countries("Flanders"),Holland=new Countries("Holland"),Luxembourg=new Countries("Luxembourg"),Burgundy=new Countries("Burgundy"),Provence=new Countries("Provence"),Corsica=new Countries("Corsica"),Sardinia=new Countries("Sardinia"),Sicilia=new Countries("Sicilia"),Napoli=new Countries("Napoli"),
Roma=new Countries("Roma"),Genoa=new Countries("Genoa"),Helvetica=new Countries("Helvetica"),Rhineland=new Countries("Rhineland"),Saxony=new Countries("Saxony"),Hannover=new Countries("Hannover"),Denmark=new Countries("Denmark"),Brandenburg=new Countries("Brandenburg"),Bohemia=new Countries("Bohemia"),
Austria=new Countries("Austria"),Venetia=new Countries("Venetia"),Dalmatia=new Countries("Dalmatia"),Hungary=new Countries("Hungary"),Poland=new Countries("Poland"),Transylvania=new Countries("Transylvania"),Serbia=new Countries("Serbia"),Wallachia=new Countries("Wallachia"),Prussia=new Countries("Prussia"),
Podolia=new Countries("Podolia"),Lithuania=new Countries("Lithuania"),Livonia=new Countries("Livonia"),Grenada=new Countries("Grenada");

// First JFrame, few components to pick the size of the teams, standard = 1 v 1, when chosen close JFrame build new Jframe for calculating
JFrame jfChosingFrame = new JFrame();
JLabel jlTeam1 = new JLabel("Team 1, Number of players"),jlTeam2 = new JLabel("Team 2, Number of players");
JTextField jtfTeam1 = new JTextField("1"), jtfTeam2 = new JTextField("1"),jtfStatusBar = new JTextField("Statusbar:");
JButton jbTeamsPicked = new JButton("Go!");
int pickedTeam1, pickedTeam2; // the variables for the team jtextfields


// Adding all the countries to an array of Countries, so we can calculate easier with it with loops etc.
Countries 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
};

// constructor of Main, when Main object is created, this will deal with the building functions etc
public Main()
{
//teampicking frame building
jfChosingFrame.setTitle("(FairConGame 2.0) Chosing team size");
jfChosingFrame.setLayout(null); // set Layout to null so positioning has to be done manually and .bounds will work
jfChosingFrame.setBounds(250,250,400,400); // 250 px from left and top width 300 height 300
jfChosingFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // make it possible to close the frame

//JLabel building
jlTeam1.setBounds(0,100,190,30);
jlTeam2.setBounds(0,150,190,30);

// Jtextarea building
jtfTeam1.setBounds(200,100,50,30);
jtfTeam2.setBounds(200,150,50,30);
jtfStatusBar.setBounds(0,250,350,30);

// JButton building
jbTeamsPicked.setBounds(260,125,80,30);
jbTeamsPicked.addMouseListener(this); // adding mouselistener

// adding components to JFrame
jfChosingFrame.add(jlTeam1);
jfChosingFrame.add(jlTeam2);

jfChosingFrame.add(jtfTeam1);
jfChosingFrame.add(jtfTeam2);
jfChosingFrame.add(jtfStatusBar);

jfChosingFrame.add(jbTeamsPicked);

// Finising the JFrame
jfChosingFrame.setVisible(true);
buildNeighbors();
}

// Adding all the neigbhors to the countries, addNeighbors function requires an array of Countries
public void buildNeighbors()
{
Morocco.addNeighbors(new Countries[]{Tangiers});
Tangiers.addNeighbors(new Countries[]{Morocco,Grenada,Algiers});
Algiers.addNeighbors(new Countries[]{Tangiers,Tunis});
Tunis.addNeighbors(new Countries[]{Algiers,Tripoli,Sicilia,Sardinia});
Tripoli.addNeighbors(new Countries[]{Tunis,Cyrenaica});
Cyrenaica.addNeighbors(new Countries[]{Tunis,Egypt});
Egypt.addNeighbors(new Countries[]{Cyrenaica,Palestine});
Palestine.addNeighbors(new Countries[]{Egypt,Syria,Cyprus});
Syria.addNeighbors(new Countries[]{Palestine,Cyprus,Natolia});
Cyprus.addNeighbors(new Countries[]{Palestine,Syria,Natolia});
Natolia.addNeighbors(new Countries[]{Cyprus,Syria,Nicaea});
Nicaea.addNeighbors(new Countries[]{Natolia,Crete,Greece,Byzantium});
Crete.addNeighbors(new Countries[]{Greece,Nicaea});
Greece.addNeighbors(new Countries[]{Crete,Nicaea,Macedonia});
Macedonia.addNeighbors(new Countries[]{Crete,Nicaea,Byzantium,Bulgaria,Napoli,Dalmatia,Serbia});
Byzantium.addNeighbors(new Countries[]{Macedonia,Nicaea,Bulgaria,});
Bulgaria.addNeighbors(new Countries[]{Byzantium,Macedonia,Serbia,Wallachia,Moldavia});
Moldavia.addNeighbors(new Countries[]{Byzantium,Wallachia,Transylvania,Poland,Podolia,Ukraine,Crimea});
Crimea.addNeighbors(new Countries[]{Moldavia,Ukraine});
Ukraine.addNeighbors(new Countries[]{Crimea,Moldavia,Lithuania,Muscovy,Podolia});
Muscovy.addNeighbors(new Countries[]{Ukraine,Lithuania,Livonia,Finland});
Finland.addNeighbors(new Countries[]{Muscovy,Sweden});
Sweden.addNeighbors(new Countries[]{Finland,Denmark,Norway});
Norway.addNeighbors(new Countries[]{Sweden,Denmark,Scotland});
Scotland.addNeighbors(new Countries[]{Norway,Ulster,Northumberland});
Ulster.addNeighbors(new Countries[]{Scotland,Eire,Wales,Northumberland});
Eire.addNeighbors(new Countries[]{Ulster,Wales});
Wales.addNeighbors(new Countries[]{Eire,Ulster,Northumberland,England});
Northumberland.addNeighbors(new Countries[]{Wales,Scotland,Ulster,England});
England.addNeighbors(new Countries[]{Northumberland,Wales,Brittany,Normandy,Flanders,Holland});
Brittany.addNeighbors(new Countries[]{England,Gascony,Iledefrance,Normandy});
Gascony.addNeighbors(new Countries[]{Brittany,Aquataine,Iledefrance,Aragon,Castile});
Castile.addNeighbors(new Countries[]{Gascony,Leon,Aragon,Grenada});
Leon.addNeighbors(new Countries[]{Castile,Grenada,Portugal});
Portugal.addNeighbors(new Countries[]{Leon,Grenada});
Aragon.addNeighbors(new Countries[]{Grenada,Castile,Gascony,Aquataine});
Aquataine.addNeighbors(new Countries[]{Aragon,Gascony,Iledefrance,Provence});
Iledefrance.addNeighbors(new Countries[]{Aquataine,Brittany,Normandy,Burgundy,Provence,Gascony});
Normandy.addNeighbors(new Countries[]{Iledefrance,England,Brittany,Flanders,Burgundy,Luxembourg});
Flanders.addNeighbors(new Countries[]{Normandy,England,Holland,Luxembourg});
Holland.addNeighbors(new Countries[]{Flanders,England,Hannover,Saxony});
Luxembourg.addNeighbors(new Countries[]{Holland,Normandy,Flanders,Saxony,Burgundy,Rhineland,Helvetica});
Burgundy.addNeighbors(new Countries[]{Luxembourg,Iledefrance,Provence,Helvetica,Genoa,Normandy});
Provence.addNeighbors(new Countries[]{Burgundy,Aquataine,Iledefrance,Genoa,Corsica});
Corsica.addNeighbors(new Countries[]{Provence,Genoa,Roma,Sardinia});
Sardinia.addNeighbors(new Countries[]{Corsica,Tunis});
Sicilia.addNeighbors(new Countries[]{Tunis,Napoli});
Napoli.addNeighbors(new Countries[]{Sicilia,Roma,Macedonia});
Roma.addNeighbors(new Countries[]{Napoli,Corsica,Genoa,Venetia});
Genoa.addNeighbors(new Countries[]{Roma,Corsica,Provence,Burgundy,Helvetica,Venetia});
Helvetica.addNeighbors(new Countries[]{Genoa,Burgundy,Luxembourg,Rhineland,Austria,Venetia});
Rhineland.addNeighbors(new Countries[]{Helvetica,Luxembourg,Saxony,Bohemia,Austria});
Saxony.addNeighbors(new Countries[]{Rhineland,Luxembourg,Holland,Hannover,Brandenburg,Bohemia});
Hannover.addNeighbors(new Countries[]{Saxony,Holland,Denmark,Brandenburg});
Denmark.addNeighbors(new Countries[]{Hannover,Norway,Sweden});
Brandenburg.addNeighbors(new Countries[]{Hannover,Saxony,Bohemia,Poland});
Bohemia.addNeighbors(new Countries[]{Brandenburg,Saxony,Rhineland,Austria,Poland,Hungary});
Austria.addNeighbors(new Countries[]{Bohemia,Rhineland,Helvetica,Venetia,Hungary,Dalmatia});
Venetia.addNeighbors(new Countries[]{Austria,Genoa,Roma,Dalmatia,Helvetica});
Dalmatia.addNeighbors(new Countries[]{Venetia,Austria,Hungary,Serbia,Macedonia});
Hungary.addNeighbors(new Countries[]{Dalmatia,Austria,Poland,Transylvania,Serbia,Bohemia});
Poland.addNeighbors(new Countries[]{Hungary,Brandenburg,Moldavia,Podolia,Prussia,Transylvania,Bohemia});
Transylvania.addNeighbors(new Countries[]{Poland,Hungary,Serbia,Wallachia,Moldavia});
Serbia.addNeighbors(new Countries[]{Transylvania,Wallachia,Bulgaria,Macedonia,Dalmatia,Hungary});
Wallachia.addNeighbors(new Countries[]{Serbia,Transylvania,Moldavia,Bulgaria});
Prussia.addNeighbors(new Countries[]{Poland,Podolia,Lithuania});
Podolia.addNeighbors(new Countries[]{Prussia,Poland,Moldavia,Lithuania,Ukraine});
Lithuania.addNeighbors(new Countries[]{Podolia,Livonia,Muscovy,Lithuania,Prussia});
Livonia.addNeighbors(new Countries[]{Lithuania,Muscovy});
Grenada.addNeighbors(new Countries[]{Tangiers,Portugal,Leon,Castile,Aragon});
}



/*
public static void main, this is the main function the program runs when its started.
Will just make a new object of Main class
*/

public static void main(String[] args)
{
new Main();
System.out.println("Program working so far..."); // when this is printed to screen, program's working so far.
}



public void mouseClicked(MouseEvent e)
{
if(e.getSource() == jbTeamsPicked)
{
try
{
pickedTeam1 = Integer.valueOf(jtfTeam1.getText()); // try typecasting the team textfields to ints
pickedTeam2 = Integer.valueOf(jtfTeam2.getText());
if(pickedTeam1 < 1 || pickedTeam1 > 14 || pickedTeam2 < 1 || pickedTeam2 >14 || pickedTeam1 + pickedTeam2 > 16)
{
jtfStatusBar.setText("Error: pick valid numbers no less then 1 no more then 16");
}
}
catch(Exception exc)
{
jtfStatusBar.setText("Only numbers allowed");
}
}
}

public void mousePressed(MouseEvent e)
{
//forced to implement this function - mouselistener
}

public void mouseReleased(MouseEvent e)
{
//forced to implement this function - mouselistener
}

public void mouseEntered(MouseEvent e)
{
//forced to implement this function - mouselistener
}

public void mouseExited(MouseEvent e)
{
//forced to implement this function - mouselistener
}
}



Edited 1 time(s). Last edit at 06/08/2009 10:54AM by Paars.

Options: ReplyQuote
Re: The FairConGame code (pls don't post in here)
Posted by: Paars ()
Date: June 18, 2009 12:24AM

Added a little bit to the program which still isn't doing much, :) picking the teamsizes now works. Will post code in forum again when there are bigger changes, however possible to download from [77.251.112.110]
the new code and the new executable.

Options: ReplyQuote
Re: The FairConGame code (pls don't post in here)
Posted by: Paars ()
Date: July 01, 2009 05:16PM

Ok I think I finally finished the basic algorithm for the faircongame2. But should still be buggy overall, when found real errors in the calculations etc please report in the other thread.

Tomorrow I might have some free time, to tweak in some extra stuff.

You can add in up to 16 players then all buttons show up for those that you can click which will give information about the countries it got and how many steps they are away.

Won't show disputed countries yet(coming soon). I've placed the executable jar file and the source code again on my webserver which is this adress: [77.251.112.110]

Options: ReplyQuote
Re: The FairConGame code (pls don't post in here)
Posted by: Paars ()
Date: July 07, 2009 12:31AM

Small update again in program a lot of extra coding, due to my crappy coding its getting big. Also got lazy on the commentary, the new game button doesn;t work at the end yet. Also Disputed countries are not shown yet.

Link for the executable jar and the source files.

[77.251.112.110]

Main class
___________________________________________________________________________

/*
Main class, will do all the calculating + build the Frame and components and display output on those frame and components
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Main implements MouseListener
{

// initialize all the countries, class Countries needs a String (name) in the constructor (public Countries)
Countries
Morocco=new Countries("Morocco"),Tangiers=new Countries("Tangiers"),Algiers=new Countries("Algiers"),Tunis=new Countries("Tunis"),Tripoli=new Countries("Tripoli"),Cyrenaica=new Countries("Cyrenaica"),Egypt=new Countries("Egypt"),Palestine=new Countries("Palestine"),Syria=new Countries("Syria"),Cyprus=new Countries("Cyprus"),
Natolia=new Countries("Natolia"),Nicaea=new Countries("Nicaea"),Crete=new Countries("Crete"),Greece=new Countries("Greece"),Macedonia=new Countries("Macedonia"),Byzantium=new Countries("Byzantium"),Bulgaria=new Countries("Bulgaria"),Moldavia=new Countries("Moldavia"),Crimea=new Countries("Crimea"),Ukraine=new Countries("Ukraine"),
Muscovy=new Countries("Muscovy"),Finland=new Countries("Finland"),Sweden=new Countries("Sweden"),Norway=new Countries("Norway"),Scotland=new Countries("Scotland"),Ulster=new Countries("Ulster"),Eire=new Countries("Eire"),Wales=new Countries("Wales"),Northumberland=new Countries("Northumberland"),England=new Countries("England"),
Brittany=new Countries("Brittany"),Gascony=new Countries("Gascony"),Castile=new Countries("Castile"),Leon=new Countries("Leon"),Portugal=new Countries("Portugal"),Aragon=new Countries("Aragon"),Aquataine=new Countries("Aquataine"),Iledefrance=new Countries("Iledefrance"),Normandy=new Countries("Normandy"),
Flanders=new Countries("Flanders"),Holland=new Countries("Holland"),Luxembourg=new Countries("Luxembourg"),Burgundy=new Countries("Burgundy"),Provence=new Countries("Provence"),Corsica=new Countries("Corsica"),Sardinia=new Countries("Sardinia"),Sicilia=new Countries("Sicilia"),Napoli=new Countries("Napoli"),
Roma=new Countries("Roma"),Genoa=new Countries("Genoa"),Helvetica=new Countries("Helvetica"),Rhineland=new Countries("Rhineland"),Saxony=new Countries("Saxony"),Hannover=new Countries("Hannover"),Denmark=new Countries("Denmark"),Brandenburg=new Countries("Brandenburg"),Bohemia=new Countries("Bohemia"),
Austria=new Countries("Austria"),Venetia=new Countries("Venetia"),Dalmatia=new Countries("Dalmatia"),Hungary=new Countries("Hungary"),Poland=new Countries("Poland"),Transylvania=new Countries("Transylvania"),Serbia=new Countries("Serbia"),Wallachia=new Countries("Wallachia"),Prussia=new Countries("Prussia"),
Podolia=new Countries("Podolia"),Lithuania=new Countries("Lithuania"),Livonia=new Countries("Livonia"),Grenada=new Countries("Grenada");

// First JFrame, few components to pick the size of the teams, standard = 1 v 1, when chosen close JFrame build new Jframe for calculating
JFrame jfChosingFrame = new JFrame(), jfCalculatingFrame;
JComboBox[] jcbArrayCountries1, jcbArrayCountries2;
JLabel jlTeam1 = new JLabel("Team 1, Number of players"),jlTeam2 = new JLabel("Team 2, Number of players");
JTextField jtfTeam1 = new JTextField("1"), jtfTeam2 = new JTextField("1"),jtfStatusBar = new JTextField("Statusbar:");
JButton jbTeamsPicked = new JButton("Go!"), jbCalculate = new JButton("calculate"),jbNewCalculation;
int pickedTeam1, pickedTeam2; // the variables for the team jtextfields
Countries [] team1,team2;
JTextArea jtaDisplayArea = new JTextArea();
JPanel[] jpanelArray;
JLabel[] labelArray;
int[][] countryAmount;
int playerIndex;




// Adding all the countries to an array of Countries, so we can calculate easier with it with loops etc.
Countries 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
};

String[] strArrayCountries = new String[allCountriesArray.length];

// constructor of Main, when Main object is created, this will deal with the building functions etc
public Main()
{
//teampicking frame building
jfChosingFrame.setTitle("(FairConGame 2.0) Chosing team size");
jfChosingFrame.setLayout(null); // set Layout to null so positioning has to be done manually and .bounds will work
jfChosingFrame.setBounds(250,250,400,400); // 250 px from left and top width 300 height 300
jfChosingFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // make it possible to close the frame

//JLabel building
jlTeam1.setBounds(0,100,190,30);
jlTeam2.setBounds(0,150,190,30);

// Jtextarea building
jtfTeam1.setBounds(200,100,50,30);
jtfTeam2.setBounds(200,150,50,30);
jtfStatusBar.setBounds(0,250,350,30);

// JButton building
jbTeamsPicked.setBounds(260,125,80,30);
jbTeamsPicked.addMouseListener(this); // adding mouselistener
jbCalculate.addMouseListener(this);

// adding components to JFrame
jfChosingFrame.add(jlTeam1);
jfChosingFrame.add(jlTeam2);

jfChosingFrame.add(jtfTeam1);
jfChosingFrame.add(jtfTeam2);
jfChosingFrame.add(jtfStatusBar);

jfChosingFrame.add(jbTeamsPicked);

// Finising the JFrame
jfChosingFrame.setVisible(true);
buildNeighbors();
}

// Adding all the neigbhors to the countries, addNeighbors function requires an array of Countries
public void buildNeighbors()
{
Morocco.addNeighbors(new Countries[]{Tangiers});
Tangiers.addNeighbors(new Countries[]{Morocco,Grenada,Algiers});
Algiers.addNeighbors(new Countries[]{Tangiers,Tunis});
Tunis.addNeighbors(new Countries[]{Algiers,Tripoli,Sicilia,Sardinia});
Tripoli.addNeighbors(new Countries[]{Tunis,Cyrenaica});
Cyrenaica.addNeighbors(new Countries[]{Tunis,Egypt});
Egypt.addNeighbors(new Countries[]{Cyrenaica,Palestine});
Palestine.addNeighbors(new Countries[]{Egypt,Syria,Cyprus});
Syria.addNeighbors(new Countries[]{Palestine,Cyprus,Natolia});
Cyprus.addNeighbors(new Countries[]{Palestine,Syria,Natolia});
Natolia.addNeighbors(new Countries[]{Cyprus,Syria,Nicaea});
Nicaea.addNeighbors(new Countries[]{Natolia,Crete,Greece,Byzantium});
Crete.addNeighbors(new Countries[]{Greece,Nicaea});
Greece.addNeighbors(new Countries[]{Crete,Nicaea,Macedonia});
Macedonia.addNeighbors(new Countries[]{Crete,Nicaea,Byzantium,Bulgaria,Napoli,Dalmatia,Serbia});
Byzantium.addNeighbors(new Countries[]{Macedonia,Nicaea,Bulgaria,});
Bulgaria.addNeighbors(new Countries[]{Byzantium,Macedonia,Serbia,Wallachia,Moldavia});
Moldavia.addNeighbors(new Countries[]{Byzantium,Wallachia,Transylvania,Poland,Podolia,Ukraine,Crimea});
Crimea.addNeighbors(new Countries[]{Moldavia,Ukraine});
Ukraine.addNeighbors(new Countries[]{Crimea,Moldavia,Lithuania,Muscovy,Podolia});
Muscovy.addNeighbors(new Countries[]{Ukraine,Lithuania,Livonia,Finland});
Finland.addNeighbors(new Countries[]{Muscovy,Sweden});
Sweden.addNeighbors(new Countries[]{Finland,Denmark,Norway});
Norway.addNeighbors(new Countries[]{Sweden,Denmark,Scotland});
Scotland.addNeighbors(new Countries[]{Norway,Ulster,Northumberland});
Ulster.addNeighbors(new Countries[]{Scotland,Eire,Wales,Northumberland});
Eire.addNeighbors(new Countries[]{Ulster,Wales});
Wales.addNeighbors(new Countries[]{Eire,Ulster,Northumberland,England});
Northumberland.addNeighbors(new Countries[]{Wales,Scotland,Ulster,England});
England.addNeighbors(new Countries[]{Northumberland,Wales,Brittany,Normandy,Flanders,Holland});
Brittany.addNeighbors(new Countries[]{England,Gascony,Iledefrance,Normandy});
Gascony.addNeighbors(new Countries[]{Brittany,Aquataine,Iledefrance,Aragon,Castile});
Castile.addNeighbors(new Countries[]{Gascony,Leon,Aragon,Grenada});
Leon.addNeighbors(new Countries[]{Castile,Grenada,Portugal});
Portugal.addNeighbors(new Countries[]{Leon,Grenada});
Aragon.addNeighbors(new Countries[]{Grenada,Castile,Gascony,Aquataine});
Aquataine.addNeighbors(new Countries[]{Aragon,Gascony,Iledefrance,Provence});
Iledefrance.addNeighbors(new Countries[]{Aquataine,Brittany,Normandy,Burgundy,Provence,Gascony});
Normandy.addNeighbors(new Countries[]{Iledefrance,England,Brittany,Flanders,Burgundy,Luxembourg});
Flanders.addNeighbors(new Countries[]{Normandy,England,Holland,Luxembourg});
Holland.addNeighbors(new Countries[]{Flanders,England,Hannover,Saxony});
Luxembourg.addNeighbors(new Countries[]{Holland,Normandy,Flanders,Saxony,Burgundy,Rhineland,Helvetica});
Burgundy.addNeighbors(new Countries[]{Luxembourg,Iledefrance,Provence,Helvetica,Genoa,Normandy});
Provence.addNeighbors(new Countries[]{Burgundy,Aquataine,Iledefrance,Genoa,Corsica});
Corsica.addNeighbors(new Countries[]{Provence,Genoa,Roma,Sardinia});
Sardinia.addNeighbors(new Countries[]{Corsica,Tunis});
Sicilia.addNeighbors(new Countries[]{Tunis,Napoli});
Napoli.addNeighbors(new Countries[]{Sicilia,Roma,Macedonia});
Roma.addNeighbors(new Countries[]{Napoli,Corsica,Genoa,Venetia});
Genoa.addNeighbors(new Countries[]{Roma,Corsica,Provence,Burgundy,Helvetica,Venetia});
Helvetica.addNeighbors(new Countries[]{Genoa,Burgundy,Luxembourg,Rhineland,Austria,Venetia});
Rhineland.addNeighbors(new Countries[]{Helvetica,Luxembourg,Saxony,Bohemia,Austria});
Saxony.addNeighbors(new Countries[]{Rhineland,Luxembourg,Holland,Hannover,Brandenburg,Bohemia});
Hannover.addNeighbors(new Countries[]{Saxony,Holland,Denmark,Brandenburg});
Denmark.addNeighbors(new Countries[]{Hannover,Norway,Sweden});
Brandenburg.addNeighbors(new Countries[]{Hannover,Saxony,Bohemia,Poland});
Bohemia.addNeighbors(new Countries[]{Brandenburg,Saxony,Rhineland,Austria,Poland,Hungary});
Austria.addNeighbors(new Countries[]{Bohemia,Rhineland,Helvetica,Venetia,Hungary,Dalmatia});
Venetia.addNeighbors(new Countries[]{Austria,Genoa,Roma,Dalmatia,Helvetica});
Dalmatia.addNeighbors(new Countries[]{Venetia,Austria,Hungary,Serbia,Macedonia});
Hungary.addNeighbors(new Countries[]{Dalmatia,Austria,Poland,Transylvania,Serbia,Bohemia});
Poland.addNeighbors(new Countries[]{Hungary,Brandenburg,Moldavia,Podolia,Prussia,Transylvania,Bohemia});
Transylvania.addNeighbors(new Countries[]{Poland,Hungary,Serbia,Wallachia,Moldavia});
Serbia.addNeighbors(new Countries[]{Transylvania,Wallachia,Bulgaria,Macedonia,Dalmatia,Hungary});
Wallachia.addNeighbors(new Countries[]{Serbia,Transylvania,Moldavia,Bulgaria});
Prussia.addNeighbors(new Countries[]{Poland,Podolia,Lithuania});
Podolia.addNeighbors(new Countries[]{Prussia,Poland,Moldavia,Lithuania,Ukraine});
Lithuania.addNeighbors(new Countries[]{Podolia,Livonia,Muscovy,Lithuania,Prussia});
Livonia.addNeighbors(new Countries[]{Lithuania,Muscovy});
Grenada.addNeighbors(new Countries[]{Tangiers,Portugal,Leon,Castile,Aragon});
}



/*
public static void main, this is the main function the program runs when its started.
Will just make a new object of Main class
*/

public static void main(String[] args)
{
new Main();
System.out.println("Program working so far..."); // when this is printed to screen, program's working so far.
}



public void mouseClicked(MouseEvent e)
{
if(e.getSource() == jbTeamsPicked)
{
try
{
pickedTeam1 = Integer.valueOf(jtfTeam1.getText()); // try typecasting the team textfields to ints
pickedTeam2 = Integer.valueOf(jtfTeam2.getText());
if(pickedTeam1 < 1 || pickedTeam1 > 15 || pickedTeam2 < 1 || pickedTeam2 >15 || pickedTeam1 + pickedTeam2 > 16)
{
jtfStatusBar.setText("Error: pick valid numbers no less than 1 no more than 16");
}
else
{
buildCalculatingFrame();
}
}
catch(Exception exc)
{
jtfStatusBar.setText("Only numbers allowed");
}
}
// if button jbcalculate is pressed
else if(e.getSource() == jbCalculate)
{
// get selected Items of jcomboboxes in a String array
String[] strPickedCountriesArray = new String[pickedTeam1 + pickedTeam2];
for(int i=0;i < pickedTeam1; i++)
strPickedCountriesArray = (String) jcbArrayCountries1.getSelectedItem();
for(int i=0;i < pickedTeam2; i++)
strPickedCountriesArray[pickedTeam1 +i] = (String) jcbArrayCountries2.getSelectedItem();

// test print all pickedCountries (Can be removed later)
for(int i=0;i < strPickedCountriesArray.length;i++)
System.out.print(strPickedCountriesArray +", ");
System.out.println();

// check if there are no double countries, if not continue with program...
boolean boolContinue=true;
for(int i=0;i < strPickedCountriesArray.length;i++)
{
if(!boolContinue)
break;
for(int j=0;j < strPickedCountriesArray.length;j++)
{
if(!boolContinue)
break;
if(i != j)
{
if(strPickedCountriesArray.equals(strPickedCountriesArray[j]))
{
jtfStatusBar.setText("No double country selection:" +strPickedCountriesArray);
boolContinue=false;
}
}
}
}

//if(boolContinue == true)continue with program
if(boolContinue)
{
jtfStatusBar.setText("Continue with program (not done yet)");

// get a countryarray (objects)of picked countries, by StringCompare
Countries[] chosenCountriesArray = new Countries[strPickedCountriesArray.length];
for(int i=0; i < chosenCountriesArray.length;i++)

for(int j=0; j < allCountriesArray.length;j++)
{
if(strPickedCountriesArray.equals(allCountriesArray[j].getName()))
{
chosenCountriesArray = allCountriesArray[j];
break;
}
}
calculateRoutes(chosenCountriesArray);
}
}
else if(e.getSource() == jbNewCalculation)
{
jtaDisplayArea.setText("Doesn't work yet...");
}
else
{
JPanel playerName = (JPanel) e.getSource();
jtaDisplayArea.setBounds(10,350,700,400);
jtaDisplayArea.setText("");
jtaDisplayArea.append(getInfo(playerName.getName()));
}
}

public void buildCalculatingFrame()
{
// disable jfChosingFrame
jfChosingFrame.setVisible(false);

// time to build up calculatingframe
jfCalculatingFrame = new JFrame();
jfCalculatingFrame.setTitle("Calculating Frame");
jfCalculatingFrame.setBounds(100,100,800,800);
jfCalculatingFrame.setLayout(null);
jfCalculatingFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jfCalculatingFrame.setVisible(true);

jcbArrayCountries1 = new JComboBox[pickedTeam1];
jcbArrayCountries2 = new JComboBox[pickedTeam2];

// get a strArray of all country names for the JComboboxes
for(int i=0;i < allCountriesArray.length;i++)
{
strArrayCountries = allCountriesArray.getName();
}

// build up jcomboboxes for team 1, add to frame
for(int i=0;i < pickedTeam1; i++)
{
jcbArrayCountries1 = new JComboBox(strArrayCountries);
jcbArrayCountries1.setBounds(50,50+(i*40),200,30);
jfCalculatingFrame.add(jcbArrayCountries1);
}

// build up jcomboboxes for team 2, add to frame
for(int i=0;i < pickedTeam2; i++)
{
jcbArrayCountries2 = new JComboBox(strArrayCountries);
jcbArrayCountries2.setBounds(500,50+(i*40),200,30);
jfCalculatingFrame.add(jcbArrayCountries2);
}

// relative positioning of the Calculating button
if(pickedTeam1 >= pickedTeam2)
{
jbCalculate.setBounds(325,jcbArrayCountries1[pickedTeam1-1].getY()+50,100,30);
}
else
{
jbCalculate.setBounds(325,jcbArrayCountries2[pickedTeam2-1].getY()+50,100,30);
}

jtfStatusBar.setText("Status: ");
jtfStatusBar.setBounds(50,710,700,30);
jfCalculatingFrame.add(jbCalculate);
jfCalculatingFrame.add(jtfStatusBar);
}

public void mousePressed(MouseEvent e)
{
//forced to implement this function - mouselistener
}

public void mouseReleased(MouseEvent e)
{
//forced to implement this function - mouselistener
}

public void mouseEntered(MouseEvent e)
{
//forced to implement this function - mouselistener
}

public void mouseExited(MouseEvent e)
{
//forced to implement this function - mouselistener
}

// this code is gonna get messy
public void calculateRoutes(Countries[] c)
{
Countries[] allCountriesArray2 = new Countries[allCountriesArray.length];
for(int i=0; i < c.length;i++)
{

int steps =0,stepscounter=0,stepscounter2=0;
c.setOwner2(c.getName());
int countryCounter=0,countryCounter2=0; //allCountriesArray.length;
int tempStop=0;
for(int j=0;j < allCountriesArray2.length;j++)
{
if(allCountriesArray2[j]!=null)
{
allCountriesArray2[j].setDone(false);
}
//else{System.out.print(",bitch"+j);}
}
allCountriesArray2 = new Countries[allCountriesArray.length];
allCountriesArray2[0] = c;
allCountriesArray2[0].setDone(true);
allCountriesArray2[0].setSteps(0);
while(countryCounter < allCountriesArray.length-1 && tempStop < 150)
{

Countries[] neighborArray;
neighborArray = allCountriesArray2[countryCounter2].getNeighbors();

//System.out.println("countryname: " + allCountriesArray2[countryCounter2].getName());
System.out.println(neighborArray[0].getName()+" : " +neighborArray[0].getDone());

for(int j=0;j < neighborArray.length;j++)
{
if(!neighborArray[j].getDone())
{
if(allCountriesArray2[countryCounter2].getOwner2().equals(c.getName()) || allCountriesArray2[countryCounter2].getDisputed() > 0)
{
if(allCountriesArray2[countryCounter2].getSteps()+1 < neighborArray[j].getSteps())
{
neighborArray[j].setSteps(allCountriesArray2[countryCounter2].getSteps()+1);
neighborArray[j].setOwner2(c.getName());
}
else if(allCountriesArray2[countryCounter2].getSteps()+1 == neighborArray[j].getSteps())
{
neighborArray[j].setOwner2(neighborArray[j].getOwner2() + c.getName());
neighborArray[j].setDisputed();
}
}

neighborArray[j].setDone(true);
countryCounter++;

allCountriesArray2[countryCounter] = neighborArray[j];
System.out.println("added: "+ neighborArray[j].getName());
}
}
countryCounter2 ++;
}


}
showResultScreen(c);

}

public void showResultScreen(Countries[] c)
{
countryAmount = new int[pickedTeam1 + pickedTeam2][1];
// clist1 array is the original picked countries array
JFrame resultFrame = new JFrame();
resultFrame.setBounds(100,100,800,800);
resultFrame.setLayout(null);
resultFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jpanelArray = new JPanel[pickedTeam1+pickedTeam2];
labelArray = new JLabel[pickedTeam1+pickedTeam2];

int[] countryNumbers = getCountriesNumber(c);
int total1=0;
int total2=0;

for(int i=0;i<pickedTeam1;i++)
total1+= countryNumbers;

for(int i=0;i<pickedTeam2;i++)
total2+= countryNumbers[i+pickedTeam1];

System.out.println("dadada"+ total1 + ":" + total2);

JLabel jlTotalCountriesTeam1 = new JLabel("Team 1 total: "+total1), jlTotalCountriesTeam2 = new JLabel("Team 2 total: "+total2);
JPanel jpTotalCountriesTeam1=new JPanel(), jpTotalCountriesTeam2=new JPanel();

for(int i=0; i < pickedTeam1; i++)
{
labelArray = new JLabel(c.getName() + " " + countryNumbers);
jpanelArray = new JPanel();
jpanelArray.setName(c.getName());
jpanelArray.add(labelArray);
jpanelArray.setBounds(10,10+(35*i),200,30);
jpanelArray.addMouseListener(this);
jpanelArray.setBackground(Color.gray);
jpanelArray.setForeground(Color.green);
resultFrame.add(jpanelArray);
}
jpTotalCountriesTeam1.add(jlTotalCountriesTeam1);
jpTotalCountriesTeam1.setBounds(10,10+(35 * pickedTeam1+35),200,30);
jpTotalCountriesTeam1.setBackground(Color.green);
jpTotalCountriesTeam1.setForeground(Color.green);
resultFrame.add(jpTotalCountriesTeam1);

for(int i=0; i < pickedTeam2; i++)
{
labelArray[i+pickedTeam1] = new JLabel(c[i+pickedTeam1].getName() + " " + countryNumbers[i+pickedTeam1]);
jpanelArray[i+pickedTeam1] = new JPanel();
jpanelArray[i+pickedTeam1].setName(c[i+pickedTeam1].getName());
jpanelArray[i+pickedTeam1].add(labelArray[i+pickedTeam1]);
jpanelArray[i+pickedTeam1].setBounds(500,10+(35*i),200,30);
jpanelArray[i+pickedTeam1].addMouseListener(this);
jpanelArray[i+pickedTeam1].setBackground(Color.gray);
jpanelArray[i+pickedTeam1].setForeground(Color.green);
resultFrame.add(jpanelArray[i+pickedTeam1]);
}
jpTotalCountriesTeam2.add(jlTotalCountriesTeam2);
jpTotalCountriesTeam2.setBounds(500,10+(35 * pickedTeam2+35),200,30);
jpTotalCountriesTeam2.setBackground(Color.green);
jpTotalCountriesTeam2.setForeground(Color.green);
resultFrame.add(jpTotalCountriesTeam2);

resultFrame.add(jtaDisplayArea);

for(int i =0; i < pickedTeam1;i++)
c.setCountryList(getInfo(c.getName()));
for(int i=pickedTeam1;i < (pickedTeam1 +pickedTeam2);i++)
c.setCountryList(getInfo(c.getName()));

jbNewCalculation = new JButton("new game");
jbNewCalculation.setBounds(300,50,150,30);
jbNewCalculation.addMouseListener(this);
resultFrame.add(jbNewCalculation);


resultFrame.setVisible(true);


}
public String getInfo(String name)
{
String strReturn = "";

for(int i=0;i < 20; i++)
{
strReturn += "\nsteps " +i+ ": ";
for(int j=0;j<allCountriesArray.length;j++)
{
if(name.equals(allCountriesArray[j].getOwner2()) && allCountriesArray[j].getSteps()==i)
{
strReturn += allCountriesArray[j].getName()+" , ";
}
}
}
System.out.println("\n name : "+name);
return strReturn;
}

public int[] getCountriesNumber(Countries[] c)
{
int[] intReturnArray = new int[c.length];
for(int i=0;i < c.length;i++)
{
int tempNumber=0;
for(int j=0;j < allCountriesArray.length;j++)
{
if(c.getName().equals(allCountriesArray[j].getOwner2()))
tempNumber++;
}
intReturnArray = tempNumber;
}
return intReturnArray;
}
}




________________________________________________________________________
Countries Class
________________________________________________________________________

public class Countries
{
private Countries[] neighbor;
private Countries owner;
private String name, owner2="", countryList;
private int steps=100,disputed=0;
private boolean done;

public Countries(String name)
{
this.name = name;
}

public void addNeighbors(Countries[] n)
{
neighbor = n;
}

public String getName()
{
return name;
}

public Countries[] getNeighbors()
{
return neighbor;
}

public void setOwner(Countries owner)
{
this.owner = owner;
}

public void setOwner2(String owner2)
{
this.owner2 = owner2;
}

public Countries getOwner()
{
return owner;
}

public String getOwner2()
{
return owner2;
}

public void setDone(boolean done)
{
this.done = done;
}

public boolean getDone()
{
return done;
}

public void setSteps(int steps)
{
this.steps = steps;
}
public int getSteps()
{
return steps;
}

public void setDisputed()
{
disputed++;
}

public int getDisputed()
{
return disputed;
}

public void setCountryList(String s)
{
countryList = s;
}

public String getCountryList()
{
return countryList;
}
}

Options: ReplyQuote
Re: The FairConGame code (pls don't post in here)
Posted by: Paars ()
Date: July 09, 2009 06:13AM

Yay! Misson.... failed, I'm going to restart the whole damn thing all over again.

Options: ReplyQuote


Sorry, only registered users may post in this forum.