我正在尝试用C ++制作一个Snake游戏。我正在使用ncurses包进行键输入,我知道我需要将initscr()放在某处以启用键输入,但我不知道在哪里。我尝试了主要方法的顶部,但这导致了显示器的意外问题。我也尝试将它放在Input()方法中,但这也成为显示器的问题。我不知道把它放在哪里,或者我是否需要添加其他东西以使其有效,但有人可以帮助我吗?
return Component.extend({
defaults: {
template: 'Icube_Snap/payment/snap'
},
redirectAfterPlaceOrder: false,
afterPlaceOrder: function() {
$.getScript(js, function() {
$.ajax({
type: 'post',
url: url.build('snap/payment/redirect'),
cache: false,
success: function(data) {
var token = data;
var methods = [];
var methodSnap = $('input[name=snap-method]:checked').val();
//Define a function to send the POST request here.
//////////////////////////////////////////////////
var sendPayment = function(param, successcallback, errorcallback) {
$.ajax({ // <-- this ajax needs to be inside function with parameter
type: 'post',
url: url.build('custom/message/post'),
cache: false,
param: {
id: param.id,
message: param.message
}
success: function(data) {
successcallback(data);
},
error: function(error) {
errorcallback(error);
}
});
};
snap.pay(token, {
enabledPayments: methods,
onSuccess: function(result) {
//Call sendPayment method and you can
//pass whatever you want.
sendPayment(result, function() {
//Call when success
}, function() {
//Call when error
});
},
onPending: function(result) {
sendPayment(result, function() {
//Call when success
}, function() {
//Call when error
});
},
onError: function(result) {
sendPayment(result, function() {
//Call when success
}, function() {
//Call when error
});
},
onClose: function() {
sendPayment(result, function() {
//Call when success
}, function() {
//Call when error
});
}
});
}
});
});
}
});
答案 0 :(得分:0)
initscr
应该被称为&#34;早期&#34; (在任何I / O之前)。但是,您的示例显示混合getch
(可能是curses,可能是conio)和stdio(除非您刷新输出,然后切换到curses,否则它将无法工作)
int main() {
initscr(); // this
Setup();
while(!gameOver) {
Draw();
Input();
Logic();
}
endwin(); // and this
return 0;
}