Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Game Modeling• Requirement: A game has two teams. Each  team has soldiers that move in the game area  and fire at soldiers...
ObjectsThe objects in the system are• Team• Soldiers• Watchtower• Grid
TeamA team comprises of soldiers and watchtowers.public class Team {        private Soldier[] live_soldiers;        privat...
SoldierA soldier is modeled as an independent threadthat moves as per the directions of player. Itsupports operations for ...
Soldierpublic class Soldier implements Runnable {    boolean is_shot;    int x; // current x coordinate    int y; // curre...
Soldierpublic void fire(int x, int y) {     }     public void left(int grids) {             int target_x = x - grids;     ...
Soldierpublic void down(int pixels) {//similar to left    }    public void move(int x, int y) {            this.x = x;    ...
Watch Tower    Watch tower watches over a square area surrounding it.    Any soldier walking into the square area is shot ...
Watch Tower    When watchtower is notified by Grid of an enemy soldier, it calls notfy In, When soldier walks out,    it c...
Watch Towerpublic void fire(int x, int y) {   }   public void registerWatchtowerWithGrids() {       Grid[] gA = Grids.getG...
GridGame area is divided into square grids.Grids observe if a soldier is over its square and notify monitoring   watchtowe...
Gridpublic void registerWatchTower(WatchTower w) {              l.add(w);     }    public void NotifyIn() {            for...
GridsAssuming area to rectangular, let x be numberof grids length wise and y be number of gridsbreadth wise.Another assump...
Gridspublic class Grids {    static Grid[][] gA ;    static {             int x,y;             x=y=100;             gA = n...
Gridspublic static Grid getGrid(int i, int y) {      //implementation  }  public static Grid[] getGrid(int x, int y, int s...
Upcoming SlideShare
Loading in …5
×

Game modeling

509 views

Published on

Designing software games involves graphics, multi-threaded programming, memory intensive operations.

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Game modeling

  1. 1. Game Modeling• Requirement: A game has two teams. Each team has soldiers that move in the game area and fire at soldiers of opposite team. Each team can install watch towers that watches over a given area. If enemy solider steps in the area that is watched, the soldier at watch tower fires at them. Create a software model of this game.
  2. 2. ObjectsThe objects in the system are• Team• Soldiers• Watchtower• Grid
  3. 3. TeamA team comprises of soldiers and watchtowers.public class Team { private Soldier[] live_soldiers; private WatchTower[] wt; private String name; public Team(Soldier[] s, WatchTower[] wt) { //assign }}
  4. 4. SoldierA soldier is modeled as an independent threadthat moves as per the directions of player. Itsupports operations for moving left, right up anddown the game area. Game area is modeled ascomposed of several square grids. A soldier canmove from one grid to another grid. It is assumedthat each grid is of size 10 pixels. Once a solider ison a grid, the grid object is notified of the same.Grids (plural) is a helper class for accessing thegrid(singular) object.
  5. 5. Soldierpublic class Soldier implements Runnable { boolean is_shot; int x; // current x coordinate int y; // current Team t; public Soldier(Team t) { this.t=t; } public void run() { while (!is_shot) { // move along grids in random/predefined fashion } }//other methods on next slide}
  6. 6. Soldierpublic void fire(int x, int y) { } public void left(int grids) { int target_x = x - grids; for (int i = x - 1; i >= target_x; i--) { move(i, y); Grid g = Grids.getGrid(i, y); g.notify(); } } public void right(int pixels) {// similar to left } public void up(int pixels) {// similar to left }
  7. 7. Soldierpublic void down(int pixels) {//similar to left } public void move(int x, int y) { this.x = x; this.y = y; Graphics.paintSoldier(x * 10, y * 10, 10); // assuming paint soldier // takes bottom left screen pixel coordinate and number of screen pixels // side. Graphic library paints the soldier in that square area by suitably //coloring the pixels. } public void gotHit() { is_shot = true; }
  8. 8. Watch Tower Watch tower watches over a square area surrounding it. Any soldier walking into the square area is shot at by soldier at watchtower.public class WatchTower { int x; int y; // number of grids for this square area where watch tower watches. int side; boolean in; Team t; public WatchTower(int x, int y, int side, Team t) { //assign } // other methods in next slide.}
  9. 9. Watch Tower When watchtower is notified by Grid of an enemy soldier, it calls notfy In, When soldier walks out, it calls notify out. When notify in is called, watchtower creates its on thread for firing so that calling thread is not blocked.public void notifyIn(final int x, final int y) { in = true; Thread t = new Thread() { public void run() { while (in) { fire(x, y); } } }; } public void notifyOut(int x, int y) { in = false; }
  10. 10. Watch Towerpublic void fire(int x, int y) { } public void registerWatchtowerWithGrids() { Grid[] gA = Grids.getGrid(x, y, side); for (int i = 0; i < gA.length; i++) { Grid g = gA[i]; g.registerWatchTower(this); } }
  11. 11. GridGame area is divided into square grids.Grids observe if a soldier is over its square and notify monitoring watchtowers. public class Grid { // coordinate for pixel int x; int y; List<WatchTower> l = new ArrayList<WatchTower>(); public void grid(int x, int y) { }
  12. 12. Gridpublic void registerWatchTower(WatchTower w) { l.add(w); } public void NotifyIn() { for (int i = 0; i < l.size(); i++) { WatchTower w = l.get(i); w.notifyIn(x, y); } } public void NotifyOut() { for (int i = 0; i < l.size(); i++) { WatchTower w = l.get(i); w.notifyOut(x, y); } }
  13. 13. GridsAssuming area to rectangular, let x be numberof grids length wise and y be number of gridsbreadth wise.Another assumption is that each grid side has10 screen pixels. So application grid (1,1) willhave (10,10) as pixel coordinate at its bottom-left.
  14. 14. Gridspublic class Grids { static Grid[][] gA ; static { int x,y; x=y=100; gA = new Grid[x][y]; for(int i=0;i<x;i++) { for(int j=0;j<y;j++){ Grid g = new Grid(i,j); gA[i][j]=g; } } }
  15. 15. Gridspublic static Grid getGrid(int i, int y) { //implementation } public static Grid[] getGrid(int x, int y, int side) { //implementation }

×