@@ -30,19 +30,19 @@ public class Game extends Canvas implements Runnable {
3030 private static final long serialVersionUID = 1L ;
3131
3232 // Setting the size and name of the frame/canvas
33- public static final int WIDTH = 160 ;
34- public static final int HEIGHT = (WIDTH / 3 * 2 );
35- public static final int SCALE = 3 ;
36- public static final String NAME = "Game" ;
37- public static Game game ;
33+ private static final int WIDTH = 160 ;
34+ private static final int HEIGHT = (WIDTH / 3 * 2 );
35+ private static final int SCALE = 3 ;
36+ private static final String NAME = "Game" ;
37+ private static Game game ;
3838 private static int Jdata_Host ;
3939 private static String Jdata_UserName = "" ;
4040 private static String Jdata_IP = "127.0.0.1" ;
4141
4242 private JFrame frame ;
4343
44- public boolean running = false ;
45- public int tickCount = 0 ;
44+ private boolean running = false ;
45+ private int tickCount = 0 ;
4646
4747 private BufferedImage image = new BufferedImage (WIDTH , HEIGHT ,
4848 BufferedImage .TYPE_INT_RGB );
@@ -57,10 +57,10 @@ public class Game extends Canvas implements Runnable {
5757 private LevelHandler level ;
5858 private Player player ;
5959 private Music music = new Music ();
60- public Thread musicThread = new Thread (music );
61- public String nowPlaying = "Playing Music" ;
60+ private Thread musicThread = new Thread (music );
61+ private String nowPlaying = "Playing Music" ;
6262
63- public boolean notActive = true ;
63+ private boolean notActive = true ;
6464
6565 private GameClient socketClient ;
6666 private GameServer socketServer ;
@@ -82,7 +82,7 @@ public Game() {
8282 }
8383
8484 public void init () {
85- game = this ;
85+ setGame ( this ) ;
8686 int index = 0 ;
8787 for (int r = 0 ; r < 6 ; r ++) {
8888 for (int g = 0 ; g < 6 ; g ++) {
@@ -178,7 +178,7 @@ public void run() {
178178 }
179179
180180 public void tick () {
181- tickCount ++ ;
181+ setTickCount ( getTickCount () + 1 ) ;
182182 getLevel ().tick ();
183183 }
184184
@@ -189,8 +189,8 @@ public void render() {
189189 return ;
190190 }
191191
192- int xOffset = getPlayer ().x - (screen .width / 2 );
193- int yOffset = getPlayer ().y - (screen .height / 2 );
192+ int xOffset = getPlayer ().x - (screen .getWidth () / 2 );
193+ int yOffset = getPlayer ().y - (screen .getHeight () / 2 );
194194
195195 getLevel ().renderTiles (screen , xOffset , yOffset );
196196
@@ -203,9 +203,9 @@ public void render() {
203203
204204 getLevel ().renderEntities (screen );
205205
206- for (int y = 0 ; y < screen .height ; y ++) {
207- for (int x = 0 ; x < screen .width ; x ++) {
208- int colourCode = screen .pixels [x + y * screen .width ];
206+ for (int y = 0 ; y < screen .getHeight () ; y ++) {
207+ for (int x = 0 ; x < screen .getWidth () ; x ++) {
208+ int colourCode = screen .getPixels () [x + y * screen .getWidth () ];
209209 if (colourCode < 255 ) {
210210 pixels [x + y * WIDTH ] = colours [colourCode ];
211211 }
@@ -264,15 +264,15 @@ public static void main(String[] args) {
264264 Thread .sleep (750 );
265265 splash .setProgress (92 , "Aquring data: Multiplayer" );
266266 Thread .sleep (200 );
267- Jdata_Host = JOptionPane .showConfirmDialog (game , "Do you want to be the HOST?" );
267+ Jdata_Host = JOptionPane .showConfirmDialog (getGame () , "Do you want to be the HOST?" );
268268 if (Jdata_Host == 1 ){
269- Jdata_IP = JOptionPane .showInputDialog (game , "Enter the name \n leave blank for local" );
269+ Jdata_IP = JOptionPane .showInputDialog (getGame () , "Enter the name \n leave blank for local" );
270270 }
271271 Thread .sleep (200 );
272272 splash .setProgress (95 , "Aquring data: Username" );
273273 Thread .sleep (200 );
274274 splash .setProgress (96 , "Initalizing as Server:Host" );
275- Jdata_UserName = JOptionPane .showInputDialog (game , "Enter a name" );
275+ Jdata_UserName = JOptionPane .showInputDialog (getGame () , "Enter a name" );
276276 splash .setProgress (97 , "Connecting as" + Jdata_UserName );
277277 Thread .sleep (500 );
278278 splash .splashOff ();
@@ -331,4 +331,20 @@ public void setNowPlaying(String nowPlaying) {
331331 this .nowPlaying = nowPlaying ;
332332 }
333333
334+ public int getTickCount () {
335+ return tickCount ;
336+ }
337+
338+ public void setTickCount (int tickCount ) {
339+ this .tickCount = tickCount ;
340+ }
341+
342+ public static Game getGame () {
343+ return game ;
344+ }
345+
346+ public static void setGame (Game game ) {
347+ Game .game = game ;
348+ }
349+
334350}
0 commit comments