diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Block.java b/Arctic_Nigthmare/src/arctic_nightmare/Block.java new file mode 100644 index 0000000000000000000000000000000000000000..0c228bce7ebee42f7485cde4dcb4c04e8aede883 --- /dev/null +++ b/Arctic_Nigthmare/src/arctic_nightmare/Block.java @@ -0,0 +1,56 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package arctic_nightmare; + +import java.awt.Color; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JLabel; + +/** + * + * @author csellar + */ +public class Block extends JLabel{ + GameWindow window; + Field field; + + Block(GameWindow window, Field field) + { + this.window = window; + this.field = field; + setSize(40, 40); + setOpaque(true); + setBackground(Color.blue); + setVisible(true); + addMouseListener(new MouseAdapter() + { + public void mouseClicked(MouseEvent e) + { + //label.setBackground(Color.red); + //frame = new JFrame("new frame"); + //frame.setVisible(true); + window.event(field); + } + }); + } + + void draw() + { + if(field.snow > 0) + { + if(field.hasIgloo) + {} + if(field.tent != null) + {} + for(Person person : field.persons) + {} + } + else + {} + + } +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Board.java b/Arctic_Nigthmare/src/arctic_nightmare/Board.java index 231039e2782e90aae88378eba4e97582d8dcf97e..cb3dde598c20b5960ff53c8c6bc08dd809e23d0c 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Board.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Board.java @@ -7,9 +7,10 @@ public class Board { /*Only when the fields lay in grid, and board's size is rows*column*/ private int columns = -1; - /*Only for proto*/ - private int id; - private int idcounter = 1; + public int size() + { + return fields.size(); + } public Board(int field_num , int column_num) { fields = new ArrayList<Field>(); @@ -21,12 +22,10 @@ public class Board { } columns = column_num; setNeighbors(); - id = idcounter++; } public Board() { fields = new ArrayList<Field>(); - id = idcounter++; } public void addField(Field f) { diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Game.java b/Arctic_Nigthmare/src/arctic_nightmare/Game.java index c73ee7ecb2b0740267315abf08cecbc9b746fe01..5298d5fdcbca97dec6b3d15f4b83c3856a9aafcf 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Game.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Game.java @@ -1,7 +1,13 @@ package arctic_nightmare; +import java.awt.Color; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; public class Game{ private Person actualPlayer; @@ -10,11 +16,10 @@ public class Game{ private IceBear bear; private boolean win; - /*Only for proto*/ - private int id; - private static int idcounter = 1; private List<Item> items; + private GameWindow window; + Game(){ actualPlayer = null; @@ -22,10 +27,11 @@ public class Game{ board = null; bear = null; win = false; - id = idcounter++; items = new ArrayList<Item> (); + window = new GameWindow(this); } + void gameOver(){} public int getPlayerNumber() { @@ -38,14 +44,13 @@ public class Game{ if(nextPlayerIdx >= players.size()) nextPlayerIdx = 0; setActualPerson(nextPlayerIdx); - } + } - public void play() { + public void play(Event event) { try { - while(true) { - actualPlayer.enablePlayer(); - nextPlayer(); - } + actualPlayer.event(event); + if (0 >= actualPlayer.getWork()) nextPlayer(); + window.drawBoard(); } catch(PlayerDiedException e) { gameOver(); @@ -72,6 +77,7 @@ public class Game{ newperson.addField(board.getfield((i + 1) * 2)); } actualPlayer = players.get(0); + window.setBoard(board); } void setActualPerson(int idx){ diff --git a/Arctic_Nigthmare/src/arctic_nightmare/GameWindow.java b/Arctic_Nigthmare/src/arctic_nightmare/GameWindow.java new file mode 100644 index 0000000000000000000000000000000000000000..7197eb33fa8cc55432e0a1878d8578e075c67a7c --- /dev/null +++ b/Arctic_Nigthmare/src/arctic_nightmare/GameWindow.java @@ -0,0 +1,64 @@ +package arctic_nightmare; + +import java.awt.Frame; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import javax.swing.JFrame; + + +public class GameWindow extends JFrame{ + private boolean active; + private Game game; + private List<Block> fields; + private int lastclick; + + GameWindow(Game game) + { + setSize(400, 400); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + fields = null; + this.game = game; + setMenu(); + active = true; + } + + public void drawBoard() + { + for (Block block : fields) + { + block.draw(); + } + } + + public void setMenu() // for adding the screen the game configuring contros. If board was present it has to be removed first + { + } + + public void setBoard(Board board)// for adding the screen the board and the other buttons, other controls has to be removed + { + fields = new ArrayList<>(); + for (int i = 0;board.size() > i; i++) + { + //magic happens + //fields.put(new Block(this), board.getfield(i)); + fields.add(new Block(this, board.getfield(i))); + } + } + + public void event(Field field) + { + //if (lastclick != -1) game.play(newEvent(lastclick, field)); + } + + public void event(int event) + { + lastclick = event; + } + + public void event(Event event) + { + game.play(event); + } +} diff --git a/Arctic_Nigthmare/src/arctic_nightmare/Person.java b/Arctic_Nigthmare/src/arctic_nightmare/Person.java index f9a8c6865495a02dbef2f337c528c68d1f405132..f84cb99b7b345d005b25e07fda8b01f0ae9092e5 100644 --- a/Arctic_Nigthmare/src/arctic_nightmare/Person.java +++ b/Arctic_Nigthmare/src/arctic_nightmare/Person.java @@ -15,8 +15,7 @@ public abstract class Person { private Game game; private Tent builtTent; - ///Person konstruktorba kell Game mindenképpen - + ///Person konstruktorba kell Game mindenképpen public Person(String name, Field f, Game g) { work = 0; this.name = name; @@ -79,6 +78,25 @@ public abstract class Person { if(this.field.emitItem()) work--; } + public void event(Event event) throws PlayerDiedException, PlayersWinException + { + switch (0) + { + case 0: + dig(); + break; + case 1: + shovel(); + break; + case 3: + step(new StableField()); + break; + case 4: + assembleFlare(); + break; + } + } + public void fall() throws PlayerDiedException { if(hasItem("DivingSuit")) {