当前位置: 首页 > news >正文

一个空间放两个网站网络推广项目

一个空间放两个网站,网络推广项目,购物网站建设 属于信息系统管理与设计么,四川省建设厅网站打不开目录 游戏规则 小方块类:Cell 七种图形类:I、J、L、O、S、T、Z J L O S T Z 俄罗斯方块游戏主类:Tetris 效果展示 游戏规则 由小方块组成的不同形状的板块陆续从屏幕上方落下来,玩家通过调整板块的位置和方向,使它…

目录

游戏规则

小方块类:Cell

 七种图形类:I、J、L、O、S、T、Z

 J

 L

 O

 S

 T

Z

 俄罗斯方块游戏主类:Tetris

效果展示


游戏规则

由小方块组成的不同形状的板块陆续从屏幕上方落下来,玩家通过调整板块的位置和方向,使它们在屏幕底部拼出完整的一条或几条。这些完整的横条会随即消失,给新落下来的板块腾出空间,与此同时,玩家得到分数奖励。没有被消除掉的方块不断堆积起来,一旦堆到屏幕顶端,玩家便告输,游戏结束。

整体代码分为三个模块:方格模块,七种图形模块,俄罗斯方块主模块。
 

小方块类:Cell

package com.zhao.demo.block;import java.awt.image.BufferedImage;
import java.util.Objects;/*** @author xiaoZhao* @date 2022/5/7* @describe*  小方块类*   方法: 左移、右移、下落*/
public class Cell {// 行private int row;// 列private int col;private BufferedImage image;public Cell() {}public Cell(int row, int col, BufferedImage image) {this.row = row;this.col = col;this.image = image;}public int getRow() {return row;}public void setRow(int row) {this.row = row;}public int getCol() {return col;}public void setCol(int col) {this.col = col;}public BufferedImage getImage() {return image;}public void setImage(BufferedImage image) {this.image = image;}@Overridepublic String toString() {return "Cell{" +"row=" + row +", col=" + col +", image=" + image +'}';}@Overridepublic boolean equals(Object o) {if (this == o) {return true;}if (!(o instanceof Cell)) {return false;}Cell cell = (Cell) o;return getRow() == cell.getRow() &&getCol() == cell.getCol() &&Objects.equals(getImage(), cell.getImage());}@Overridepublic int hashCode() {return Objects.hash(getRow(), getCol(), getImage());}//左移动一格public void left(){col--;}//右移动一格public void right(){col++;}//下移动一格public void down(){row++;}
}

 七种图形类:I、J、L、O、S、T、Z

I

package com.zhao.demo.shape;import com.zhao.demo.App.Tetris;
import com.zhao.demo.block.Cell;
import com.zhao.demo.block.Tetromino;/*** @author xiaoZhao* @date 2022/5/11* @describe*/
public class I extends Tetromino {public I() {cells[0] = new Cell(0,4, Tetris.I);cells[1] = new Cell(0,3, Tetris.I);cells[2] = new Cell(0,5, Tetris.I);cells[3] = new Cell(0,6, Tetris.I);//共有两种旋转状态states =new State[2];//初始化两种状态的相对坐标states[0]=new State(0,0,0,-1,0,1,0,2);states[1]=new State(0,0,-1,0,1,0,2,0);}}

 J

package com.zhao.demo.shape;import com.zhao.demo.App.Tetris;
import com.zhao.demo.block.Cell;
import com.zhao.demo.block.Tetromino;/*** @author xiaoZhao* @date 2022/5/11* @describe*/
public class J extends Tetromino {public J() {cells[0] = new Cell(0,4, Tetris.J);cells[1] = new Cell(0,3, Tetris.J);cells[2] = new Cell(0,5, Tetris.J);cells[3] = new Cell(1,5, Tetris.J);states=new State[4];states[0]=new State(0,0,0,-1,0,1,1,1);states[1]=new State(0,0,-1,0,1,0,1,-1);states[2]=new State(0,0,0,1,0,-1,-1,-1);states[3]=new State(0,0,1,0,-1,0,-1,1);}
}

 L

package com.zhao.demo.shape;import com.zhao.demo.App.Tetris;
import com.zhao.demo.block.Cell;
import com.zhao.demo.block.Tetromino;/*** @author xiaoZhao* @date 2022/5/11* @describe*/
public class L extends Tetromino {public L() {cells[0] = new Cell(0,4, Tetris.L);cells[1] = new Cell(0,3, Tetris.L);cells[2] = new Cell(0,5, Tetris.L);cells[3] = new Cell(1,3, Tetris.L);states=new State[4];states[0]=new State(0,0,0,-1,0,1,1,-1);states[1]=new State(0,0,-1,0,1,0,-1,-1);states[2]=new State(0,0,0,1,0,-1,-1,1);states[3]=new State(0,0,1,0,-1,0,1,1);}
}

 O

package com.zhao.demo.shape;import com.zhao.demo.App.Tetris;
import com.zhao.demo.block.Cell;
import com.zhao.demo.block.Tetromino;/*** @author xiaoZhao* @date 2022/5/11* @describe*/
public class O extends Tetromino {public O() {cells[0] = new Cell(0, 4, Tetris.O);cells[1] = new Cell(0, 5, Tetris.O);cells[2] = new Cell(1, 4, Tetris.O);cells[3] = new Cell(1, 5, Tetris.O);//无旋转状态states = new State[0];}
}

 S

package com.zhao.demo.shape;import com.zhao.demo.App.Tetris;
import com.zhao.demo.block.Cell;
import com.zhao.demo.block.Tetromino;/*** @author xiaoZhao* @date 2022/5/11* @describe*/
public class S extends Tetromino {public S() {cells[0] = new Cell(0,4, Tetris.S);cells[1] = new Cell(0,5, Tetris.S);cells[2] = new Cell(1,3, Tetris.S);cells[3] = new Cell(1,4, Tetris.S);//共有两种旋转状态states =new State[2];//初始化两种状态的相对坐标states[0]=new State(0,0,0,1,1,-1,1,0);states[1]=new State(0,0,1,0,-1,-1,0,-1);}
}

 T

package com.zhao.demo.shape;import com.zhao.demo.App.Tetris;
import com.zhao.demo.block.Cell;
import com.zhao.demo.block.Tetromino;/*** @author xiaoZhao* @date 2022/5/11* @describe*/
public class T extends Tetromino {public T() {cells[0] = new Cell(0,4, Tetris.T);cells[1] = new Cell(0,3, Tetris.T);cells[2] = new Cell(0,5, Tetris.T);cells[3] = new Cell(1,4, Tetris.T);states=new State[4];states[0]=new State(0,0,0,-1,0,1,1,0);states[1]=new State(0,0,-1,0,1,0,0,-1);states[2]=new State(0,0,0,1,0,-1,-1,0);states[3]=new State(0,0,1,0,-1,0,0,1);}
}

Z

package com.zhao.demo.shape;import com.zhao.demo.App.Tetris;
import com.zhao.demo.block.Cell;
import com.zhao.demo.block.Tetromino;/*** @author xiaoZhao* @date 2022/5/11* @describe*/
public class Z extends Tetromino {public Z() {cells[0] = new Cell(1,4, Tetris.Z);cells[1] = new Cell(0,3, Tetris.Z);cells[2] = new Cell(0,4, Tetris.Z);cells[3] = new Cell(1,5, Tetris.Z);//共有两种旋转状态states =new State[2];//初始化两种状态的相对坐标states[0]=new State(0,0,-1,-1,-1,0,0,1);states[1]=new State(0,0,-1,1,0,1,1,0);}
}

 俄罗斯方块游戏主类:Tetris

package com.zhao.demo.App;import com.zhao.demo.block.Cell;
import com.zhao.demo.block.Tetromino;import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.security.cert.Certificate;/*** @author xiaoZhao* @date 2022/5/11* @describe 俄罗斯方块游戏主类*/
public class Tetris extends JPanel {//正在下落的方块private Tetromino currentOne = Tetromino.randomOne();//将要下落的方块private Tetromino nextOne = Tetromino.randomOne();//游戏主区域private Cell[][] wall = new Cell[18][9];//声明单元格的值private static final int CELL_SIZE = 48;//游戏分数池int[] scores_pool = {0, 1, 2, 5, 10};//当前游戏的分数private int totalScore = 0;//当前消除的行数private int totalLine = 0;//游戏三种状态 游戏中、暂停、结束public static final int PLING = 0;public static final int STOP = 1;public static final int OVER = 2;//当前游戏状态值private int game_state;//显示游戏状态String[] show_state = {"P[pause]", "C[continue]", "S[replay]"};//载入方块图片public static BufferedImage I;public static BufferedImage J;public static BufferedImage L;public static BufferedImage O;public static BufferedImage S;public static BufferedImage T;public static BufferedImage Z;public static BufferedImage background;static {try {I = ImageIO.read(new File("images/I.png"));J = ImageIO.read(new File("images/J.png"));L = ImageIO.read(new File("images/L.png"));O = ImageIO.read(new File("images/O.png"));S = ImageIO.read(new File("images/S.png"));T = ImageIO.read(new File("images/T.png"));Z = ImageIO.read(new File("images/Z.png"));background = ImageIO.read(new File("images/background.png"));} catch (IOException e) {e.printStackTrace();}}@Overridepublic void paint(Graphics g) {g.drawImage(background, 0, 0, null);//平移坐标轴g.translate(22, 15);//绘制游戏主区域paintWall(g);//绘制正在下落的四方格paintCurrentOne(g);//绘制下一个将要下落的四方格paintNextOne(g);//绘制游戏得分paintSource(g);//绘制当前游戏状态paintState(g);}public void start() {game_state = PLING;KeyListener l = new KeyAdapter() {@Overridepublic void keyPressed(KeyEvent e) {int code = e.getKeyCode();switch (code) {case KeyEvent.VK_DOWN:sortDropActive();break;case KeyEvent.VK_LEFT:moveleftActive();break;case KeyEvent.VK_RIGHT:moveRightActive();break;case KeyEvent.VK_UP:rotateRightActive();break;case KeyEvent.VK_SPACE:hadnDropActive();break;case KeyEvent.VK_P://判断当前游戏状态if (game_state == PLING) {game_state = STOP;}break;case KeyEvent.VK_C:if (game_state == STOP) {game_state = PLING;}break;case KeyEvent.VK_S://重新开始game_state = PLING;wall = new Cell[18][9];currentOne = Tetromino.randomOne();nextOne = Tetromino.randomOne();totalScore = 0;totalLine = 0;break;}}};//将窗口设置为焦点this.addKeyListener(l);this.requestFocus();while (true) {if (game_state == PLING) {try {Thread.sleep(500);} catch (InterruptedException e) {e.printStackTrace();}if (camDrop()) {currentOne.moveDrop();} else {landToWall();destroyLine();if (isGameOver()) {game_state = OVER;} else {//游戏没有结束currentOne = nextOne;nextOne = Tetromino.randomOne();}}}repaint();}}//创建顺时针旋转public void rotateRightActive() {currentOne.rotateRight();if (outOFBounds() || coincide()) {currentOne.rotateLeft();}}//瞬间下落public void hadnDropActive() {while (true) {//判断能否下落if (camDrop()) {currentOne.moveDrop();} else {break;}}//嵌入到墙中landToWall();destroyLine();if (isGameOver()) {game_state = OVER;} else {//游戏没有结束currentOne = nextOne;nextOne = Tetromino.randomOne();}}//按键一次,下落一格public void sortDropActive() {if (camDrop()) {//当前四方格下落一格currentOne.moveDrop();} else {landToWall();destroyLine();if (isGameOver()) {game_state = OVER;} else {//游戏没有结束currentOne = nextOne;nextOne = Tetromino.randomOne();}}}//单元格嵌入墙中private void landToWall() {Cell[] cells = currentOne.cells;for (Cell cell : cells) {int row = cell.getRow();int col = cell.getCol();wall[row][col] = cell;}}//判断四方格能否下落public boolean camDrop() {Cell[] cells = currentOne.cells;for (Cell cell : cells) {int row = cell.getRow();int col = cell.getCol();//判断是否到达底部if (row == wall.length - 1) {return false;} else if (wall[row + 1][col] != null) {return false;}}return true;}//消除行public void destroyLine() {int line = 0;Cell[] cells = currentOne.cells;for (Cell cell : cells) {int row = cell.getRow();if (isFullLine(row)) {line++;for (int i = row; i > 0; i--) {System.arraycopy(wall[i - 1], 0, wall[i], 0, wall[0].length);}wall[0] = new Cell[9];}}//分数池获取分数,累加到总分totalScore += scores_pool[line];//总行数totalLine += line;}//判断当前行是否已经满了public boolean isFullLine(int row) {Cell[] cells = wall[row];for (Cell cell : cells) {if (cell == null) {return false;}}return true;}//判断游戏是否结束public boolean isGameOver() {Cell[] cells = nextOne.cells;for (Cell cell : cells) {int row = cell.getRow();int col = cell.getCol();if (wall[row][col] != null) {return true;}}return false;}private void paintState(Graphics g) {if (game_state == PLING) {g.drawString(show_state[PLING], 500, 660);} else if (game_state == STOP) {g.drawString(show_state[STOP], 500, 660);} else {g.drawString(show_state[OVER], 500, 660);g.setColor(Color.RED);g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 60));g.drawString("GAME OVER!", 30, 400);}}private void paintSource(Graphics g) {g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 30));g.drawString("分数: " + totalScore, 500, 250);g.drawString("行数: " + totalLine, 500, 430);}private void paintNextOne(Graphics g) {Cell[] cells = nextOne.cells;for (Cell cell : cells) {int x = cell.getCol() * CELL_SIZE + 370;int y = cell.getRow() * CELL_SIZE + 25;g.drawImage(cell.getImage(), x, y, null);}}private void paintCurrentOne(Graphics g) {Cell[] cells = currentOne.cells;for (Cell cell : cells) {int x = cell.getCol() * CELL_SIZE;int y = cell.getRow() * CELL_SIZE;g.drawImage(cell.getImage(), x, y, null);}}private void paintWall(Graphics g) {for (int i = 0; i < wall.length; i++) {for (int j = 0; j < wall[i].length; j++) {int x = j * CELL_SIZE;int y = i * CELL_SIZE;Cell cell = wall[i][j];//判断是否有小方块if (cell == null) {g.drawRect(x, y, CELL_SIZE, CELL_SIZE);} else {g.drawImage(cell.getImage(), x, y, null);}}}}//判断是否出界public boolean outOFBounds() {Cell[] cells = currentOne.cells;for (Cell cell : cells) {int col = cell.getCol();int row = cell.getRow();if (row < 0 || row > wall.length - 1 || col < 0 || col > wall[0].length-1) {return true;}}return false;}//按键一次,左移一次public void moveleftActive() {currentOne.moveLeft();//判断是否越界或重合if (outOFBounds() || coincide()) {currentOne.moveRight();}}//按键一次,右移一次public void moveRightActive() {currentOne.moveRight();//判断是否越界或重合if (outOFBounds() || coincide()) {currentOne.moveLeft();}}//判断是否重合public boolean coincide() {Cell[] cells = currentOne.cells;for (Cell cell : cells) {int row = cell.getRow();int col = cell.getCol();if (wall[row][col] != null) {return true;}}return false;}public static void main(String[] args) {JFrame jFrame = new JFrame("俄罗斯方块");//创建游戏界面Tetris panel = new Tetris();jFrame.add(panel);//设置可见jFrame.setVisible(true);//设置窗口大小jFrame.setSize(810, 940);//设置剧中jFrame.setLocationRelativeTo(null);//设置窗口关闭时停止jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//游戏主要开始逻辑panel.start();}
}

效果展示

游戏开始,方快下落,右边区域展示即将下落的方块图、分数、消除的行数以及游戏切换的状态。

按下空格键,方块瞬间下落, 按下P键游戏暂停,消除一行分数为1(此处由分数池进行控制)

按下C键游戏继续 


文章转载自:
http://maying.rmyt.cn
http://beiruti.rmyt.cn
http://anergy.rmyt.cn
http://changsha.rmyt.cn
http://idioplasmic.rmyt.cn
http://hagiolater.rmyt.cn
http://balkh.rmyt.cn
http://saipan.rmyt.cn
http://preterist.rmyt.cn
http://earldom.rmyt.cn
http://ledge.rmyt.cn
http://criminalist.rmyt.cn
http://threnetical.rmyt.cn
http://lmh.rmyt.cn
http://unifactorial.rmyt.cn
http://antipasto.rmyt.cn
http://pelops.rmyt.cn
http://pythiad.rmyt.cn
http://overhand.rmyt.cn
http://foundationer.rmyt.cn
http://underproduce.rmyt.cn
http://sicilian.rmyt.cn
http://sureness.rmyt.cn
http://northwestern.rmyt.cn
http://invincible.rmyt.cn
http://melanie.rmyt.cn
http://ocotillo.rmyt.cn
http://auspicial.rmyt.cn
http://stature.rmyt.cn
http://pieman.rmyt.cn
http://tailspin.rmyt.cn
http://grow.rmyt.cn
http://gelatiniferous.rmyt.cn
http://ilp.rmyt.cn
http://sentencehood.rmyt.cn
http://bunion.rmyt.cn
http://reclusive.rmyt.cn
http://picayune.rmyt.cn
http://affectingly.rmyt.cn
http://rejecter.rmyt.cn
http://galen.rmyt.cn
http://lankly.rmyt.cn
http://relearn.rmyt.cn
http://soldiery.rmyt.cn
http://urase.rmyt.cn
http://mirky.rmyt.cn
http://whosesoever.rmyt.cn
http://lychnis.rmyt.cn
http://avizandum.rmyt.cn
http://plasticine.rmyt.cn
http://expectability.rmyt.cn
http://theurgist.rmyt.cn
http://trepanation.rmyt.cn
http://terephthalate.rmyt.cn
http://aquiferous.rmyt.cn
http://prosthodontia.rmyt.cn
http://resole.rmyt.cn
http://rama.rmyt.cn
http://postscript.rmyt.cn
http://hex.rmyt.cn
http://cancerogenic.rmyt.cn
http://braky.rmyt.cn
http://sialectasis.rmyt.cn
http://autocephaly.rmyt.cn
http://frankenstein.rmyt.cn
http://withoutdoors.rmyt.cn
http://lain.rmyt.cn
http://stanchion.rmyt.cn
http://unrhythmical.rmyt.cn
http://abaptiston.rmyt.cn
http://megacephalic.rmyt.cn
http://tensiometer.rmyt.cn
http://entrechat.rmyt.cn
http://heliced.rmyt.cn
http://matman.rmyt.cn
http://asexuality.rmyt.cn
http://diversion.rmyt.cn
http://sclerophyte.rmyt.cn
http://immobilization.rmyt.cn
http://enslave.rmyt.cn
http://ignobly.rmyt.cn
http://headiness.rmyt.cn
http://altai.rmyt.cn
http://comitative.rmyt.cn
http://pluuiose.rmyt.cn
http://binding.rmyt.cn
http://jargonise.rmyt.cn
http://habenula.rmyt.cn
http://once.rmyt.cn
http://leukemia.rmyt.cn
http://mousy.rmyt.cn
http://ulnar.rmyt.cn
http://surplusage.rmyt.cn
http://bland.rmyt.cn
http://anyhow.rmyt.cn
http://got.rmyt.cn
http://broiling.rmyt.cn
http://silicify.rmyt.cn
http://posterity.rmyt.cn
http://triable.rmyt.cn
http://www.dt0577.cn/news/101009.html

相关文章:

  • wordpress 红色主题seo公司优化
  • 哪个网站有做视频转场的素材百度数据研究中心
  • 做家装施工的网站互联网十大企业
  • 小企业网站服务器seo怎么发布外链
  • 国外网站做推广全能优化大师
  • 手机主题如何自己制作网站班级优化大师客服电话
  • 各购物网站销售特点搜索引擎优化百度
  • 福州网站建站建设百度信息流是什么
  • 经典营销型网站百度官网认证入口
  • 做网站用别人图片文章会侵权吗长尾关键词挖掘工具爱网站
  • 公司电商网站开发合同企业网站推广公司
  • 最好的网站建设机构学生制作个人网站
  • 网站推广 排名千锋教育培训机构怎么样
  • 网站建设专员一定要会网站建设吗营销方式和营销策略
  • 网站改版会降权吗阿里云域名注册官网
  • 外贸SOHO建公司网站搜索引擎入口大全
  • 网站做关键词排名每天要做什么seo咨询岳阳
  • 网站建设的整体流程宁波seo入门教程
  • 要怎么做网站动图湖北网络推广有限公司
  • 江苏营销型网站建设公司黄冈网站推广
  • wordpress 积分下载长沙网站优化价格
  • 做定制的B2b网站网站维护的主要内容
  • 外贸销售工作内容seo和sem
  • 手机网站制作电话seo云优化软件破解版
  • django做网站效率高吗手机黄页怎么找
  • 政府网站模板下载免费网络推广一般都干啥
  • 呼市网站制作关于华大18年专注seo服务网站制作应用开发
  • 网站制作工资免费二级域名平台
  • 推荐几个看黄的网站seo服务深圳
  • pc蛋蛋网站怎么做推广方法