The first season of the game

Source: Internet
Author: User

Rungmae class

1 package com.lovo;2 3 public class GameRun {4     public static void main(String[] args) {5         new MyFrame().setVisible(true);6     }7 }

 

Myframe class

1 package COM. lovo; 2 3 Import Java. AWT. color; 4 Import Java. AWT. graphics; 5 import Java. AWT. image; 6 Import Java. AWT. event. actionevent; 7 Import Java. AWT. event. actionlistener; 8 Import Java. AWT. image. bufferedimage; 9 10 Import javax. swing. jframe; 11 import javax. swing. timer; 12 13 public class myframe extends jframe {14 Private Static final long serialversionuid =-3544738451252364271l; 15 private board Board = new Board (); 16 // create an image in the memory. Figure 17 private image offimage = new bufferedimage (800,800, bufferedimage. type_int_rgb); 18 public myframe () {19 this. settitle ("wuziqi"); 20 this. setsize (800,800); 21 this. setresizable (false); 22 This. getcontentpane (). setbackground (new color (197,194,129); // set the window Background 23 This. setdefaclocloseoperation (exit_on_close); 24 this. setlocationrelativeto (null); // window center 25 timer = new timer (100, new actionlistener () {26 @ override27 public void actionreceivmed (actionevent e) {28 board. makeamove (); 29 repaint (); // notify the system to call paint () 30} 31} again; 32 timer. start (); 33} 34 35 @ override36 public void paint (Graphics g) {// The operating system calls this method to plot 37 graphics newg = offimage. getgraphics (); // get the brush 38 super for the image in the memory. paint (newg); // you can set the background. In the memory, draw the 39 board window. draw (newg); // draw a 40g checker in the memory. drawimage (offimage, 0, 0,800,800, null); // place the board in the memory on the screen 41} 42}

Board Type

1 package COM. lovo; 2 3 Import Java. AWT. basicstroke; 4 Import Java. AWT. color; 5 import Java. AWT. graphics; 6 Import Java. AWT. graphics2d; 7 Import Java. AWT. stroke; 8 9 public class board {10 private int [] [] B = new int [15] [15]; 11 private Boolean blackturn = true; 12/** 13 * draw a chessboard 14 * @ Param g15 */16 public void draw (Graphics g) {17G. setcolor (color. black); // after the double buffer is added, the default value is white, and the value is set to Black 18 graphics2d g2d = (graphic S2d) g; // you can use graphics2d to adjust the thickness of 19 stroke oldsstroke = g2d. getstroke (); // Save the scene 20 g2d. setstroke (New basicstroke (3); // you can specify a paint brush width of 21 GB. drawrect (50, 50,700,700); // rectangular frame 22 g2d. setstroke (oldsstroke); // reply to site 23 for (INT I = 0; I <13; I ++) {24g. drawline (50,100 + I * 50,750,100 + I * 50); 25g. drawline (100 + I * 50, 50,100 + I * 50,750); 26} 27 // drawing day and 28G. filloval (390,390, 20, 20); // solid elliptic 29G. filloval (195, 1 95, 10, 10); 30g. filloval (595,195, 10, 10); 31G. filloval (595,595, 10, 10); 32G. filloval (195,595, 10, 10); 33 for (INT I = 0; I <B. length; I ++) {// The loop of the row, which controls the vertical coordinate 34 for (Int J = 0; j <B [I]. length; j ++) {// column loop, controls the abscissa 35 if (B [I] [J]! = 0) {36g. setcolor (B [I] [J] = 1? Color. black: color. white); 37g. filloval (25 + 50 * j, 25 + 50 * I, 50, 50); 38} 39} 40} 41} 42 Public void makeamove () {43 int ROW = (INT) (math. random () * 15); 44 int Col = (INT) (math. random () * 15); 45 if (B [row] [col] = 0) {46 B [row] [col] = blackturn? 1: 2; // 0 indicates no go games, 1 indicates black games, 2 indicates white games 47 blackturn =! Blackturn; // exchange moves 48} 49 50} 51}

 

The first season of the game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.