0
我正在研究一種主要利用C++和Javascript的基於3D學習的遊戲。我試圖設計一個通知系統,當玩家將信息發送到他們的筆記本時。如何在遊戲中設置通知系統
我建立了一個系統,但是主管認爲它可以做得更好。這是我需要你們幫忙的地方!
非常基本的方式,去:
玩家會做一些觸發信息發送到筆記本電腦。在發生這種情況的相同方法中,我打開了通知。通知會通過閃爍兩個div的圖像(閃爍效果)顯示在玩家的屏幕上。當其中任一個div被點擊時,它向玩家顯示筆記本。任何時候玩家查看或退出筆記本,通知都會關閉。
現在,這裏是我使用的代碼:
在主遊戲狀態
int GameModeState::notify(int query)
{
static int notified;
if(query == 1)
{
notified = 1;
return notified;
}
if(query == 2)
{
notified = 0;
return notified;
}
else
{
return notified;
}
}
在遊戲狀態的更新功能
// checks if the unviewed information notification needs to be on or off
if(notify(0) == 1) // supposed to be on
{
mScreen->executeJavascript("notebookNotification(1);"); // turns it on
} else {
int nothing = notify(2); // clears out notify to 0
mScreen->executeJavascript("notebookNotification(0);"); // turns it off
}
在我的JS
var intervalID; // Needed to turn off setInterval()
//Function takes in 0 to turn off notification, anything else turns it on
function notebookNotification(setting)
{
if(setting == 0)
{
if(intervalID) {
// clears the blinking darkContainer
window.clearInterval(intervalID);
intervalID = null;
}
// hides both of the images
$("#lightNotificationContainer").hide();
$("#darkNotificationContainer").hide();
}
else
{
$("#lightNotificationContainer").show();
if(!intervalID) {
// "animates" the blinking of the notification; the darkContainer toggles on and off every second, and covers the lightContainer
intervalID = window.setInterval('$("#darkNotificationContainer").toggle()', 1000);
}
}
}
我會轉關閉使用GameModeState::notify(2)
現在,什麼是更好的系統使用,而不是這個?
究竟什麼不主管認爲可以做的更好?我們在談論性能,視覺效果,可讀性代碼結構,什麼? –
@Levi Morrison:部分性能,部分代碼結構。它只是沒有以最好的方式建立。 – Briz
當然,它有效,但它可能會更好。如果我知道一個更好的方法,我不會問經驗豐富的編碼員對此有所幫助。 – Briz