intro/MazeGraphicsExample

From ggc

Jump to: navigation, search

01 package intro;
02 //start auto-imports
03 import java.io.*;
04 import java.util.*;
05 import wiki.*;
06 //end auto-imports
07 
08 import fang.*;
09 import java.awt.*;
10 import java.awt.geom.*;
11 
12 /**
13  * All about my game.
14  @author My Name Here
15  */
16 public class MazeGraphicsExample extends Game
17 {
18   private Sprite[][] maze;
19 
20   /**sets up the game*/
21   public void setup()
22   {
23     char[][] textMaze=getMazeText("Maze3.txt");
24     maze=new Sprite[textMaze.length][textMaze[0].length];
25     for(int r=0; r<maze.length; r++)
26     {
27       for(int c=0; c<maze[r].length; c++)
28       {
29         if(textMaze[r][c]=='.')
30           maze[r][c]=new OvalSprite(0.010.01);
31         else
32           maze[r][c]=new RectangleSprite(0.10.1);
33         maze[r][c].setLocation(c*0.1+0.1, r*0.1+0.1);
34         addSprite(maze[r][c]);
35       }
36     }
37   }
38 
39   private char[][] getMazeText(String filename)
40   {
41     Scanner scanner=null;
42     try
43     {
44       scanner=new Scanner(Wiki.getInputStream(filename));
45     }
46     catch(IOException e)
47     {}
48     int rows=scanner.nextInt();
49     int cols=scanner.nextInt();
50     char[][] maze=new char[rows][cols];
51     for(int r=0; r<rows; r++)
52     {
53       for(int c=0; c<cols; c++)
54       {
55         maze[r][c]=scanner.next().charAt(0);
56       }
57     }
58     return maze;
59   }
60 
61   /**handle input and game events*/
62   public void advance()
63   {}
64 }


Download/View intro/MazeGraphicsExample.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter