-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbollywoodGame.java
84 lines (82 loc) · 3.19 KB
/
bollywoodGame.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
import java.io.*;
import java.util.Scanner;
class bollywoodGame {
static int score=9,flag=0;
public static void main (String[] args)
{
int count_1=0;
Scanner s=new Scanner(System.in);
String player1=s.nextLine();
StringBuffer sc= new StringBuffer (player1);
StringBuffer sc1= new StringBuffer ();
sc1.setLength(sc.length());
//-------------------------------------------------check vowel-------------------------------------------------------------
for(int i=0;i<player1.length();i++)
{
if(sc.charAt(i)=='A'||sc.charAt(i)=='a'||sc.charAt(i)=='e'||sc.charAt(i)=='E'||sc.charAt(i)=='I'||sc.charAt(i)=='i'||sc.charAt(i)=='o'||sc.charAt(i)=='O'||sc.charAt(i)=='u'||sc.charAt(i)=='U')
{
char a=sc.charAt(i);
sc1.setCharAt(i,a);
}
else
{
//------------------------------------------------------------------------set blankets to next strong----------------------------------
sc1.setCharAt(i,'_');
count_1++;
}
}
score=count_1;// u have only count1 chances for winning this game and count1 is equals to number of consonante in string
System.out.println(sc1);
//----------------------------------------------loop end to 0-------------------------------------------------------------------------------------
while(score>0)
{
int flag2=1;
//--------------------------------------------if it complete all the blanks-------------------------------------------------------------
if(flag==1)
{
break;
}
//------------------------------------------------------------scan a characters------------------------------------------------
char x=s.next().charAt(0);
char temp=x;
//---------------------------------------------chech character is in the name--------------------------------------------------
for(int i=0;i<sc.length();i++)
{
if(Character.toLowerCase(sc.charAt(i)) ==Character.toLowerCase(x))
{
//----------------------------------------if uou get break----------------------------------------------------------
flag2=0;
break;
}
}
//---------------------------------------if not score decrement ---------------------------------------------------------------------
if(flag2==1)
{
score--;
System.out.println("Wrong Answer"+" "+" You have only "+score+" Choices ");
}
//--------------------------------------put the character in the sytring 2-----------------------------------------------------
if(flag2==0)
{
for(int i=0;i<sc.length();i++)
{
if(Character.toLowerCase(sc.charAt(i)) ==Character.toLowerCase(x)&&sc1.charAt(i)=='_')
{
sc1.setCharAt(i,sc.charAt(i));
String k=sc1.toString();
String l=sc.toString();
flag=0;
if(l.equals(k))
{
//-----------------------------------------------------------------flag=1 hame over------------------------------------------
flag=1;
break;
}
}
}
System.out.println(sc1);
}
}
System.out.println(score);
}
}