-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
82 lines (72 loc) · 2.68 KB
/
Game.java
File metadata and controls
82 lines (72 loc) · 2.68 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
import java.util.Scanner;
import java.util.Random;
public class Game {
private final BingoCard[] cards;
private final WinningPattern patterns;
private final Random rand;
private final Scanner sc;
public Game(BingoCard[] cards, WinningPattern patterns, Random rand, Scanner sc) {
this.cards = cards;
this.patterns = patterns;
this.rand = rand;
this.sc = sc;
}
// Main game loop
public int play() {
int drawCount = 0;
int score = 0;
int drawingLimit = (cards.length*(25)); //all spaces in card has chance
while (drawCount < drawingLimit) {
//random num between 1 and 75
int drawnNumber = rand.nextInt(75) + 1;
boolean bingo = false;
drawCount++;
System.out.print("\033[H\033[2J");
System.out.flush();
char letter = ' ';
if (drawnNumber <= 15) {
letter = 'B';
} else if (drawnNumber <= 30) {
letter = 'I';
} else if (drawnNumber <= 45) {
letter = 'N';
} else if (drawnNumber <= 60) {
letter = 'G';
} else {
letter = 'O';
}
System.out.println("\nDraw #"+drawCount+"/"+drawingLimit+
": "+ letter + ":" + drawnNumber +"\n");
for (int i = 0; i < cards.length; i++) {
cards[i].markNumber(drawnNumber);
}
Main.printBingoCards(cards);
for (int i = 0; i < cards.length; i++) {
score = patterns.checkPatterns(cards[i]);
if(score > 0) break; //first card from the Left to Bingo
}
System.out.print("\nTimer:");
for(int i = 0; i < 3; i++){
System.out.printf(" *",(i+1));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println();
if (score == 0 && drawCount == drawingLimit){
System.out.printf("You failed %d draws!", drawingLimit);
System.out.print("\n\nPress Enter for new game...");
sc.nextLine();
return score = 5;
}else if (score > 0){
System.out.printf("Bingo! +%d Coins", score);
System.out.print("\n\nPress Enter for new game...");
sc.nextLine();
return score;
}
}
return score;
}
}