So we have to make a graphics journal/report, so I chose Map War 2 as the project I wanted to make for it (considered a galaxy image generator, but I have more of an itch to make progress on Map War 2, I've worked on it during most of the breaks since I chose it as my project
).
Right now, the map is a square divided into smaller squares... It has to be either 1x1, 2x2, 3x3, 4x4, 5x5, 6x6 and so on... So far, all you can do is setting the name of your nation and your leader (which doesn't affect gameplay anyway
) and choose which zone you want to start on. Then the game will paint that zone red. Which I just chose to be the national color of nation 1. Then it makes 3-5 other nations which don't do anything yet anyway. But I set up the turn and round structure which automagically adapts to the number of nations. And each second, it tells me what round and turn it is, which is very relaxing.
I bet I'll have to make the zones a two-dimensional array *rageragerage*.Here's the code and a skreenshawt:
package mapwar2;
import java.awt.Color;
public class MapWar2
{
public static void main(String[] args)
{
//Make the user's nation, let the user give it a name, name the leader and give the nation 5 resources.
java.util.Scanner tastatur = new java.util.Scanner(System.in);
Nation Nat1;
Nat1 = new Nation();
Nat1.NatColor = Color.red;
System.out.print("Write the name of your nation and press enter: ");
Nat1.Name = tastatur.next();
System.out.print("What is your name, mighty leader of "+Nat1.Name+"? ");
Nat1.Leader = tastatur.next();
Nat1.Resources = 5;
//Generate 2 to 5 other nations.
int NationNumber;
NationNumber = (int)(Math.round((Math.random())*4+2));
System.out.println("Number of other nations: "+NationNumber);
Nation[] Nat = new Nation[NationNumber-1];
//Create the map.
Map Map = new Map();
Map.addZones();
Map.zRepaint = false;
GraphicsWindow window = new GraphicsWindow(); //Creates the graphics window.
window.setSize(Map.sqrtZoneNumber*101+19,Map.sqrtZoneNumber*101+39); //Sets the size of the window.
window.setTitle("Map War 2"); //Sets the title of the window.
window.setVisible(true); //Shows the window.
for (int Round=1;;Round++) //Rounds loop
{
for (int Turn=1;Turn<NationNumber+1;Turn++) //Turns loop
{
System.out.println("It is now round "+Round+", turn "+Turn); //Shows the current round and turn.
if (Round == 1 && Turn == 1) //The first turn in the game...
{
System.out.println("Type the x coordinate of the zone you want to start on (starts at 0) and press Enter. Then type the y coordinate and press Enter.");
Map.xstart = tastatur.nextInt();
Map.ystart = tastatur.nextInt();
Map.zRepaint = true;
}
try {Thread.sleep(1000);} catch (Exception e) {}
}
}
}
}
package mapwar2;
import java.awt.*;
public class GraphicsWindow extends Frame
{
public void paint(Graphics g)
{
//Draw background.
g.fillRect(8, 28, Map.sqrtZoneNumber*101+3, Map.sqrtZoneNumber*101+3);
//Draw initial zones on map.
g.setColor(Color.WHITE);
for (int i=0; i<Map.ZoneNumber; i++)
{
g.fillPolygon(Map.z[i].Shape);
}
for(;;)
{
if (Map.zRepaint == true)
{
g.setColor(Color.red);
g.fillPolygon(Map.z[(Map.sqrtZoneNumber*Map.ystart+Map.xstart)].Shape);
Map.zRepaint = false;
}
}
}
}
package mapwar2;
import java.awt.*;
public class Nation
{
String Leader;
String Name;
Color NatColor; //National color
double Zones;
double Production;
double Resources;
double Technology;
double Trade;
double CityLvl1; //Costs 4 resources, gives 1 production.
double CityLvl2; //Costs 7 resources, gives 2 production.
double CityLvl3; //Costs 13 resources, gives 4 production.
double CityLvl4; //Costs 25 resources, gives 8 production.
double CityLvl5; //Costs 50 resources, gives 20 production.
//Calculates the production of a nation.
double Production()
{
double Prod;
Prod = Zones + CityLvl1 + (2 * CityLvl2) + (4 * CityLvl3) + (8 * CityLvl4) + (20 * CityLvl5);
return Prod;
}
//Calculates the resources of a nation, should be done once a turn.
double Resources()
{
double Res;
Res = Production + Resources + (Trade / 5) + (Technology / 10) - (Resources * Resources / 1000);
return Res;
}
package mapwar2;
public class Map
{
public static int ZoneNumber = 25; //Number of zones on the map. Must be the result of squaring an integer.
public static int sqrtZoneNumber = (int)Math.round(Math.sqrt(ZoneNumber)); //Used for determining zones pr. map height/width.
public static int ZoneReference = 0; //References which zone in the zone array methods should be called on.
public static Zone[] z = new Zone[ZoneNumber]; //Creates the array of zones.
public static boolean zRepaint;
public static int xstart;
public static int ystart;
//Adds zones to the map:
public static void addZones()
{
for (int i=0; i<sqrtZoneNumber; i++)
{
for (int k=0; k<sqrtZoneNumber; k++)
{
z[ZoneReference] = new Zone();
z[ZoneReference].setShape();
z[ZoneReference].Shape.translate(101*i, 101*k);
ZoneReference++;
}
}
}
}[/quote]
[quote=Zone class]package mapwar2;
import java.awt.*;
public class Zone extends Polygon
{
public String Owner;
public Polygon Shape;
public Polygon setShape()
{
Polygon s = new Polygon();
s.addPoint(10, 30);
s.addPoint(110, 30);
s.addPoint(110, 130);
s.addPoint(10, 130);
Shape = s;
return s;
}
public void claim(String claimer, Nation Nat)
{
Owner = claimer;
Nat.Resources = Nat.Resources - 5;
Nat.Production ++;
}
}
Oh and also, teachers can scan our documents for being similar to content on the internet, so I guess I'll be convicted and eternally banned from educat-ions for plagiarizing from myself now. Kol.