-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (71 loc) · 1.73 KB
/
main.go
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
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
d := newDeck()
for true {
fmt.Println("\n\n****************************\n")
fmt.Println("Welcome to Cards Program.")
fmt.Println("\n")
fmt.Println("Current Deck:")
d.print()
fmt.Println("Press 1 to deal")
fmt.Println("Press 2 to shuffle deck")
fmt.Println("Press 3 to save the deck in the file")
fmt.Println("Press 4 to create New Deck from file")
fmt.Println("Press 5 to exit")
fmt.Println("Enter your choice")
var choice int
_, err := fmt.Scanf("%d", &choice)
if err != nil {
fmt.Println("Invalid Input")
}
switch choice {
case 1:
fmt.Println("Enter number of cards you want to draw")
var handSize int
_, err := fmt.Scanf("%d", &handSize)
if err != nil {
fmt.Println("Invalid Input")
}
handCards, remainingCards := deal(d, handSize)
fmt.Println("Hands Cards : ")
handCards.print()
fmt.Println("Remaining Cards : ")
remainingCards.print()
break
case 2:
fmt.Println("Shuffling the deck.")
d.shuffle()
fmt.Println("Shuffled Deck : ")
d.print()
break
case 3:
fmt.Println("Enter the name of the file")
filename, _ := reader.ReadString('\n')
err := d.saveDeckToFile(filename)
if err != nil {
fmt.Println("Problem occured while saving deck to file : ", err)
os.Exit(1)
}
fmt.Println("Deck saved to file successfully")
break
case 4:
fmt.Println("Enter the name of the file")
filename, _ := reader.ReadString('\n')
d = readDeckFromFile(filename)
fmt.Println("Deck from file : ")
d.print()
break
case 5:
fmt.Println("Exiting the program.")
os.Exit(0)
default:
fmt.Println("Invalid Choice, should be between 1 to 5.")
}
}
}