forked from ASD-ADF/ASD_Task_4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.cpp
More file actions
110 lines (96 loc) · 2.56 KB
/
player.cpp
File metadata and controls
110 lines (96 loc) · 2.56 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
#include "player.h"
#include <ctime>
int randomInt(int max_int) {
/** YOU DON'T NEED TO MODIFY THIS */
srand(time(NULL));
return (rand() % max_int) + 1;
}
void printInfo(List L) {
/**
* PR : menampilkan informasi ID, nama, dan lokasi file
* YOU DON'T NEED TO MODIFY THIS
*/
address Q = first(L);
do {
cout<<"name : "<<info(Q).name<<endl
<<"ID : "<<info(Q).ID<<endl
<<"location: "<<info(Q).location<<endl;
Q = next(Q);
} while(Q!=first(L));
cout<<"==============================================="<<endl;
}
void playMusic(address P) {
/**
* PR : memainkan lagu yang ditunjuk oleh pointer P
* YOU DON'T NEED TO MODIFY THIS
*/
string filename = info(P).location+"/"+info(P).name;
cout<<"playing "<<filename<<endl;
PlaySound(TEXT(filename.c_str()), NULL, SND_FILENAME);
_sleep(500); //delay 0.5 second
}
void shuffleList(List &L) {
/**
* PR : mengacak isi (elemen) dari list L
* FS : isi (elemen) dari list teracak
*/
//------------- YOUR CODE HERE -------------
address P;
P=first(L);
int i=0;
int j=randomInt(i);
while (P!=first(L)) {
i++;
P=next(P);
}
while (i>0) {
P=first(L);
while (j!=0){
P=next(P);
j--;
}
address Prec=P;
deleteAfter(L, prev(P), Prec);
insertFirst(L, Prec);
i--;
}
cout<<"UNDER MAIN TENIS"<<endl;
//----------------------------------------
}
void playRepeat(List &L, int n) {
/**
* PR : memainkan seluruh lagu di dalam list
* dari lagu pertama hingga terakhir sebanyak n kali
*/
//------------- YOUR CODE HERE -------------
address P;
int i=0;
P=first(L);
while (i<n) {
i++;
while (P!=first(L)) {
P=next(P);
playMusic(P);
}
}
cout<<"UNDER MAIN TENIS"<<endl;
//----------------------------------------
}
void deleteMusicByID(List &L, infotype x) {
/**
* IS : list L mungkin kosong
* PR : menerima input user untuk ID lagu yang ingin dihapus
* jika ID lagu ditemukan, hapus (deallocate) lagu dari list
* FS : elemen dengan ID yang dicari dideallocate
*/
//------------- YOUR CODE HERE -------------
address P;
if (first(L)!=NULL) {
if (findElmByID(L, x) != NULL){
deleteAfter(L, prev(findElmByID(L, x)), P);
deallocate(P);
}
}
cout<<"UNDER MAIN TENIS"<<endl;
//----------------------------------------
}