所以我刚开始学习基础知识,我尝试对一个数字做出响应,但它给了我第10行和第13行的“std ::”绑定错误。 这是代码(P.S我认为最后一个大括号留下了):
var players = {};
var rooms = {};
rooms['randomId236512'] = {// add an example starter room
id: 'randomId236512',
name: 'Happy Box House Room',
players: [],
started: false,
setCount: 0
};
function findOpenRoom() {
//here you would search through the list of games waiting for players
//if no rooms, make one, add it to the list, then return it
return rooms[0];
}
io.on('connection', function (socket) {
var newPlayer = {//A better pratice would be create a "class" or new function for the Player object
name: 'Mr. Jones',
color: 'blue',
currentRoom: null,
requestedSets: [],//or could just be NumRequestedSets
//Whatever additional game related data could go here
//Alternately, if the data is specific to the whole game, put it on the room itself
};
players[socket.id] = newPlayer;//Adding this to the players dictionary will let us find the player object again via their socket id
var openRoom = findOpenRoom();
newPlayer.currentRoom = openRoom; //Now the player object has a reference to the game room it's in
openRoom.players.push(newPlayer);
socket.join(openRoom.id);//This will create a new socket.io channel to make it easy to emit to a single room
socket.on('startGame', function (socketId, msg) {
var myRoom = players[socketId].currentRoom;
myRoom.started = true;
myRoom.setCount = 0;//Ensure 0 at start
//Broadcast the startGame message here, see below for building gamestate
});
socket.on('requestSet', function (socketId, msg) {
sendSetOfBoxes(players[socketId]);//Respond to the message here, update the requested set number or whatever
var gameState = {
playerData: []
};
var myRoom = players[socketId].currentRoom;
for (var i = 0; i < myRoom.players.length; i++) {
//Loop over the players, and build a list of players and their history of requested sets
gameState.playerData.push({
name: myRoom.players[i].name,
requestedSetHistory: myRoom.player[i].requestedSets
})
}
socket.broadcast.to(myRoom.id).emit('setWasRequested', gameState);
});
function sendSetOfBoxes(player) {
//do your sending of boxes here
}
});
答案 0 :(得分:3)
cin >> name >> "\n";
应该是
cin >> name;
在你使用它的两个地方。您无法将输入流发送到字符串文字。