Skip to content
Snippets Groups Projects
Commit bcff26a5 authored by haloadam's avatar haloadam
Browse files

Board konstruktor, bár nem grafikus de kellett

parent 5ef3bd1f
No related branches found
No related tags found
No related merge requests found
package arctic_nightmare;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.lang.Math;
public class Board {
private List<Field> fields;
......@@ -17,14 +21,35 @@ public class Board {
return columns;
}
public Board(int field_num , int column_num) {
public Board(int field_num , int column_num, int player_num) {
fields = new ArrayList<Field>();
ArrayList<Item> essentials = new ArrayList<Item>();
essentials.add(new Item("Pistol")); essentials.add(new Item("Flare"));essentials.add( new Item("Cartridge"));
ArrayList<Item> otheritems = new ArrayList<Item>();
otheritems.add(new Item("Food"));otheritems.add(new Item("Rope"));otheritems.add(new Item("DivingSuit")); otheritems.add(new Item("Shovel"));
otheritems.add(new FragileShovel());otheritems.add(new Tent());
Random rnd = new Random(); //random generator for the snow layers
for(int i = 0; i < field_num; ++i) {
if(i % 2 == 0)
fields.add(new StableField());
fields.add(new StableField(rnd.nextInt(5), (Item)null));
else
fields.add(new UnstableField(1,1,(Item)null));
//fields.add(new StableField());
fields.add(new UnstableField(rnd.nextInt(5), rnd.nextInt(player_num),(Item)null));
}
//place essential objects on stable fields
while(essentials.size() != 0){
int idx = rnd.nextInt(fields.size());
if(fields.get(idx).getCapacity() == 10 && fields.get(idx).getItem() == null){
fields.get(idx).addItem(essentials.get(0));
essentials.remove(0);
}
}
//place other items to remaining fields
while(otheritems.size() != 0){
int idx = rnd.nextInt(fields.size());
if(fields.get(idx).getCapacity() != 0 && fields.get(idx).getItem() == null){
fields.get(idx).addItem(otheritems.get(0));
otheritems.remove(0);
}
}
columns = column_num;
setNeighbors();
......
......@@ -70,7 +70,7 @@ public class Game{
void newGame(int fieldsnum, int boardcolumns, int playernum){
board = new Board(fieldsnum, boardcolumns);
board = new Board(fieldsnum, boardcolumns, playernum);
bear = new IceBear(board.getfield(0));
players = new ArrayList<Person>();
board.getfield(0).bear = bear;
......
......@@ -142,7 +142,7 @@ public class GameWindow extends JFrame{
static public Object[] getMapOptions()
{
String[] size = {"3", "4", "5", "6", "7", "8", "9"};
String[] players = {"2", "4", "5", "6"};
String[] players = {"2","3","4", "5", "6"};
String[] difficulty = {"CakeWalk", "Saturdy afternoon", "Sure?", "You are kidding!", "White hell"};
JComboBox<String> combo = new JComboBox<>(size);
JComboBox<String> combo1 = new JComboBox<>(players);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment