Difference between revisions of "Assessment 2008 Hard"

From Progzoo
Jump to: navigation, search
(Cards)
(Monopoly)
 
(10 intermediate revisions by the same user not shown)
Line 36: Line 36:
 
}
 
}
 
</prog>
 
</prog>
<answer>
+
<answer><![CDATA[
 +
//This answer is way too complicated :( mant students came up with
 +
//better solutions.
 +
static int s=20;
 +
static int off=12;
 +
static int r = 6;
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
   BufferedImage img= new BufferedImage(184,104,
+
   g.setColor(new Color(64,64,255));
      BufferedImage.TYPE_INT_ARGB);
+
  g.fillRect(off,off,8*s,4*s);
   try{
+
   g.setColor(Color.black);
     img = (BufferedImage)ImageIO.read(new File("fanorona.png"));
+
  g.translate(off,off);
     g.drawImage(img,0,0,null);
+
  for (int i=-4;i<8;i++)
   }catch(Exception e){}
+
     g.drawLine(Math.max(0,i*s),Math.max(0,-i*s),
 +
              Math.min(i*s+4*s,8*s),Math.min(4*s,(8-i)*s));
 +
  for (int i=0;i<12;i++)
 +
    g.drawLine(Math.min(i*s,8*s),
 +
              Math.max(0,(i-8)*s),
 +
  //Math.max(i*s,0),0,//Math.max(0,i*s),
 +
              Math.max(i*s-4*s,0),Math.min(i*s,4*s));
 +
  g.setColor(Color.white);
 +
  g.setColor(Color.black);
 +
  for (int i=0;i<9;i++){
 +
     g.drawLine(i*s,0,i*s,4*s);
 +
  }
 +
  for (int i=0;i<5;i++){
 +
    g.drawLine(0,i*s,8*s,i*s);
 +
   }
 +
  g.setRenderingHint(
 +
    RenderingHints.KEY_ANTIALIASING,
 +
    RenderingHints.VALUE_ANTIALIAS_ON);
 +
  for (int i=0;i<9;i++)
 +
    for (int j=0;j<5;j++){
 +
      if (j<2||(j==2 && (i==0||i==2||i==5||i==7))){
 +
        g.setColor(Color.black);
 +
        g.fillOval(-r+i*s,-r+j*s,2*r,2*r);
 +
      }
 +
      if (j>2||(j==2 && (i==1||i==3||i==6||i==8))) {
 +
        g.setColor(Color.white);
 +
        g.fillOval(-r+i*s,-r+j*s,2*r,2*r);
 +
        g.setColor(Color.black);
 +
        g.drawOval(-r+i*s,-r+j*s,2*r,2*r);
 +
      }
 +
    }
 
}
 
}
</answer>
+
]]></answer>
 
</question>
 
</question>
  
Line 57: Line 92:
 
}
 
}
 
</prog>
 
</prog>
<answer>
+
<answer><![CDATA[
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
   BufferedImage img= new BufferedImage(241,241,
+
   int d=24;
      BufferedImage.TYPE_INT_ARGB);
+
  g.setColor(Color.black);
   try{
+
   for (int i=0;i<10;i++){
     img = (BufferedImage)ImageIO.read(new File("snakes_and_ladders.png"));
+
     for (int j=0;j<10;j++){
    g.drawImage(img,0,0,null);
+
      g.drawRect(i*d,j*d,d,d);
   }catch(Exception e){}
+
      int k = 1+10*(9-j)+((j%2==1)?i:(9-i));
}  
+
      g.drawString(""+k,i*d,j*d+d);
</answer>
+
    }
 +
   }
 +
}
 +
]]></answer>
 
</question>
 
</question>
  
Line 78: Line 116:
 
}
 
}
 
</prog>
 
</prog>
<answer>
+
<answer><![CDATA[
 +
static int d = 16;
 +
static void quarter(Graphics2D g,Color c){
 +
  //This list of coordinates is describe square with a
 +
  //square cut out of it. Start in the middle top, go
 +
  //around the outside of the outer square then round
 +
  //the inner square
 +
  int x[] = new int[] {1,0,0,2,2,1,0,1,2};
 +
  int y[] = new int[] {0,0,2,2,0,0,1,2,1};
 +
  Polygon p = new Polygon();
 +
  for (int i=0;i<x.length;i++)
 +
    p.addPoint(3*d*x[i],3*d*y[i]);
 +
  g.setColor(c);
 +
  g.fillPolygon(p);
 +
  g.fillRect(d,6*d,d,2*d);
 +
  g.fillRect(2*d,7*d,4*d,d);
 +
  Polygon t =new Polygon(new int[]{6*d,6*d,15*d/2},
 +
                        new int[]{6*d,9*d,15*d/2},3);
 +
  g.fillPolygon(t);
 +
  g.setColor(Color.black);
 +
  g.drawPolygon(p);
 +
  g.drawPolygon(t);
 +
  for (int i=0;i<7;i++)
 +
    g.drawLine(i*d,6*d,i*d,9*d);
 +
  for (int i=0;i<4;i++)
 +
    g.drawLine(0,6*d+d*i,6*d,6*d+d*i);
 +
}
 +
 
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
   BufferedImage img= new BufferedImage(300,300,
+
   g.translate(8,8);
      BufferedImage.TYPE_INT_ARGB);  
+
  g.setColor(new Color(228,228,228));
   try{  
+
  g.fillRect(0,0,15*d,15*d);
    img = (BufferedImage)ImageIO.read(new File("ludo.png"));
+
   for (Color c:new Color[]{Color.green,Color.yellow,
     g.drawImage(img,0,0,null);  
+
                          Color.blue, Color.red}){
  }catch(Exception e){}
+
    quarter(g,c);
 +
     g.translate(0,15*d);
 +
    g.rotate(-Math.PI/2);
 +
  }
 
}
 
}
</answer>
+
]]></answer>
 
</question>
 
</question>
  
Line 98: Line 166:
 
*Each suit image (e.g. clubs.png) is 16x16
 
*Each suit image (e.g. clubs.png) is 16x16
 
*The corner image is 13x20 from the centre of the card
 
*The corner image is 13x20 from the centre of the card
 +
*If you want to work outside progzoo you can get the images: http://progzoo.net/hearts.png http://progzoo.net/clubs.png http://progzoo.net/diamonds.png http://progzoo.net/spades.png
 
[[Image:cards.png|frame|Deck of Cards]]
 
[[Image:cards.png|frame|Deck of Cards]]
<img src='/hearts.png'/>
 
 
<prog>
 
<prog>
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
Line 116: Line 184:
 
}
 
}
 
</prog>
 
</prog>
<answer>
+
<answer><![CDATA[
 +
static void doubleTB(Graphics2D g,int x,int y,BufferedImage img){
 +
  g.translate(x,y);
 +
  g.drawImage(img,-8,-8,null);
 +
  g.translate(-x-x,-y-y);
 +
  g.rotate(Math.PI);
 +
  g.drawImage(img,-8,-8,null);
 +
  g.rotate(-Math.PI);
 +
  g.translate(x,y);
 +
}
 +
 
 +
static void fillOff(Graphics2D g,int x,int y,BufferedImage img){
 +
  g.translate(x,y);
 +
  g.drawImage(img,-8,-8,null);
 +
  g.translate(-x,-y);
 +
}
 +
 
 +
static void pips(Graphics2D g,int x,int y,int n,BufferedImage img){
 +
  int w=4; int h=6;
 +
  int tl = 20;int rl=13;
 +
  g.translate(x,y);
 +
  if (n==1||n==3||n==5||n==9)
 +
    g.drawImage(img,-8,-8,null);
 +
  if (n==2||n==3)
 +
    doubleTB(g,0,tl,img);
 +
  if (n>3){
 +
    doubleTB(g,rl,tl,img);
 +
    doubleTB(g,-rl,tl,img);
 +
  }
 +
  if (n==6||n==7||n==8){
 +
    fillOff(g,rl,0,img);
 +
    fillOff(g,-rl,0,img);
 +
  }
 +
  if (n==7)
 +
    fillOff(g,0,-tl/2,img);
 +
  if (n==8)
 +
    doubleTB(g,0,tl/2,img);
 +
  if (n==9||n==10){
 +
    doubleTB(g,-rl,tl/3,img);
 +
    doubleTB(g,rl,tl/3,img);
 +
  }
 +
  if (n==10) doubleTB(g,0,2*tl/3,img);
 +
  g.translate(-x,-y);
 +
}
 +
 
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
   BufferedImage img= new BufferedImage(448,270,
+
  int p = 4;
       BufferedImage.TYPE_INT_ARGB);  
+
  int r = 8;
   try{  
+
  int w = 40;
     img = (BufferedImage)ImageIO.read(new File("cards.png"));
+
  int h = 60;
     g.drawImage(img,0,0,null);
+
  g.setRenderingHint(
  }catch(Exception e){ }
+
  RenderingHints.KEY_ANTIALIASING,
 +
  RenderingHints.VALUE_ANTIALIAS_ON);
 +
   BufferedImage img = new BufferedImage(16,16,
 +
       BufferedImage.TYPE_INT_ARGB);
 +
   String [] suits = "diamonds.png clubs.png hearts.png spades.png".split(" ");
 +
  for (int j=0;j<4;j++){
 +
     try {
 +
      img = (BufferedImage)ImageIO.read(new File(suits[j]));
 +
     }catch (Exception e){}
 +
    for (int i=0;i<10;i++)
 +
    {
 +
      g.setColor(Color.white);
 +
      g.fillRoundRect((p+w)*i+p,(p+h)*j+p,w,h,r,r);
 +
      g.setColor(Color.black);
 +
      g.drawRoundRect((p+w)*i+p,(p+h)*j+p,w,h,r,r);
 +
      g.setColor((j%2==0)?Color.red:Color.black);
 +
      pips(g,(p+w)*i+p+w/2,(p+h)*j+p+h/2,i+1,img);
 +
    }
 +
  }
 
}
 
}
</answer>
+
]]></answer>
 
</question>
 
</question>
  
Line 154: Line 284:
 
}
 
}
 
</prog>
 
</prog>
<answer>
+
<answer><![CDATA[
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
   BufferedImage img= new BufferedImage(1040,1040,
+
   FontMetrics fm = g.getFontMetrics();
      BufferedImage.TYPE_INT_ARGB);
+
  String [] [] monopoly =
   try{
+
    new String [] [] {
     img = (BufferedImage)ImageIO.read(new File("monopoly.png"));
+
      new String [] {"Old Kent\nRoad#7e3517","Community\nChest","Whitechapel#7e3517",
    g.drawImage(img,0,0,null);
+
                    "Income Tax","King's Cross\nStation","The Angel\nIslington#6699ff",
  }catch(Exception e){}
+
                    "Chance","Euston Road#6699ff","Pentonville\nRoad#6699ff"},
 +
      new String [] {"Pall Mall#cc44cc","Electric\nCompany","Whitehall#cc44cc",
 +
                    "Northum'nd\nAvenue#cc44cc","Marlebone\nStation","Bow\nStreet#ff9900",
 +
                    "Community\nChest","Marlborough\nStreet#ff9900","Vine\nStreet#ff9900"},
 +
      new String [] {"Strand#ee0000","Chance","Fleet\nStreet#ee0000","Trafalgar\nSquare#ee0000",
 +
                    "Fenchurch\nStreet\nStation","Leichester\nSquare#ffff00",
 +
                      "Coventry\nStreet#ffff00","Water Works","Piccadilly#ffff00"},
 +
      new String [] {"Regent\nStreet#008000","Oxford\nStreet#008000","Community\nChest",
 +
                    "Bond\nStreet#008000","Liverpool\nStreet\nStation","Chance",
 +
                    "Park\nLane#333366","Super Tax","Mayfair#333366"}
 +
    };
 +
  int w = 85;
 +
  int h = (1000-w*9)/2;
 +
  g.setRenderingHint(
 +
    RenderingHints.KEY_ANTIALIASING,
 +
    RenderingHints.VALUE_ANTIALIAS_ON);
 +
   g.setColor(Color.black);
 +
  g.translate(h+8*w,h+9*w);
 +
  for (String [] row : monopoly){
 +
     for (String property : row){
 +
      String [] s = property.split("#");
 +
      g.drawRect(0,0,w,h);
 +
      String [] lines = s[0].split("\n");
 +
      g.translate(w/2,h/5);
 +
      for (String l : lines){
 +
        g.translate(0,fm.getHeight());
 +
        g.drawString(l,(0-fm.stringWidth(l))/2,0);
 +
      }
 +
      g.translate(0,-1*fm.getHeight()*lines.length);
 +
      g.translate(-w/2,-h/5);
 +
      if (s.length>1){
 +
        g.setColor(new Color(Integer.parseInt(s[1],16)));
 +
        g.fillRect(0,0,w,h/5);
 +
        g.setColor(Color.black);
 +
        g.drawRect(0,0,w,h/5);
 +
      }
 +
      g.translate(-w,0);
 +
    }
 +
    g.translate(w,0);
 +
    g.rotate(Math.PI/2.0);
 +
    g.translate(-w,0);
 +
  }
 
}
 
}
</answer>
+
]]></answer>
 
[[Image:monopoly.png]]
 
[[Image:monopoly.png]]
 
</question>
 
</question>

Latest revision as of 01:28, 10 November 2008

Fanorona

Fanorona
  • The separation is 20
  • The disks have radius 6
  • The background is 184x104
  • The blue is 64,64,255


[Font] [Default] [Show] [Resize] [History] [Profile]

Snakes and Ladders

Snakes and Ladders
  • The squares are 24
  • The background is 241x241


[Font] [Default] [Show] [Resize] [History] [Profile]

Ludo

Ludo
  • The background is 256x256
  • The gray is 228, 228, 228


[Font] [Default] [Show] [Resize] [History] [Profile]

Cards

Deck of Cards


[Font] [Default] [Show] [Resize] [History] [Profile]

Monopoly

This is a large image and takes too much memory on the the progzoo system. Please use Dr Java or similar.

  • The width of each property is 85
  • The background is 1040x1040
  • You should use strings in the array


Monopoly.png

[Font] [Default] [Show] [Resize] [History] [Profile]