-
Notifications
You must be signed in to change notification settings - Fork 0
/
battletest.java
108 lines (87 loc) · 4.14 KB
/
battletest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.io.*;
import java.util.*;
class battle{
int y1,w1,b1,d1;
public void battleship()throws IOException{
String[][] batgrid = new String[5][5];
int x = batgrid.length;
int y = (int)(Math.random()*x);
y1 = y;
int z= batgrid.length;
int w = (int)(Math.random()*z);
w1 = w;
batgrid[y][w] = "VULCAN SHIP 1 ";
int a = batgrid.length;
int b = (int)(Math.random()*a);
b1 = b;
int c = batgrid.length;
int d = (int)(Math.random()*c);
d1 = d;
batgrid[b][d] = "VULCAN SHIP 2 ";
System.out.println(" *******************WELCOME TO BATTLESHIP***********************");
//System.out.println(""+y+""+w+" "+b+""+d);
//System.out.println(""+batgrid[y][w]+"***"+batgrid[b][d]);
}
}
class battleshipmain extends battle{
void bmc()throws IOException{
for(int r =1;r<4;r++){
System.out.println(" 1. NEW GAME "+" 2.RULES 3. EXIT ");
BufferedReader eng = new BufferedReader(new InputStreamReader(System.in));
r =Integer.parseInt(eng.readLine());
if(r==1){
System.out.println(" LET THE GAME BEGIN ");
System.out.println(" WELCOME PLAYER ");
System.out.println(" YOUR AIM IS TO SAVE THE HUMANITY FROM THE VULCANS ");
int c1,c2;
int count = 0;
for(int k=2;k>=0;k--){
System.out.println(" ENTER THE COORDINATES : ");
BufferedReader cor = new BufferedReader(new InputStreamReader(System.in));
c1 = Integer.parseInt(cor.readLine());
if(c1>6){
System.out.println(" INVALID INPUT , ENTER THE COORDINATE AGAIN (RANGE 0-5) :");
c1 = Integer.parseInt(cor.readLine());
}
c2 = Integer.parseInt(cor.readLine());
if(c2>6){
System.out.println(" INVALID INPUT , ENTER THE COORDINATE AGAIN (RANGE 0-5) :");
c2 = Integer.parseInt(cor.readLine());
}
if(c1==y1&&c2==w1||c1==b1&&c2==d1){
System.out.println(" DIRECT HIT GOOD ONE !!! ");
count = count +1;
}
else {System.out.println(" SORRY YOU MISSED THE VULCAN SHIP ... TRY AGAIN!!");
System.out.println(" CHANCES LEFT "+k);}
}
if(count==2){
System.out.println(" YOU WON CONGRATS ON SAVING THE HUMANITY !!!");
}
else{
System.out.println(" YOU LOST !! BETTER LUCK NEXT TIME ");
}
}
else if(r==2){
System.out.println(" RULES : ");
System.out.println("1. There are two battleships in the space. And your battleship is hidden in the Saturn dust.");
System.out.println("2. YOUR SHIP IS THE USS ENTERPRISE. YOUR MISSION IS TO SAVE THE HUMANITY FROM THE VULCANS. ");
System.out.println("3. You have three chances to hit the Vulcan ship before they figure out your position and you fail to save the humanity from annihilation.");
System.out.println("4. Enter the desired coordinates, make sure you enter the coordinates wisely as you will only get 3 chances");
System.out.println("5. If you successfully blow up the VULCANS SHIP in one go then you get an extra chance.");
System.out.println("6. Coordinates Range (0-5)(0-5)");
}
else if(r==3){
System.out.println("THANK YOU FOR PLAYING");
break;
}
}
}
}
class battletest {
public static void main(String[] args)throws IOException {
battleshipmain obj = new battleshipmain();
obj.battleship();
obj.bmc();
}
}