forked from DHEERAJHARODE/Hacktoberfest2024-Open-source-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonopoly_banker.go
426 lines (388 loc) · 11.3 KB
/
monopoly_banker.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
package main
import (
"fmt"
"os"
"os/exec"
"runtime"
)
var clear map[string]func() //create a map for storing clear funcs
var username [5]string
var balance [5]float32
var house [5] int
var hotels [5] int
var value [5] float32
var choice int
func init() {
clear = make(map[string]func()) //Initialize it
clear["linux"] = func() {
cmd := exec.Command("clear") //Linux example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
clear["windows"] = func() {
cmd := exec.Command("cmd", "/c", "cls") //Windows example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
}
func CallClear() {
value, ok := clear[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc.
if ok { //if we defined a clear func for that platform:
value() //we execute it
} else { //unsupported platform
panic("Your platform is unsupported! I can't clear terminal screen :(")
}
}
func Startup() {
for count := 1; count <= 4; count++ {
fmt.Print("Enter the ")
fmt.Print(count)
fmt.Println(" Name :")
fmt.Scanln(&username[count])
CallClear()
}
for count := 1; count <= 4; count++ {
balance[count] = 1500
}
}
func PrintBalance() {
fmt.Println("No. Name Balance House Hotels Value")
fmt.Println(" ")
for count := 1; count <= 4; count++ {
fmt.Println("______________________________________________________________________________________________")
fmt.Println(" ")
fmt.Print(count)
fmt.Print(" ")
fmt.Print(username[count])
fmt.Print(" ")
fmt.Print(balance[count])
fmt.Print(" ")
fmt.Print(house[count])
fmt.Print(" ")
fmt.Print(hotels[count])
fmt.Print(" ")
fmt.Print(value[count])
fmt.Println(" ")
}
fmt.Println("______________________________________________________________________________________________")
}
func PrintMenu() {
fmt.Println(" ")
fmt.Println(" Which operation you wanna perform?")
fmt.Println(" _______________________________________________________")
fmt.Println(" ")
fmt.Println(" 1. Inc/Dec balance 5. Birthday Party")
fmt.Println(" ")
fmt.Println(" 2. Manage houses 6. Salaray or gifts")
fmt.Println(" ")
fmt.Println(" 3. Transfer Balance 7. Taxes and fine")
fmt.Println(" ")
fmt.Println(" 4. Increase 10% 8. House repair")
fmt.Println(" ")
fmt.Println(" _________________________________________________________")
fmt.Println(" ")
//fmt.Println(" 4. It is some one birthday")
fmt.Scanln(&choice)
}
func PerformAction() {
switch choice {
case 1:
BankTrans()
case 2:
Houses()
case 3:
NormTrans()
case 4:
Inc10()
case 5:
BirthDay()
case 6:
General(1)
case 7:
General(2)
case 8:
Repairs()
default:
fmt.Println("try again")
fmt.Scanln()
}
}
func BankTrans() {
var amount float32
var act int
fmt.Println(" Increase or decrease")
fmt.Println(" _________________________________")
fmt.Println(" ")
fmt.Scanln(&act)
fmt.Println(" By how much")
fmt.Println(" _________________________________")
fmt.Println(" ")
fmt.Scanln(&amount)
Modify(act, amount)
}
func Houses(){
var action int
var amount float32
var act int
fmt.Println(" What do you wanna do?")
fmt.Println(" _________________________________")
fmt.Println(" ")
fmt.Println(" 1. Buy a House 2.Sell a House ")
fmt.Println(" ")
fmt.Println(" 3. Buy a Hotel 4.Sell a Hotel ")
fmt.Println(" ")
fmt.Println(" 5. Transfer a House ")
fmt.Scanln(&act)
switch act{
case 1:
fmt.Println(" What is the price?")
fmt.Scanln(&amount)
fmt.Println(" On which person")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action)
if action > 0 && action < 5 {
break
}
}
balance[action] = balance[action] - amount
value[action] = value[action] + amount
house[action]++
case 2:
fmt.Println(" What is the price?")
fmt.Scanln(&amount)
fmt.Println(" On which person")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action)
if action > 0 && action < 5 {
break
}
}
balance[action] = balance[action] + amount
value[action] = value[action] - amount
house[action]--
case 3:
fmt.Println(" What is the price?")
fmt.Scanln(&amount)
fmt.Println(" On which person")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action)
if action > 0 && action < 5 {
break
}
}
balance[action] = balance[action] - amount
value[action] = value[action] + amount
hotels[action]++
case 4:
fmt.Println(" What is the price?")
fmt.Scanln(&amount)
fmt.Println(" On which person")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action)
if action > 0 && action < 5 {
break
}
}
balance[action] = balance[action] + amount
value[action] = value[action] - amount
hotels[action]--
case 5:
HouseTrans()
default:
fmt.Println(" try again")
fmt.Scanln()
}
}
func HouseTrans() {
var action [2]int
var amount float32
fmt.Println(" From")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action[0])
if action[0] > 0 && action[0] < 5 {
break
}
}
fmt.Println(" ")
fmt.Println(" To")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action[1])
if action[1] > 0 && action[1] < 5 {
break
}
}
fmt.Println(" ")
fmt.Println(" By how much")
fmt.Println(" _________________________________")
fmt.Println(" ")
fmt.Scanln(&amount)
balance[action[0]] = balance[action[0]] + amount
balance[action[1]] = balance[action[1]] - amount
value[action[0]] = value[action[0]] - amount
value[action[1]] = value[action[1]] + amount
house[action[1]]++
house[action[0]]--
}
func NormTrans() {
var action [2]int
var amount float32
fmt.Println(" From")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action[0])
if action[0] > 0 && action[0] < 5 {
break
}
}
fmt.Println(" ")
fmt.Println(" To")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action[1])
if action[1] > 0 && action[1] < 5 {
break
}
}
fmt.Println(" ")
fmt.Println(" By how much")
fmt.Println(" _________________________________")
fmt.Println(" ")
fmt.Scanln(&amount)
balance[action[0]] = balance[action[0]] - amount
balance[action[1]] = balance[action[1]] + amount
}
func Inc10() {
var action int
fmt.Println(" On which person")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action)
if action > 0 && action < 5 {
break
}
}
balance[action] = balance[action] * 1.1
}
func General(act int) {
var amount float32
var action int
fmt.Println(" Which Amount?")
fmt.Println(" _________________________________")
fmt.Println(" ")
fmt.Println(" 1. $10 2.$15 3.$20")
fmt.Println(" ")
fmt.Println(" 4. $50 5.$100 6.$150")
fmt.Println(" ")
fmt.Println(" 7. $200")
fmt.Println(" ")
fmt.Scanln(&action)
switch action {
case 1:
amount = 10
case 2:
amount = 15
case 3:
amount = 20
case 4:
amount = 50
case 5:
amount = 100
case 6:
amount = 150
case 7:
amount = 200
default:
fmt.Println(" try again")
fmt.Scanln()
}
Modify(act, amount)
}
func BirthDay() {
var action int
fmt.Println(" Whose birthday is it?")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action)
if action > 0 && action < 5 {
break
}
}
for count := 1; count <= 4; count++ {
balance[count] = balance[count] - 10
}
balance[action] = balance[action] + 40
}
func Modify(act int, amount float32) {
var action int
fmt.Println(" On which person")
fmt.Println(" _________________________________")
fmt.Println(" ")
for {
fmt.Scanln(&action)
if action > 0 && action < 5 {
break
}
}
if act == 1 {
balance[action] = balance[action] + amount
} else if act == 2 {
balance[action] = balance[action] - amount
} else {
fmt.Println("try again!")
}
}
func Repairs(){
var action int
var amount int
var houses[5] int
var hotels[5] int
fmt.Println(" Which type of repairs ?")
fmt.Println(" ________________________________")
fmt.Println(" ")
fmt.Println(" 1. major 2.minor")
fmt.Println(" ")
fmt.Scanln(&action)
fmt.Println(" Houses ?")
fmt.Println(" ________________________________")
fmt.Println(" ")
fmt.Scanln(&houses[0])
fmt.Println(" Hotels ?")
fmt.Println(" ________________________________")
fmt.Println(" ")
fmt.Scanln(&hotels[0])
switch action {
case 1:
amount = (houses[0]*40) + (hotels[0]*115)
case 2:
amount = (houses[0]*25) + (hotels[0]*100)
default:
fmt.Println(" try again")
fmt.Scanln()
}
Modify(2,float32(amount))
}
func main() {
Startup()
for count := 0; count <= 1111; count++ {
CallClear()
PrintBalance()
PrintMenu()
PerformAction()
}
}