-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientGame2.cpp
More file actions
81 lines (69 loc) · 1.66 KB
/
ClientGame2.cpp
File metadata and controls
81 lines (69 loc) · 1.66 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
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
using namespace std;
class ClientGame2 {
private:
int socket;
//RPC sends here:
const char *EXIT_MENU = "rpc=exitmenu;";
public:
ClientGame2(int socket) {
this->socket = socket;
}
~ClientGame2() {
cout << "Gclient2 destructed" << endl;
}
int getUserChoice()
{
int userChoice;
cin >> userChoice;
return userChoice;
}
// display menu options to the user
void displayGameMenu()
{
cout << "\nGame Options\n";
cout << "\nSelect from the following options\n";
cout << "1 - Disconnect\n";
cout << "2 - Exit menu\n";
// TODO: add game menu/ more options
cout << "\nUser Selection: ";
}
int gameMenu() {
char buffer[1024] = {0};
int choice = 0;
cout << "Entered game" << endl;
do
{
cout << "Buffer in CG2 = " << buffer << endl;
displayGameMenu();
choice = getUserChoice();
switch(choice)
{
case 1: {
return 1;
break;
}
case 2: {
send(socket , EXIT_MENU, strlen(EXIT_MENU) , 0);
cout << "\nExiting menu\n";
// placeholder read
read(socket, buffer, 1024);
cout << "Has read" << endl;
return 2;
}
case 3: {
// you know, whatever.
break;
}
default:
break;
}
} while (true);
return 0;
}
};