-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.java
More file actions
143 lines (121 loc) · 3.83 KB
/
World.java
File metadata and controls
143 lines (121 loc) · 3.83 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* The program allows a user to draw and move
* figures which are oval, happy face and rectangle.
* To draw a circle, type "c", then drag mouse to create oval
* To draw a rectangle, type "r", then drag mouse
* To draw a happy face, type "h", then drag mouse
* To move an object, type "s", then press mouse key on object and drag.
* To delete an object, click on the object, then type "d".
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;
import java.io.*;
import java.util.Scanner;
public class World extends JPanel
implements MouseListener, MouseMotionListener, KeyListener
{
static String levelName;
static Level level;
int globalX=0, globalY=0;
public static void main()//Jacob Waters, David Wisneski
{
System.out.println("What level do you want to play?");
Scanner scan=new Scanner(System.in);
levelName=scan.nextLine();
level=new Level(new File(levelName+".txt"));
JFrame window = new JFrame();
window.setSize(1080,720);
window.setTitle("World");
World panel = new World(); // window content pane to hold the draw and tool panels
window.add(panel);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}
public World( ){//David Wisneski
addMouseListener(this);
addMouseMotionListener(this);
addKeyListener(this);
}
public void paintComponent(Graphics g){//Jacob Waters, David Wisneski
g.clearRect(0, 0, getWidth(), getHeight());
level.refreshBounds(globalX,getWidth());
level.globalDraw(g,globalX,globalY);
}
public void mousePressed(MouseEvent e){//David Wisneski
requestFocus();
}
public void mouseReleased(MouseEvent e){//David Wisneski
}
public void mouseClicked(MouseEvent e){//David Wisneski
}
public void mouseEntered(MouseEvent e){//David Wisneski
}
public void mouseExited(MouseEvent e){//David Wisneski
}
public void mouseDragged(MouseEvent e){//David Wisneski
}
public void mouseMoved(MouseEvent e){//David Wisneski
}
public void keyPressed(KeyEvent e){//David Wisneski
int key = e.getKeyCode();
}
public void keyReleased(KeyEvent e){//David Wisneski
}
public void keyTyped(KeyEvent e){//David Wisneski
}
public void save(String levelName)//Jacob Waters
{
BufferedWriter output = null;
try
{
output = new BufferedWriter(new FileWriter(levelName+".txt",false));
output.append("");
output.newLine();
}
catch ( IOException e)
{
System.out.println(e);
}
try
{
output.close();
}
catch ( IOException e)
{
System.out.println(e);
}
}
public void save(Level level)//Jacob Waters
{
// Scanner scan=new Scanner(System.in);
// System.out.println("What is the Level Name?");
// String levelName=scan.nextLine();
BufferedWriter output = null;
try
{
output = new BufferedWriter(new FileWriter("level1.txt",false));
for(int i=0;i<level.length();i++)
{
for(String a:level.get(i).save())
{
output.append(a);
output.newLine();
}
}
}
catch ( IOException e)
{
System.out.println(e);
}
try
{
output.close();
}
catch ( IOException e)
{
System.out.println(e);
}
}
}