-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
66 lines (59 loc) · 1.5 KB
/
Player.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
import java.util.*;
public class Player implements Runnable
{
private SharedData obj;
private int id;
private int[] arr=new int[10];
private int count=0;
private String name;
//private HashSet<Integer> st=new HashSet<Integer>();
public Player(SharedData obj,int id,String name)
{
this.obj=obj;
this.id=id;
this.name=name;
Random num=new Random();
int i=0;
for(i=0;i<10;i++)
{
arr[i]=num.nextInt(50)+1;
}
}
public void display()
{
System.out.println("The PLAYER "+this.name+" WITH ID "+ this.id+" HAS THE FOLLOWING CARDS:");
for(int i=0;i<10;i++)
System.out.print(arr[i]+" ");
System.out.println();
}
public void run()
{
while(!obj.gameCompleteFlag)
{
int value=obj.get();
int flag=0;
for(int i=0;i<10;i++)
{
if(arr[i]==value)
{
// System.out.println(obj.avl());
System.out.println("THE PLAYER " +this.name+" WITH ID "+this.id+" HAS GOT THIS CARD");
flag=1;
this.count++;
arr[i]=51;//jisse ye firse strikeout na ho kyuki range 1-50 ki h
break;//to prevent striking all the redundant occurrences of a number
}
}
if(flag==0)
{
// System.out.println(obj.avl());
System.out.println("THE PLAYER "+this.name+" WITH ID "+this.id+" DON'T HAS GOT THIS CARD");
}
if(count==3)
{
System.out.println("Congratulations! The PLAYER "+this.name+" WITH ID "+this.id+" has won !!");
obj.gameCompleteFlag=true;
System.exit(0);
}
}}
}