飞翔的小鸟java素材
时间: 2023-12-20 07:32:38 浏览: 69
你好,以下是一个简单的Java代码示例,实现了一个“飞翔的小鸟”小游戏:
```java
import java.util.Scanner;
public class FlyingBirdGame {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int height = 10;
int width = 20;
boolean isFlying = false;
boolean isJumping = false;
int score = 0;
int gameOver = false;
char c = 'n';
char[] bird = {'n', 'n', 'n', 'n', 'n'};
int[] pipe = {20, 15, 50, 20, 20};
int gap = 15; int gravity = 1;
int velocity = 0;
int maxVelocity = 15; int minVelocity = -15;
while (!gameOver) {
System.out.println("Press n to start, m to mute, j to jump, k to fly");
c = scanner.next().charAt(0);
if (c == 'm') {
System.out.println("Muted");
} else if (c == 'j') {
isJumping = true;
} else if (c == 'k') {
isFlying = true;
} else if (c == 'n') {
isJumping = false;
isFlying = false;
} else if (Character.isDigit(c)) {
score += Integer.parseInt(Character.toString(c)); } else if (c == 'g') {
gameOver = true;
} else if (c == 'q') {
System.exit(0);
} else {
System.out.println("Invalid input");
}
for (int i = 0; i < height - 1; i++) {
if (i == 0 || i == 19) {
System.out.print("#");
} else if (i % 20 == 0) {
System.out.print("@");
} else if (i % gap == 0) {
System.out.print("-");
} else if (i % gap == 2 && i != height - 2) {
System.out.print("|"); } else if (i % gap == 3 && i != height - 2) {
System.out.print("/\\");
} else if (i % gap == 4 && i != height - 2) {
System.out.print("\\/");
} else if (i % gap == 5 && i != height - 2) {
System.out.print("_/");
} else if (i % gap == 6 && i != height - 2) {
System.out.print("|/");
} else if (i % gap == 7 && i != height - 2) {
System.out.print("/\\");
} else if (i % gap == 8 && i != height - 2) {
System.out.print("\\/");
} else if (i % gap == 9 && i != height - 2) {
System.out.print("_/");
} else if (i % gap == 10 && i != height - 2) {
System.out.print("/\\");
} else if (i % gap == 11 && i != height - 2) {
System.out.print("\\/");
} else if (i % gap == 12 && i != height - 2) {
System.out.print("_/");
} else if (i % gap == 13 && i != height - 2) {
System.out.print("|/");
} else if (i % gap == 14 && i != height - 2) {
System.out--;
阅读全文