Skip to content
Snippets Groups Projects
Commit eebdafd3 authored by CsellarAndras's avatar CsellarAndras
Browse files

Added primitive graphics for planning

parent 1a488c16
No related branches found
No related tags found
No related merge requests found
/*
* 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
{}
}
}
......@@ -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) {
......
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() {
......@@ -40,12 +46,11 @@ public class Game{
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){
......
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);
}
}
......@@ -16,7 +16,6 @@ public abstract class Person {
private Tent builtTent;
///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")) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment