-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCODEE
141 lines (141 loc) · 3.38 KB
/
CODEE
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import java.util.*;
class tictac
{
public static void main(String at[])throws Exception
{
Scanner sc=new Scanner(System.in);
int c,r,x,i,ch,r1,c1,k,j,h=0,r2=0,n,e=0,f=0,p=0,q=0,z=0,k2=0;
for(x=1;x<=18;x++)
{
System.out.print(" ");
System.out.println(" ");
}
System.out.println(" ");
Thread.sleep(76);
System.out.println(" # # ###### # ###### ###### ## ## ###### ");
Thread.sleep(76);
System.out.println(" # # # # # # # # # # # # ");
Thread.sleep(76);
System.out.println(" # # # #### # # # # # # # #### ");
Thread.sleep(76);
System.out.println(" # # # # # # # # # # # # ");
Thread.sleep(76);
System.out.println(" # # ###### ####### ###### ###### # # ###### ");
Thread.sleep(76);
System.out.println(" ");
Thread.sleep(1000);
for(i=1;i<=20;i++)
{
System.out.println(" ");
Thread.sleep(75);
}
System.out.println(" ....INSTRUCTIONS......"+"\n"+" * Take turns to play the game"+"\n"+" * For player1 use @, for player2 use #"+"\n"+" * Do not choose the spaces which are already filled"+"\n"+" * First one to complete the number of symbols as given is the winner"+"\n");
Thread.sleep(800);
for(i=1;i<=20;i++)
{
System.out.println(" ");
Thread.sleep(75);
}
System.out.println(" LET'S START<<<<<<<<<"+"\n");
Thread.sleep(1000);
System.out.println(" ");
System.out.println("enter no of rows and columns");
r=sc.nextInt();
c=sc.nextInt();
char t[][]=new char[r][c];
System.out.println(" ");
System.out.println("enter number of crosses");
x=sc.nextInt();
System.out.println(" ");
n=c;
System.out.println("enter choice(1-player1,2-player2)");
ch=sc.nextInt();
lb:for(k=1;k>=0;k++)
{
switch(ch)
{
case 1:
System.out.println("enter rows and columns by player 1");
r1=sc.nextInt();
c1=sc.nextInt();
t[r1][c1]='@';
for(i=0;i<r;i++)
{
if(t[i][c1]=='@') //rows
e++;
else
e=0;
for(j=0;j<c;j++)
{
if(t[r1][j]=='@') //column
h++;
else
h=0;
if(i==j) //right diagonal
{
if(t[i][j]=='@')
f++;
else
f=0;
}
if((i+j)==(n-1)) //left diagonal
{
if(t[i][j]=='@')
z++;
else
z=0;
}
System.out.print(t[i][j]+"|");
}
System.out.println();
if(h==x || e==x || f==x || z==x)
{
System.out.println("PLAYER1 WINS");
break lb;
}
}
case 2:
System.out.println("enter rows and columns by player 2");
r1=sc.nextInt();
c1=sc.nextInt();
//if(t[r1][c1]==' ')
t[r1][c1]='#';
for(i=0;i<r;i++)
{
if(t[i][c1]=='#')
p++;
else
p=0;
for(j=0;j<c;j++)
{
if(t[r1][j]=='#')
q++;
else
q=0;
if(i==j)
{
if(t[i][j]=='#')
r2++;
else
r2=0;
}
if((i+j)==(n-1))
{
if(t[i][j]=='#')
k2++;
else
k2=0;
}
System.out.print(t[i][j]+"|");
}
System.out.println();
if(p==x || q==x || r2==x || k2==x)
{
System.out.println("player2 wins");
break lb;
}
}
}
}
}
}