Skip to content
This repository was archived by the owner on Sep 4, 2023. It is now read-only.

Commit c29e10a

Browse files
committed
Lab 3
1 parent c189e46 commit c29e10a

File tree

86 files changed

+5080
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+5080
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Lab03_toStudent</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
</buildSpec>
9+
<natures>
10+
</natures>
11+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package application;
2+
3+
import java.util.Scanner;
4+
5+
import application.shop.Shop;
6+
import player.Player;
7+
import deck.Deck;
8+
import card.base.*;
9+
import card.type.*;
10+
11+
12+
public class Main {
13+
static Scanner scanner = new Scanner(System.in);
14+
15+
private static void printLineSeparator() {
16+
System.out.println("==================================================");
17+
}
18+
19+
private static void printDeckList(Deck deck) {
20+
int cardsNumber = 0;
21+
for (Card card : deck.getDeckList()) {
22+
if(card != null) {
23+
cardsNumber += 1;
24+
}
25+
}
26+
System.out.println("Deck count (" + cardsNumber + "/" + deck.getDeckSize() + ")");
27+
int index = 1;
28+
for (Card card : deck.getDeckList()) {
29+
if(card != null) {
30+
System.out.println(index + ": " + card.toString());
31+
index += 1;
32+
}
33+
}
34+
}
35+
36+
public static void main(String[] args) {
37+
printLineSeparator();
38+
System.out.println("============ YugiUno: Card Shop =========");
39+
printLineSeparator();
40+
41+
Player player = new Player("Player");
42+
Player opponent = new Player("Opponent");
43+
44+
Deck deck = new PlayerSelection(System.out, scanner).runDeckSelection();
45+
player.setDeck(deck);
46+
System.out.println("Selected " + deck.getName());
47+
printLineSeparator();
48+
49+
System.out.println("Entering card shop");
50+
new Shop(System.out, scanner, player).run();
51+
52+
printLineSeparator();
53+
/*System.out.println("Final stats: ");
54+
System.out.println(player.toString());
55+
printDeckList(player.getDeck());
56+
printLineSeparator();
57+
58+
System.out.println(player.getName() + " : It's time to DueDue Due Due DDDDDDDDDDD DUEL!!");*/
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package application;
2+
3+
import java.io.PrintStream;
4+
import java.util.Scanner;
5+
6+
import player.Player;
7+
import deck.Deck;
8+
import deck.PremadeDeck;
9+
10+
public class PlayerSelection extends ShopApp {
11+
public PlayerSelection(PrintStream out, Scanner in) {
12+
super(out, in);
13+
}
14+
15+
public Deck runDeckSelection() {
16+
int choice;
17+
out.println("Select your Deck: ");
18+
choice = this.getChoice(1, PremadeDeck.premadeDecks.length, () -> this.printDecks(), index -> PremadeDeck.premadeDecks[index-1].getName());
19+
20+
return PremadeDeck.premadeDecks[choice - 1];
21+
}
22+
public Deck runOpponentDeckSelection() {
23+
int choice;
24+
out.println("Select your opponent's Deck: ");
25+
choice = this.getChoice(1, PremadeDeck.premadeDecks.length, () -> this.printDecks(), index -> PremadeDeck.premadeDecks[index-1].getName());
26+
27+
return PremadeDeck.premadeDecks[choice - 1];
28+
}
29+
30+
private void printDecks() {
31+
int index = 1;
32+
for (Deck deck : PremadeDeck.premadeDecks) {
33+
out.println(index + ": " + deck.toString());
34+
index += 1;
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package application;
2+
3+
import java.io.PrintStream;
4+
import java.util.List;
5+
import java.util.Scanner;
6+
7+
import application.base.CLIApp;
8+
import card.base.Card;
9+
import deck.Deck;
10+
11+
public class ShopApp extends CLIApp {
12+
public ShopApp(PrintStream out, Scanner in) {
13+
super(out, in);
14+
}
15+
16+
public Card getCardChoice(List<Card> cards, Runnable prompt) {
17+
int choice = getChoice(1, cards.size(), prompt);
18+
return cards.get(choice - 1);
19+
}
20+
21+
public Card getCardChoice(Card[] cards, Runnable prompt) {
22+
int choice = getChoice(1, cards.length, prompt);
23+
return cards[choice - 1];
24+
}
25+
26+
public Deck getDeckChoice(List<Deck> decks, Runnable prompt) {
27+
int choice = getChoice(1, decks.size(), prompt);
28+
return decks.get(choice - 1);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package application.base;
2+
3+
import java.io.PrintStream;
4+
import java.util.Scanner;
5+
import java.util.function.Function;
6+
7+
public class CLIApp {
8+
9+
protected PrintStream out;
10+
protected Scanner in;
11+
12+
public CLIApp(PrintStream out, Scanner in) {
13+
this.out = out;
14+
this.in = in;
15+
}
16+
17+
protected int getChoice(int minChoice, int maxChoice, Runnable prompt) {
18+
return getChoice(minChoice, maxChoice, prompt, n -> n.toString());
19+
}
20+
21+
protected int getChoice(int minChoice, int maxChoice, boolean ensureSelection, Runnable prompt) {
22+
return getChoice(minChoice, maxChoice, ensureSelection, prompt, n -> n.toString());
23+
}
24+
25+
protected int getChoice(int minChoice, int maxChoice, Runnable prompt, Function<Integer, String> choiceNameFn) {
26+
return getChoice(minChoice, maxChoice, true, prompt, choiceNameFn);
27+
}
28+
29+
protected int getChoice(int minChoice, int maxChoice, boolean ensureSelection, Runnable prompt, Function<Integer, String> choiceNameFn) {
30+
while(true) {
31+
prompt.run();
32+
int choice = in.nextInt();
33+
if (minChoice <= choice && choice <= maxChoice) {
34+
if(!ensureSelection) {
35+
return choice;
36+
}
37+
38+
if(this.ensureSelection(choice, choiceNameFn)) {
39+
return choice;
40+
}
41+
} else {
42+
out.println("Please input number from " + minChoice + " to " + maxChoice + ".");
43+
}
44+
}
45+
}
46+
47+
boolean ensureSelection(int choice) {
48+
return ensureSelection(choice, n -> n.toString());
49+
}
50+
51+
boolean ensureSelection(int choice, Function<Integer, String> choiceNameFn) {
52+
out.println("Select " + choiceNameFn.apply(choice) + " ?(y/n)");
53+
in.nextLine();
54+
while(true) {
55+
char confirm = in.nextLine().toLowerCase().charAt(0);
56+
if(confirm == 'y') {
57+
return true;
58+
} else if (confirm == 'n') {
59+
return false;
60+
} else {
61+
out.println("Please input y or n");
62+
}
63+
}
64+
}
65+
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package application.shop;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.io.PrintStream;
6+
import java.util.Scanner;
7+
8+
import application.ShopApp;
9+
import application.shop.actions.PlayTest;
10+
import application.shop.actions.ForgeCard;
11+
import application.shop.actions.InsertCard;
12+
import application.shop.actions.RemoveCard;
13+
import application.shop.actions.ReviewDeckList;
14+
import application.shop.actions.ChangeToPremadeDeck;
15+
import deck.PremadeDeck;
16+
17+
import card.base.Card;
18+
19+
import player.Player;
20+
21+
public class Shop extends ShopApp {
22+
Player player;
23+
List<Card> cards;
24+
25+
public Shop(PrintStream out, Scanner in, Player player) {
26+
super(out, in);
27+
this.player = player;
28+
this.cards = PremadeDeck.initialCardStock;
29+
}
30+
31+
public void run() {
32+
while(true) {
33+
int choice = this.getChoice(1, 6, false, () -> this.prompt());
34+
switch(choice) {
35+
case 1:
36+
Card toAdd = new ForgeCard(this.out, this.in).runForge();
37+
if(toAdd != null) {
38+
cards.add(toAdd);
39+
}
40+
break;
41+
case 2:
42+
new InsertCard(this.out, this.in, this.player, this.cards).run();
43+
out.println("Insert Card Done");
44+
break;
45+
case 3:
46+
new RemoveCard(this.out, this.in, this.player, this.cards).run();
47+
out.println("Remove Card Done");
48+
break;
49+
case 4:
50+
new ReviewDeckList(this.out, this.in, this.player, this.cards).run();
51+
break;
52+
case 5:
53+
new ChangeToPremadeDeck(this.out, this.in, this.player).run();
54+
55+
break;
56+
case 6:
57+
new PlayTest(this.out, this.in, this.player).run();
58+
return;
59+
}
60+
}
61+
}
62+
63+
public void prompt() {
64+
out.println("Select action :");
65+
out.println("1: Create new Card");
66+
out.println("2: Insert card to " + player.getDeck().getName() + " deck");
67+
out.println("3: Remove card from " + player.getDeck().getName() + " deck");
68+
out.println("4: Review Deck list");
69+
out.println("5: Change to premade deck");
70+
out.println("6: Begin the game");
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package application.shop.actions;
2+
3+
import java.io.PrintStream;
4+
import java.util.Scanner;
5+
6+
import application.ShopApp;
7+
import deck.Deck;
8+
import deck.PremadeDeck;
9+
import player.Player;
10+
11+
public class ChangeToPremadeDeck extends ShopApp {
12+
private Player player;
13+
14+
15+
public ChangeToPremadeDeck(PrintStream out, Scanner in, Player player) {
16+
super(out, in);
17+
out.println("Select Premade Deck");
18+
this.player = player;
19+
}
20+
21+
public void run() {
22+
int choice;
23+
out.println("Select deck: ");
24+
choice = this.getChoice(1, PremadeDeck.premadeDecks.length, () -> this.prompt(), index -> PremadeDeck.premadeDecks[index-1].getName());
25+
player.setDeck(PremadeDeck.premadeDecks[choice - 1]);
26+
out.println(player.getName() + " change his deck to " + player.getDeck().getName() + " premade deck");
27+
}
28+
29+
public void prompt() {
30+
out.println("Select premade deck");
31+
int index = 1;
32+
for (Deck deck : PremadeDeck.premadeDecks) {
33+
out.println(index + ": " + deck.toString());
34+
index += 1;
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package application.shop.actions;
2+
3+
import java.io.PrintStream;
4+
import java.util.Scanner;
5+
6+
import application.ShopApp;
7+
import application.shop.actions.forge.*;
8+
9+
import card.base.*;
10+
11+
12+
public class ForgeCard extends ShopApp {
13+
14+
public ForgeCard(PrintStream out, Scanner in) {
15+
super(out, in);
16+
out.println("Forging new card");
17+
}
18+
19+
public Card runForge() {
20+
int choice = this.getChoice(1, 7, false, () -> this.promptItemType());
21+
switch (choice) {
22+
case 1:
23+
return new ForgeNormalUnitCard(this.out, this.in).runForge();
24+
case 2:
25+
return new ForgeDebuffUnitCard(this.out, this.in).runForge();
26+
case 3:
27+
return new ForgeLeaderUnitCard(this.out, this.in).runForge();
28+
case 4:
29+
return new ForgeVenomUnitCard(this.out, this.in).runForge();
30+
case 5:
31+
return new ForgeBuffSpellCard(this.out, this.in).runForge();
32+
case 6:
33+
return new ForgeDamageSpellCard(this.out, this.in).runForge();
34+
case 7:
35+
return null;
36+
}
37+
return null;
38+
}
39+
40+
public void promptItemType() {
41+
out.println("Select card to crate :");
42+
out.println("1: Leader Unit Card");
43+
out.println("2: Debuff Unit Card");
44+
out.println("3: Overwhelm Unit Card");
45+
out.println("4: Venom Unit Card");
46+
out.println("5: Overwhelm Unit Card");
47+
out.println("6: Venom Unit Card");
48+
out.println("7: Cancel");
49+
}
50+
}

0 commit comments

Comments
 (0)