Difference between revisions of "Assessment 2008 Easy"

From Progzoo
Jump to: navigation, search
(Solitaire)
 
(19 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Assessment 2008}}
+
{{Assessment 2008}}
 
<shell>
 
<shell>
 
import java.awt.image.BufferedImage;
 
import java.awt.image.BufferedImage;
Line 25: Line 25:
 
}
 
}
 
</shell>
 
</shell>
==Noughts and Crosses==
 
<question className='Raster' imgOut='flag.png' copyFile='noughts_and_crosses.png' width='200' height='200'>
 
[[Image:noughts_and_crosses.png|frame|Naughts and Crosses]]
 
*The lines use rounded end-caps (see [[Drawing_Lines]])
 
*The lines have thickness 10
 
*Each line is 150
 
*The background is 200x200
 
<prog>
 
static void drawFlag(Graphics2D g){
 
}
 
</prog>
 
<answer>
 
static void drawFlag(Graphics2D g){
 
  BufferedImage img= new BufferedImage(200,200,
 
      BufferedImage.TYPE_INT_ARGB);
 
  try{
 
    img = (BufferedImage)ImageIO.read(new File("noughts_and_crosses.png"));
 
    g.drawImage(img,0,0,null);
 
  }catch(Exception e){}
 
}
 
</answer>
 
</question>
 
 
 
==Chess==
 
==Chess==
 
<question className='Raster' imgOut='flag.png' copyFile='chess.png' width='160' height='160'>
 
<question className='Raster' imgOut='flag.png' copyFile='chess.png' width='160' height='160'>
Line 54: Line 31:
 
<prog>
 
<prog>
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
 +
  g.setColor(Color.red);
 +
  g.fillRect(20,20,20,20);
 +
  g.setColor(Color.black);
 +
  g.fillRect(20,40,20,20);
 
}
 
}
 
</prog>
 
</prog>
<answer>
+
<answer><![CDATA[
static void drawFlag(Graphics2D g){
+
static void drawFlag(Graphics g){
   BufferedImage img= new BufferedImage(200,200,
+
   for (int i=0;i<8;i++)
      BufferedImage.TYPE_INT_ARGB);
+
     for (int j=0;j<8;j++){
  try{
+
      g.setColor(((i+j)%2==1)?Color.black:Color.red);
     img = (BufferedImage)ImageIO.read(new File("chess.png"));
+
      g.fillRect(20*i,20*j,20,20);
    g.drawImage(img,0,0,null);
+
    }
  }catch(Exception e){}
 
 
}
 
}
</answer>
+
]]></answer>
 
</question>
 
</question>
  
Line 75: Line 55:
 
*The separation is 8
 
*The separation is 8
 
*The background is 160x160
 
*The background is 160x160
 +
<prog>
 +
static void drawFlag(Graphics2D g){
 +
}
 +
</prog><answer><![CDATA[
 +
static void drawFlag(Graphics g){
 +
  g.setColor(new Color(220,179,92));
 +
  g.fillRect(8,8,18*8,18*8);
 +
  g.setColor(Color.black);
 +
  for (int i=0;i<19;i++){
 +
    g.drawLine(8+i*8,8,8+i*8,152);
 +
    g.drawLine(8,8+8*i,152,8+8*i);
 +
    }
 +
}
 +
]]></answer>
 +
</question>
 +
 +
==Noughts and Crosses==
 +
<question className='Raster' imgOut='flag.png' copyFile='noughts_and_crosses.png' width='200' height='200'>
 +
[[Image:noughts_and_crosses.png|frame|Noughts and Crosses]]
 +
*The lines use rounded end-caps (see [[Drawing_Lines]])
 +
*The lines have thickness 10
 +
*Each line is 150
 +
*The background is 200x200
 
<prog>
 
<prog>
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
Line 80: Line 83:
 
</prog>
 
</prog>
 
<answer>
 
<answer>
 +
static int l = 150;
 +
static int d = 25;
 +
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
   BufferedImage img= new BufferedImage(160,160,
+
   g.setStroke(
      BufferedImage.TYPE_INT_ARGB);
+
  new BasicStroke(10,
   try{
+
        BasicStroke.CAP_ROUND,
    img = (BufferedImage)ImageIO.read(new File("go.png"));
+
        BasicStroke.JOIN_MITER));
    g.drawImage(img,0,0,null);
+
   g.setColor(Color.black);
   }catch(Exception e){}
+
  g.drawLine(d+l/3,d,d+l/3,d+l);
 +
  g.drawLine(d+2*l/3,d,d+2*l/3,d+l);
 +
  g.drawLine(d,d+l/3,d+l,d+l/3);
 +
   g.drawLine(d,d+2*l/3,d+l,d+2*l/3);
 
}
 
}
 
</answer>
 
</answer>
Line 93: Line 102:
 
==Solitaire==
 
==Solitaire==
 
<question className='Raster' imgOut='flag.png' copyFile='solitaire.png' width='150' height='150'>
 
<question className='Raster' imgOut='flag.png' copyFile='solitaire.png' width='150' height='150'>
[[Image:solitaire.png|frame|Solitaire]]
+
[[Image:solitaire.png|frame|Solitaire]]  
 
*Each circle has radius 6
 
*Each circle has radius 6
 
*The circles are 16 apart
 
*The circles are 16 apart
Line 103: Line 112:
 
}
 
}
 
</prog>
 
</prog>
<answer>
+
<answer><![CDATA[
 +
static int sd = 150;
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
   BufferedImage img= new BufferedImage(150,150,
+
   int r=6;
      BufferedImage.TYPE_INT_ARGB);
+
  int d=16;
   try{  
+
  g.translate(sd/2,sd/2);
     img = (BufferedImage)ImageIO.read(new File("solitaire.png"));
+
  int br = 72;
    g.drawImage(img,0,0,null);
+
  g.setColor(new Color(39,155,102));
  }catch(Exception e){}
+
  g.fillOval(-br,-br,2*br,2*br);
 +
   g.setColor(Color.black);
 +
  g.drawOval(-br,-br,2*br,2*br);
 +
  g.translate(-3*d,-3*d);
 +
  for (int i=0;i<7;i++){
 +
     for (int j=0;j<7;j++){
 +
      if (Math.abs(i-3)<2||Math.abs(j-3)<2)
 +
        if (i==3&&j==3){
 +
          g.setColor(Color.white);
 +
          g.fillOval(i*d-r,j*d-r,2*r,2*r);
 +
          g.setColor(Color.black);
 +
          g.drawOval(i*d-r,j*d-r,2*r,2*r);
 +
        }else
 +
          g.fillOval(i*d-r,j*d-r,2*r,2*r);
 +
    }
 +
  }
 
}
 
}
</answer>
+
]]></answer>
 
</question>
 
</question>
  
 
==Connect 4==
 
==Connect 4==
<question className='Raster' imgOut='flag.png' copyFile='connect4.png' width='288' height='256'>
+
<question className='Raster' imgOut='flag.png' copyFile='connect4.png' width='148' height='128'>
 
[[Image:connect4.png|frame|Connect 4]]
 
[[Image:connect4.png|frame|Connect 4]]
 
*Each circle has radius 8
 
*Each circle has radius 8
 
*The circles are 20 apart
 
*The circles are 20 apart
 
*The background is 148x128
 
*The background is 148x128
*The color is 150,146,100
+
*The color is 160,146,100
 
<prog>
 
<prog>
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
 
}
 
}
 
</prog>
 
</prog>
<answer>
+
<answer><![CDATA[
static void drawFlag(Graphics2D g){  
+
static int sw = 148;static int sh = 128;
   BufferedImage img= new BufferedImage(288,256,
+
static void drawFlag(Graphics2D g){
      BufferedImage.TYPE_INT_ARGB);
+
   int r=8;
   try{
+
  int d=20;
     img = (BufferedImage)ImageIO.read(new File("connect4.png"));
+
  g.translate((sw-7*d)/2,(sh-6*d)/2);
    g.drawImage(img,0,0,null);
+
  g.setColor(new Color(160,146,100));
   }catch(Exception e){}
+
  g.fillRect(0,0,7*d,6*d);
 +
  g.setColor(Color.black);
 +
  g.drawRect(0,0,7*d,6*d);
 +
   for (int i=0;i<7;i++){
 +
     g.drawLine(i*d,0,i*d,6*d);
 +
    for (int j=0;j<6;j++){
 +
      g.setColor(Color.white);
 +
      g.fillOval(i*d-r+d/2,j*d-r+d/2,2*r,2*r);
 +
      g.setColor(Color.black);
 +
      g.drawOval(i*d-r+d/2,j*d-r+d/2,2*r,2*r);
 +
    }
 +
   }
 
}
 
}
</answer>
+
]]></answer>
 
</question>
 
</question>

Latest revision as of 19:32, 21 March 2009

Chess

Simple Chess Board
  • The background is 160x160


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

Go

Go
  • The board color is 220,179,92
  • There are 19 lines across and 19 down
  • The separation is 8
  • The background is 160x160


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

Noughts and Crosses

Noughts and Crosses
  • The lines use rounded end-caps (see Drawing_Lines)
  • The lines have thickness 10
  • Each line is 150
  • The background is 200x200


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

Solitaire

Solitaire
  • Each circle has radius 6
  • The circles are 16 apart
  • The background is 150x150
  • The big disk has radius 72
  • The green in 39,155,102


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

Connect 4

Connect 4
  • Each circle has radius 8
  • The circles are 20 apart
  • The background is 148x128
  • The color is 160,146,100


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