-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyWorld.java
93 lines (87 loc) · 3.74 KB
/
MyWorld.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
/**
* This is the class that sets everything up.
* It creates the world and gives an introduction.
* Throughout the game, it sets the variable gotPicked to false at the start of every round,
* signifying that nothing has yet been picked up this round.
* It also times the game and closes out after four minutes ("days").
*
* @author Isabel Rosa
*/
public class MyWorld extends World implements Data{
private long daysLeft = 4;
private int startInt = 0;
private ChangeableData cd;
private Actor start;
private Player p;
private Player temp;
private Key k;
private long startTime;
private GetKeyDown gkd;
/**
* Constructor for objects of class MyWorld.
* Sets world size, brings certain objects to front, and sets order of being called.
* Creates access to database, makes the start room, adds the player, creates access to which key is down, and prepares to start timer.
*/
public MyWorld(){
super(500, 400, 1);
setPaintOrder(GreenfootImage.class, Black.class, Person.class, BagThings.class, Desk.class, Door.class, Pamphlet.class, Room.class);
setActOrder(World.class, Key.class, Flashlight.class, Magnifier.class, Art.class, PlaceHolder.class);
cd=new ChangeableData();
start=new Room(0, this, cd);
p=new Player(start, this, cd, "you");
gkd=new GetKeyDown(this);
//this part is to get the console working
JFrame frame = new JFrame();
frame.add( new JLabel("Messages" ), BorderLayout.NORTH );
JTextArea ta = new JTextArea();
TextAreaOutputStream taos = new TextAreaOutputStream( ta, 60 );
PrintStream ps = new PrintStream( taos );
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
System.setOut( ps );
System.setErr( ps );
frame.add( new JScrollPane( ta ) );
frame.pack();
frame.setVisible( true );
frame.setSize(800,600);
startTime=-1;
}
/**
* Displays the starting instructions.
*/
private void startMessage(){
if(startInt==0){
JOptionPane.showMessageDialog(null, "You are the well-renowned art dealer, I.\nPress the arrow keys to move yourself, the person in the middle of the room.\nRun over a person to hear what they have to say.\nYou have four days to pay off your mortgage debt of $10,000,100, or else you lose your house.\nI haven't taken my econ class yet so I have a poor grasp of how mortgages work and also how to spell mortgage but I saw a movie with a plot along these lines so I turned it into a game.\nGood luck!");
startInt=1;
}
}
/**
* Act - do whatever the Room wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
* Displays start message when the game starts and sets gotPicked to false to signify nothing has yet been picked up this round.
* Times the game and shuts down if player doesn't finish in time.
*/
public void act(){
startMessage();
BagThings.gotPicked=false;
if(startTime==-1)
startTime=System.currentTimeMillis();
else if((System.currentTimeMillis()-startTime)%120000<15){
daysLeft--;
if(daysLeft>0)
System.out.println("A day has passed. You have " + daysLeft + " days left.");
else{
System.out.println("You ran out of days. Game over.");
System.exit(0);
}
}
}
}