-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
123 lines (96 loc) · 3.97 KB
/
Main.java
File metadata and controls
123 lines (96 loc) · 3.97 KB
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input;
input = new Scanner(System.in);
//some variables
int row = 0;
int col = 0;
String rowLetter;
int i = 0;
int points = 0;
int tmp = 10, tmp2, choice;
boolean exit = false;
//initialization the object
TicTacToe game1 = new TicTacToe();
while(!exit){
System.out.println("Insert 1 to start a game");
System.out.println("Insert 0 to exit");
System.out.print("Insert your choice: ");
choice = input. nextInt();
System.out.println("\n\n\n\n\n\n\n\n\n\n\n");
switch (choice){
case 0:
exit = true;
System.out.println("Godbye");
break;
case 1:
//print start table
game1.tableReset();
System.out.println("GAME START");
System.out.println(game1.toString());
while(tmp != 2 && tmp != 4){
System.out.println("");
System.out.print("Insert the row: ");
input = new Scanner(System.in);
rowLetter = input.nextLine();
switch(rowLetter){
case "a":
row = 0;
break;
case "A":
row = 0;
break;
case "b":
row = 1;
break;
case "B":
row = 1;
break;
case "c":
row = 2;
break;
case "C":
row = 2;
break;
}
System.out.print("Insert the column: ");
input = new Scanner(System.in);
col = input.nextInt();
col--;
System.out.println("\n");
tmp = game1.playerInput(row, col);
switch(tmp){
case 2:
System.out.println("You Win ;)");
points++;
System.out.println("Your points :"+ points);
break;
case 0:
System.out.println ("Your move was not inserted in the table");
break;
case 1:
tmp = game1.computerMove();
System.out.println("Your turn");
System.out.println(game1.toString());
switch (tmp){
case 4:
System.out.print("\n");
System.out.println ("The table is full");
System.out.println("Tie");
break;
case 2:
System.out.print("\n");
System.out.println("The computer has Win ;(");
System.out.println("Your points : "+ points);
break;
}
}
}
}
tmp = 10; //reset tmp
System.out.print("\n\n\n");
}
}
}
//Eric Cristelli