b2c信息网

您现在的位置是:首页 > 今日新闻 > 正文

今日新闻

求web前端打字游戏源码(大型WEB文字游戏源码)

hacker2022-06-11 09:13:30今日新闻45
本文目录一览:1、求JAVA编写打字游戏源代码!

本文目录一览:

求JAVA编写打字游戏源代码!

package chen;

import java.awt.*;

import java.awt.event.*;

import java.awt.image.BufferedImage;

import java.util.Vector;

import javax.swing.JFrame;

public class keyTest extends Window implements KeyListener, Runnable {

int width, height;

BufferedImage buf;

Graphics gc;

boolean play = true;

VectoroneChar keys = new VectoroneChar();

int ok = 0, fail = 0, error = 0, sum = 0;

Font small = new Font("宋体", 0, 30);

Font big = new Font("宋体", 0, 50);

long time = System.currentTimeMillis();

keyTest(Frame f) {

super(f);

Dimension s = getToolkit().getScreenSize();

width = (int) s.getWidth();

height = (int) s.getHeight();

this.setBounds(0, 0, width, height);

this.buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

gc = buf.getGraphics();

this.setVisible(true);

this.setAlwaysOnTop(true);

this.buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

gc = buf.getGraphics();

new Thread(this).start();

}

public static void main(String s[]) {

JFrame help = new JFrame("打字练习");

help.setVisible(true);

help.setDefaultCloseOperation(3);

help.addKeyListener(new keyTest(help));

}

public void keyTyped(KeyEvent e) {

}

public synchronized void keyPressed(KeyEvent e) {

if (e.getKeyCode() == 27) {

play = false;

this.dispose();

System.exit(0);

}

char s = e.getKeyChar();

if (s = 'a' s = 'z' || (s = 'A' s = 'Z')) {

String l = "" + s;

for (int i = 0; i keys.size(); i++) {

if (l.equals(((oneChar) keys.elementAt(i)).s)) {

keys.removeElementAt(i);

ok++;

return;

}

}

error++;

}

}

public void keyReleased(KeyEvent e) {

}

@Override

public void update(Graphics g) {

gc.setColor(Color.BLACK);

gc.fillRect(0, 0, width, height);

gc.setColor(Color.red);

int l = (ok + error) 0 ? (ok * 100 / (ok + error)) : 100;

gc.setFont(small);

gc.drawString("成功:" + ok + " 错误:" + error + " 失败:" + fail + " 正确率:" + l + "% 时间:" + (System.currentTimeMillis() - time) / 1000, 10, height - 30);

gc.setFont(big);

oneChar o;

for (int i = 0; i keys.size(); i++) {

o = keys.elementAt(i);

gc.setColor(o.c);

gc.drawString(o.s, o.x, o.y += 6);

if (o.y height - 10) {

fail++;

keys.removeElementAt(i);

}

}

g.drawImage(buf, 0, 0, null);

}

public void run() {

while (play) {

try {

sum++;

if (sum % 5 == 0) {

newchar();

}

Thread.sleep(80);

repaint();

} catch (InterruptedException ex) {

ex.printStackTrace();

}

}

}

private void newchar() {

keys.add(oneChar.getinstance(width));

}

}

package chen;

import java.awt.Color;

public class oneChar {

static java.util.Random r = new java.util.Random();

public static oneChar getinstance(int maxX) {

oneChar a = new oneChar();

int b = r.nextInt(26);

a.s = "" + (char) (b + (r.nextInt(4) 1 ? 'a' : 'A'));

a.x = r.nextInt(maxX - 30);

a.c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));

return a;

}

int x, y;

Color c;

String s;

}

大型的web前端源码去哪里可以下载?

html的标签确实比较多。说实在它和CSS结合在一起的时候也很麻烦。掌握他们关键在实践,那就是自己动手敲。在github上找一些小项目敲一敲,完成一个项目就会有信心了。就会发现没那么难。前期不要急,欲速不达。

用java web小游戏源代码。期末结课老师让做,急用,谢了

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.Toolkit;

import javax.swing.JFrame;

@SuppressWarnings("serial")

public class MainClass extends JFrame {

ControlSnake control;

Toolkit kit;

Dimension dimen;

public static void main(String[] args) {

new MainClass("my snake");

}

public MainClass(String s) {

super(s);

control = new ControlSnake();

control.setFocusable(true);

kit = Toolkit.getDefaultToolkit();

dimen = kit.getScreenSize();

add(control);

setLayout(new BorderLayout());

setLocation(dimen.width / 3, dimen.height / 3);// dimen.width/3,dimen.height/3

setSize(FWIDTH, FHEIGHT);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setResizable(false);

setVisible(true);

}

public static final int FWIDTH = 315;

public static final int FHEIGHT = 380;

}

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.Point;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.util.ArrayList;

import java.util.Random;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.Timer;

@SuppressWarnings("serial")

public class ControlSnake extends JPanel implements ActionListener {

Random rand;

ArrayListPoint list, listBody;

String str, str1;

static boolean key;

int x, y, dx, dy, fx, fy, flag;

int snakeBody;

int speed;

public ControlSnake() {

snakeBody = 1;

str = "上下左右方向键控制 P键暂停...";

str1 = "现在的长度为:" + snakeBody;

key = true;

flag = 1;

speed = 700;

rand = new Random();

list = new ArrayListPoint();

listBody = new ArrayListPoint();

x = 5;

y = 5;

list.add(new Point(x, y));

listBody.add(list.get(0));

dx = 10;

dy = 0;

fx = rand.nextInt(30) * 10 + 5;// 2

fy = rand.nextInt(30) * 10 + 5;// 2

setBackground(Color.BLACK);

setSize(new Dimension(318, 380));

final Timer time = new Timer(speed, this);

time.start();

addKeyListener(new KeyAdapter(){

public void keyPressed(KeyEvent e) {

if (e.getKeyCode() == 37) {

dx = -10;

dy = 0;

} else if (e.getKeyCode() == 38) {

dx = 0;

dy = -10;

} else if (e.getKeyCode() == 39) {

dx = 10;

dy = 0;

} else if (e.getKeyCode() == 40) {

dx = 0;

dy = 10;

} else if (e.getKeyCode() == 80) {

if (flag % 2 == 1) {

time.stop();

}

if (flag % 2 == 0) {

time.start();

}

flag++;

}

}

});

}

public void paint(Graphics g) {

g.setColor(Color.WHITE);

g.fillRect(0, 0, 400, 400);

g.setColor(Color.DARK_GRAY);

g.drawLine(3, 3, 305, 3);

g.drawLine(3, 3, 3, 305);

g.drawLine(305, 3, 305, 305);

g.drawLine(3, 305, 305, 305);

g.setColor(Color.PINK);

for (int i = 0; i listBody.size(); i++) {

g.fillRect(listBody.get(i).x, listBody.get(i).y, 9, 9);

}

g.fillRect(x, y, 9, 9);

g.setColor(Color.ORANGE);

g.fillRect(fx, fy, 9, 9);

g.setColor(Color.DARK_GRAY);

str1 = "现在的长度为:" + snakeBody;

g.drawString(str, 10, 320);

g.drawString(str1, 10, 335);

}

public void actionPerformed(ActionEvent e) {

x += dx;

y += dy;

if (makeOut() == false) {

JOptionPane.showMessageDialog(null, "重新开始......");

speed = 700;

snakeBody = 1;

x = 5;

y = 5;

list.clear();

list.add(new Point(x, y));

listBody.clear();

listBody.add(list.get(0));

dx = 10;

dy = 0;

}

addPoint(x, y);

if (x == fx y == fy) {

speed = (int) (speed * 0.8);//速度增加参数

if (speed 200) {

speed = 100;

}

fx = rand.nextInt(30) * 10 + 5;// 2

fy = rand.nextInt(30) * 10 + 5;// 2

snakeBody++;// 2

} // 2

repaint();

}

public void addPoint(int xx, int yy) {

// 动态的记录最新发生的50步以内的移动过的坐标

// 并画出最新的snakeBody

if (list.size() 100) {//蛇身长度最长为100

list.add(new Point(xx, yy));

} else {

list.remove(0);

list.add(new Point(xx, yy));

}

if (snakeBody == 1) {

listBody.remove(0);

listBody.add(0, list.get(list.size() - 1));

} else {

listBody.clear();

if (list.size() snakeBody) {

for (int i = list.size() - 1; i 0; i--) {

listBody.add(list.get(i));

}

} else {

for (int i = list.size() - 1; listBody.size() snakeBody; i--) {

listBody.add(list.get(i));

}

}

}

}

public boolean makeOut() {

if ((x 3 || y 3) || (x 305 || y 305)) {

return false;

}

for (int i = 0; i listBody.size() - 1; i++) {

for (int j = i + 1; j listBody.size(); j++) {

if (listBody.get(i).equals(listBody.get(j))) {

return false;

}

}

}

return true;

}

}

/*贪吃蛇代码*/

谁能写一个java打字游戏 超级简单的源码

编好了,你自己运行下:

import java.util.Random;

import java.util.Scanner;

public class Test

{

public static Random r = new Random();

public static void printMenu()

{

System.out.println("(1) play another round");

System.out.println("(2) exit the game");

System.out.print("Selection:");

}

public static void main(String[] args) throws Exception

{

String content = null;

Scanner scan = new Scanner(System.in);

while(true)

{

printMenu();

content = scan.nextLine();

System.out.println();

//输入内容是2,则退出程序

if(content.equals("2")) break;

if(content.equals("1"))

{

System.out.print("Text to Match: ");

int count = r.nextInt(50) + 1;

char[] letters = new char[count];

for(int i=0;icount;i++)

{

letters[i] = (char)(r.nextInt(26) + 97);

System.out.print(letters[i]);

}

System.out.print("\n ");

long startTime = System.currentTimeMillis();

int correctCount = 0;

content = scan.nextLine();

for(int i=0;icount;i++)

{

if(content.charAt(i) == letters[i])

correctCount++;

}

long endTime = System.currentTimeMillis();

int time = (int)((endTime - startTime) / 1000);

if(correctCount == 0)

System.out.println("INCORRECTLY TYPED, YOU GET A SPEED OF 0!");

else

{

System.out.println("共花了" + time + "秒,正确率为:" + ((int)(((double)correctCount/count))*100) + "%");

}

}

System.out.println();

}

}

}

求纯C语言打字游戏源代码及解析

# include "Typer.h"

# include stdio.h

# include stdlib.h

# include graphics.h

//download by

void main()

{

BOOL bQuit=FALSE; /* 是否退出 */

BOOL bPause=FALSE; /* 是否暂停 */

int tm1,tm2;

BYTE Key;

randomize(); /* 初始化随机数种子 */

SetGraphMode();

SelectLevel();

ShowBar();

tm1=CreateTimer(1,MoveLetter); /* 创建移动字符对象时钟 */

tm2=CreateTimer(Interval,CreateLetter); /* 创建产生字符对象时钟 */

CreateLetter();

Key=AscKey();

while (!bQuit)

{

TimerEvent();

switch (Key)

{

case NULL:

break;

case KEY_ESC:

bQuit=TRUE;

break;

case KEY_SPACE:

bPause=!bPause;

tmTM[tm1].Enable=!bPause;

tmTM[tm2].Enable=!bPause;

break;

default:

if (!bPause) Check(Key);

}

Key=AscKey();

}

CloseGraphMode();

}

void SetGraphMode()

{

int Device=VGA,Mode=VGAHI;

initgraph(Device,Mode,"");

settextstyle(TRIPLEX_FONT,HORIZ_DIR,1);

setfillstyle(SOLID_FILL,0);

setcolor(7);

}

void CloseGraphMode()

{

restorecrtmode();

}

/* 从键盘缓冲区内直接读出ASC码 */

BYTE AscKey(void)

{

int start,end;

WORD key=0;

start=peek(0,0x41a);

end=peek(0,0x41c);

if (start==end) return(0);

else

{

key=peek(0x40,start);

start+=2;

if (start==0x3e) start=0x1e;

poke(0x40,0x1a,start);

return(key0xff);

}

}

void MoveLetter(void)

{

int i;

for (i=0;iMAX_LETTER;i++)

{

if (Letter[i].Used)

{

HideLetter(i);

Letter[i].y+=Step;

ShowLetter(i);

/* 字符对象下落到最底部 */

if (Letter[i].yMAX_HEIGHT) KillLetter(i);

}

}

}

void KillLetter(int LetterID)

{

if (Letter[LetterID].Used)

{

Letter[LetterID].Used=FALSE;

LetterUsed--;

HideLetter(LetterID);

}

/* 删除字符对象后马上再创建一个 */

CreateLetter();

}

void CreateLetter()

{

int i=0;

int x;

BYTE val;

if (LetterUsed==MAX_LETTER) return; /* 无字符对象可用则返回 */

while (Letter[++i].Used); /* 找到第一个空闲的字符对象,产生一个字符对象 */

x=i;

Letter[i].x=x*640/MAX_LETTER;

Letter[i].y=0;

Letter[i].val=random(26)+'A';

Letter[i].Used=TRUE;

LetterUsed++;

}

void HideLetter(int ID)

{

/* 用填充矩形来消隐字符 */

bar(Letter[ID].x,Letter[ID].y,Letter[ID].x+16,Letter[ID].y+20);

}

void ShowLetter(int ID)

{

char str[2]={0,0};

str[0]=Letter[ID].val;

outtextxy(Letter[ID].x,Letter[ID].y,str);

}

void Check(BYTE Key)

{

int i;

char str[6];

Hits++;

for (i=0;iMAX_LETTER;i++)

/* 击中 */

if (Letter[i].UsedLetter[i].val==toupper(Key))

{

sound(1000);

delay(10);

KillLetter(i);

Right++;

nosound();

}

/* 显示状态 */

setfillstyle(SOLID_FILL,5);

bar(260,430,320,450);

bar(410,430,470,450);

setcolor(2);

sprintf(str," %4ld",Hits);

outtextxy(260,430,str);

sprintf(str," %4ld",Right);

outtextxy(410,430,str);

setcolor(7);

setfillstyle(SOLID_FILL,0);

}

void ShowBar()

{

FILE *bmp;

BYTE r,g,b,t;

int i,x,y;

bmp=fopen("bar.bmp","rb");

fseek(bmp,54,SEEK_SET);

for (i=0;i16;i++)

{

setpalette(i,i);

b=fgetc(bmp)2;

g=fgetc(bmp)2;

r=fgetc(bmp)2;

t=fgetc(bmp)2;

setrgbpalette(i,r,g,b);

}

for (y=0;y80;y++)

for (x=0;x320;x++)

{

t=fgetc(bmp);

putpixel(x*2,479-y,t4);

putpixel(x*2+1,479-y,t15);

}

fclose(bmp);

}

void SelectLevel()

{

int Steps[3]={1,2,4};

int Intervals[3]={18,9,5};

int Sel=0;

FILE *bmp;

BYTE r,g,b,t,Key;

int i,x,y;

bmp=fopen("sel.bmp","rb");

fseek(bmp,54,SEEK_SET);

for (i=0;i16;i++)

{

setpalette(i,i);

b=fgetc(bmp)2;

g=fgetc(bmp)2;

r=fgetc(bmp)2;

t=fgetc(bmp)2;

setrgbpalette(i,r,g,b);

}

for (y=0;y200;y++)

for (x=0;x160;x++)

{

t=fgetc(bmp);

putpixel(x*2+160,339-y,t4);

putpixel(x*2+161,339-y,t15);

}

fclose(bmp);

while (TRUE)

{

Key=toupper(AscKey());

if (Key=='A') Sel=1;

if (Key=='B') Sel=2;

if (Key=='C') Sel=3;

if (Sel) break;

}

Step=Steps[Sel-1];

Interval=Intervals[Sel-1];

cleardevice();

}

/*********************************************************/

/* 文件:TIMER.H */

/*********************************************************/

/*********************************************************/

/* 系统可用计时器的最大数目 */

# define MAXTIMER 10

# ifndef NULL

# define NULL 0

# endif

/* 计时器结构 */

struct TM

{

DWORD Interval; /* 间隔 */

DWORD LastTimer; /* 上次事件发生时间*/

BOOL Enable; /* 活动 */

BOOL Used; /* 可用 */

void (*Pointer)(); /* 事件远指针 */

};

struct TM tmTM[MAXTIMER+1];

int TimerUsed=0;

/* 获取BIOS计数器数值 */

DWORD BiosTimer(void)

{

DWORD BIOSTIMER=0;

BIOSTIMER=peek(0x0,0x46e);

BIOSTIMER=8;

BIOSTIMER+=peek(0x0,0x46c);

return (BIOSTIMER);

}

/* 时间事件(时钟系统核心) */

void TimerEvent()

{

int i;

DWORD TimerDiff;

for (i=1;i=MAXTIMER;i++)

{

if (tmTM[i].UsedtmTM[i].Enable)

{

TimerDiff=BiosTimer()-tmTM[i].LastTimer;

if (tmTM[i].Interval=TimerDiff)

{

tmTM[i].Pointer();

tmTM[i].LastTimer=BiosTimer();

}

}

}

}

/* 创建一个时钟(成功返回时钟的句柄,否则返回NULL) */

int CreateTimer(DWORD Interval,void (*Pointer)())

{

int i=0;

if (TimerUsed==MAXTIMER) return NULL;

while (tmTM[++i].Used);

tmTM[i].Pointer=Pointer;

tmTM[i].Interval=Interval;

tmTM[i].Enable=TRUE;

tmTM[i].Used=TRUE;

tmTM[i].LastTimer=BiosTimer();

TimerUsed++;

return i;

}

/* 删除一个时钟 */

void KillTimer(int *TimerID)

{

if (tmTM[*TimerID].Used)

{

TimerUsed--;

tmTM[*TimerID].Used=FALSE;

}

*TimerID=0;

}

/* 删除所有时钟 */

void KillAllTimer()

{

int i;

for (i=0;i=MAXTIMER;i++) tmTM[i].Used=FALSE;

TimerUsed=0;

}

发表评论

评论列表

  • 晴枙过活(2022-06-11 20:30:38)回复取消回复

    snakeBody = 1; x = 5; y = 5; list.clear(); list.add(new Point(x, y)); listBody.clear(); listBody.add(list.get(0)); dx = 10; dy =