student 2 недель назад
Родитель
Сommit
587734457a

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/data.json


BIN
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/images/shared-0-sheet1.webp


BIN
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/images/shared-0-sheet2.webp


BIN
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/images/shared-0-sheet3.webp


BIN
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/images/shared-0-sheet4.webp


BIN
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/images/shared-0-sheet5.webp


BIN
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/images/shared-0-sheet6.webp


+ 1 - 1
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/offline.json

@@ -1 +1 @@
-{"version":1784640300607,"fileList":["scripts/main.js","scripts/c3runtime.js","scripts/objRefTable.js","scripts/project/main.js","scripts/c3main.js","scripts/dispatchworker.js","scripts/jobworker.js","data.json","scripts/modernjscheck.js","scripts/supportcheck.js","scripts/offlineclient.js","icons/loading-logo.png","icons/icon-16.png","icons/icon-32.png","icons/icon-64.png","icons/icon-128.png","icons/icon-256.png","icons/icon-512.png","media/congratulations.webm","media/click.webm","media/Button03.webm","media/cute-cat-352656.webm","media/win2.webm","media/timeup_.webm","media/click_sound.webm","media/playground.webm","box2d.wasm.js","box2d.wasm","style.css","images/shared-0-sheet0.webp","images/shared-0-sheet1.webp","images/shared-0-sheet2.webp","images/shared-0-sheet3.webp","images/shared-0-sheet4.webp","images/shared-0-sheet5.webp","images/block1a-sheet0.webp","images/block1a-sheet1.webp","images/cats-sheet0.webp","images/cats-sheet1.webp","images/cats-sheet2.webp","images/cats-sheet3.webp","images/cats-sheet4.webp","images/confettix-sheet0.webp","images/confettix-sheet1.webp","images/sprite3-sheet0.webp","images/sprite3-sheet1.webp","images/sprite3-sheet2.webp","images/scroll-sheet0.webp","images/btn_lvl-sheet0.webp","images/btn_lvl-sheet1.webp","scripts/register-sw.js"]}
+{"version":1784652352331,"fileList":["scripts/main.js","scripts/c3runtime.js","scripts/objRefTable.js","scripts/project/main.js","scripts/c3main.js","scripts/dispatchworker.js","scripts/jobworker.js","data.json","scripts/modernjscheck.js","scripts/supportcheck.js","scripts/offlineclient.js","icons/loading-logo.png","icons/icon-16.png","icons/icon-32.png","icons/icon-64.png","icons/icon-128.png","icons/icon-256.png","icons/icon-512.png","media/congratulations.webm","media/click.webm","media/Button03.webm","media/cute-cat-352656.webm","media/win2.webm","media/timeup_.webm","media/click_sound.webm","media/playground.webm","box2d.wasm.js","box2d.wasm","style.css","images/shared-0-sheet0.webp","images/shared-0-sheet1.webp","images/shared-0-sheet2.webp","images/shared-0-sheet3.webp","images/shared-0-sheet4.webp","images/shared-0-sheet5.webp","images/shared-0-sheet6.webp","images/block1a-sheet0.webp","images/block1a-sheet1.webp","images/cats-sheet0.webp","images/cats-sheet1.webp","images/cats-sheet2.webp","images/cats-sheet3.webp","images/cats-sheet4.webp","images/confettix-sheet0.webp","images/confettix-sheet1.webp","images/sprite3-sheet0.webp","images/sprite3-sheet1.webp","images/sprite3-sheet2.webp","images/scroll-sheet0.webp","images/btn_lvl-sheet0.webp","images/btn_lvl-sheet1.webp","scripts/register-sw.js"]}

+ 4 - 1
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/scripts/c3runtime.js

@@ -1703,7 +1703,10 @@ self.C3_ExpressionFuncs = [
 			const v0 = p._GetNode(0).GetVar();
 			return () => (("Ton tai roi nhe: " + v0.GetValue()) + "_unlocked_level");
 		},
-		() => "Lay du lieu ra bi missing",
+		p => {
+			const v0 = p._GetNode(0).GetVar();
+			return () => ("Lay du lieu ra bi missing and set start game type " + v0.GetValue());
+		},
 		p => {
 			const f0 = p._GetNode(0).GetBoundMethod();
 			return () => f0();

+ 6 - 0
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/scripts/objRefTable.js

@@ -179,6 +179,8 @@ self.C3_JsPropNameTable = [
 	{txt: 0},
 	{txtLevelDisplay: 0},
 	{Browser: 0},
+	{txtGiftValues: 0},
+	{txtGiftText: 0},
 	{Physics2: 0},
 	{blocks: 0},
 	{match: 0},
@@ -205,6 +207,8 @@ self.C3_JsPropNameTable = [
 	{data: 0},
 	{exitGame: 0},
 	{score: 0},
+	{gGiftValues: 0},
+	{gGiftText: 0},
 	{isShowComplete: 0},
 	{touchX: 0},
 	{touchY: 0},
@@ -263,5 +267,7 @@ self.InstanceType = {
 	txt: class extends self.ITextInstance {},
 	txtLevelDisplay: class extends self.ITextInstance {},
 	Browser: class extends self.IInstance {},
+	txtGiftValues: class extends self.ITextInstance {},
+	txtGiftText: class extends self.ITextInstance {},
 	blocks: class extends self.ISpriteInstance {}
 }

+ 146 - 116
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/catpuzzle/scripts/project/main.js

@@ -3,8 +3,6 @@
 let levelSending = false;
 let gameOverSending = false;
 let lastExitGame=false;
-let exitSending = false;
-let exitTimeoutId = 0;
 
 let lastLevelCompleted = 0;
 let lastGameOver = 0;
@@ -24,6 +22,9 @@ async function OnBeforeProjectStart(runtime)
 {
 	console.log("Construct3 Started");
 
+	// 1. Lấy gameType từ URL
+	LoadGameConfigFromUrl(runtime);
+
 	// Nhận dữ liệu từ MVC
 	window.addEventListener(
 		"message",
@@ -51,6 +52,97 @@ async function OnBeforeProjectStart(runtime)
 
 }
 
+
+
+function LoadGameConfigFromUrl(runtime)
+{
+	try
+	{
+		const params = new URLSearchParams(
+			window.location.search
+		);
+
+		const gameType =
+			params.get("gameType");
+
+
+		if (gameType)
+		{
+			runtime.globalVars.gameType = gameType;
+		}
+		else
+		{
+			runtime.globalVars.gameType = "Easy";
+		}
+		runtime.globalVars.InitGameTypeSuccess =1;
+
+		// Sau khi có gameType thì set cấu hình game
+		SetGameConfig(runtime);
+
+
+		console.log(
+			"GameType:",
+			runtime.globalVars.gameType,
+			"TotalTime:",
+			runtime.globalVars.totaltime
+		);
+
+	}
+	catch(error)
+	{
+		console.error(
+			"LoadGameConfigFromUrl Error:",
+			error
+		);
+
+		runtime.globalVars.gameType = "Easy";
+
+		SetGameConfig(runtime);
+	}
+}
+
+
+function SetGameConfig(runtime)
+{
+	switch(runtime.globalVars.gameType)
+	{
+		case "Easy":
+
+			runtime.globalVars.totaltime = 150;
+
+			break;
+
+
+		case "Medium":
+
+			runtime.globalVars.totaltime = 100;
+
+			break;
+
+
+		case "Hard":
+
+			runtime.globalVars.totaltime = 60;
+
+			break;
+
+
+		default:
+
+			runtime.globalVars.totaltime = 150;
+
+			break;
+	}
+
+
+	console.log(
+		"Set Total Time:",
+		runtime.globalVars.totaltime
+	);
+}
+
+
+
 function HandleMessage(runtime, event)
 {
 	 console.log("MESSAGE RECEIVED");
@@ -65,8 +157,8 @@ function HandleMessage(runtime, event)
 
 			console.log("INIT_GAME received: "+ event.data);
 
-			runtime.globalVars.gameType =
-				event.data.gameType ?? "";
+			//runtime.globalVars.gameType =
+			//	event.data.gameType ?? "";
 
 			runtime.globalVars.msisdn =
 				event.data.msisdn ?? "";
@@ -89,17 +181,6 @@ function HandleMessage(runtime, event)
 			);
 
 			break;
-
-		case "EXIT_GAME_RESULT":
-			// DEV NOTE: callback Exit chay trong iframe an, chuyen ket qua len MVC.
-			exitSending = false;
-			if (exitTimeoutId)
-			{
-				clearTimeout(exitTimeoutId);
-				exitTimeoutId = 0;
-			}
-			window.parent.postMessage(event.data, "*");
-			break;
 	}
 }
 
@@ -170,80 +251,67 @@ function Tick(runtime)
 //Set showPrizePopup = 0
 async function SaveLevelResult(runtime)
 {
-	// DEV NOTE: levelCompleted co the giu gia tri 1 qua nhieu tick.
-	// Khoa request de mot level khong bi ghi nhieu lan.
-	if (levelSending)
-		return;
-
-	levelSending = true;
-
 	try
 	{
 		console.log("Calling SaveLevelResult...");
-		
+
 		const body = {
-						token: runtime.globalVars.token,
-						msisdn: runtime.globalVars.msisdn,
-						transId: runtime.globalVars.transId,
-						level: runtime.globalVars.cur_level,
-						score: runtime.globalVars.score,
-						gameType: runtime.globalVars.gameType,
-						gameOver: 0
-					};
-		console.log("Request Body:", body);
-		console.log("JSON:", JSON.stringify(body));
+			token: runtime.globalVars.token,
+			msisdn: runtime.globalVars.msisdn,
+			transId: runtime.globalVars.transId,
+			level: runtime.globalVars.cur_level,
+			score: runtime.globalVars.score,
+			gameType: runtime.globalVars.gameType,
+			gameOver: 0
+		};
 
-		const response = await fetch(runtime.globalVars.root+"/Game/SaveLevelResult", 
-						{
-							method: "POST",
-							headers: {
-								"Content-Type": "application/json"
-							},
-							body: JSON.stringify(body)
-						});
+		console.log("Request Body:", body);
 
-		if (!response.ok)
-			throw new Error("Save level HTTP " + response.status);
+		const response = await fetch(
+			runtime.globalVars.root + "/Game/SaveLevelResult",
+			{
+				method: "POST",
+				headers: {
+					"Content-Type": "application/json"
+				},
+				body: JSON.stringify(body)
+			}
+		);
 
 		const result = await response.json();
 
 		console.log("Level Result:", result);
 
-		if (!result || result.success !== true)
-			throw new Error(result?.message || "Save level failed");
-
-		// Ví dụ dữ liệu trả về
-		runtime.globalVars.point =
-			result.point ?? "0";
+		// Lưu dữ liệu gốc
+		runtime.globalVars.point = Number(result.point ?? 0);
+		runtime.globalVars.data = Number(result.data ?? 0);
+		runtime.globalVars.score = Number(result.score ?? 0);
+		runtime.globalVars.transId = result.transId ?? "";
 
-		runtime.globalVars.data =
-			result.data ?? "";
+		// Xác định phần thưởng
+		runtime.globalVars.gGiftValues = 0;
+		runtime.globalVars.gGiftText = "";
 
-		runtime.globalVars.score =
-			result.score ?? "0";
-
-		runtime.globalVars.transId =
-			result.transId ?? runtime.globalVars.transId;
+		if (runtime.globalVars.point > 0)
+		{
+			runtime.globalVars.gGiftValues = runtime.globalVars.point;
+			runtime.globalVars.gGiftText = "POINTS";
+		}
+		else if (runtime.globalVars.data > 0)
+		{
+			runtime.globalVars.gGiftValues = runtime.globalVars.data;
+			runtime.globalVars.gGiftText = "DATA";
+		}
+		else if (runtime.globalVars.score > 0)
+		{
+			runtime.globalVars.gGiftValues = runtime.globalVars.score;
+			runtime.globalVars.gGiftText = "SCORE";
+		}
 
-		// Chi hien popup sau khi MVC xac nhan luu thanh cong.
 		runtime.globalVars.showPrizePopup = 1;
 
-		// DEV NOTE: Website dung message nay de tong hop thuong cua phien choi.
-		window.parent.postMessage({
-			type: "LEVEL_REWARD",
-			level: runtime.globalVars.cur_level,
-			point: result.point ?? "0",
-			data: result.data ?? "",
-			score: result.score ?? "0",
-			rewardType: result.rewardType ?? "",
-			rewardValue: result.rewardValue ?? 0,
-			rewardUnit: result.rewardUnit ?? "",
-			transId: runtime.globalVars.transId
-		}, "*");
-		console.log("Chuẩn bị gọi vào function trong event sheet:");
-		//runtime.callFunction("Quangbh");
-		console.log("Da goi goi vao function event sheet xong nhe!!!");
-		
+		console.log("Gift Type:", runtime.globalVars.gGiftText);
+		console.log("Gift Value:", runtime.globalVars.gGiftValues);
 	}
 	catch (error)
 	{
@@ -259,35 +327,11 @@ async function SaveLevelResult(runtime)
 // Khi muốn thoát game về MVC
 function SaveExitGame(runtime)
 {
-	// DEV NOTE: khoa ngay lan bam dau de tranh tao nhieu request Exit.
-	if (exitSending)
-		return;
-
-	exitSending = true;
-	const btn = runtime.objects.btn_exit?.getFirstInstance?.();
 	try
 	{
-
-		if (btn)
-		{
-			btn.isCollisionEnabled = false;
-		}
-
-		let targetFrame = document.getElementById("kitty-exit-target");
-		if (!targetFrame)
-		{
-			targetFrame = document.createElement("iframe");
-			targetFrame.id = "kitty-exit-target";
-			targetFrame.name = "kitty-exit-target";
-			targetFrame.hidden = true;
-			document.body.appendChild(targetFrame);
-		}
-
 		const form = document.createElement("form");
 		form.method = "POST";
 		form.action = runtime.globalVars.root + "/Game/ExitGame";
-		form.target = targetFrame.name;
-		form.hidden = true;
 
 		// Thêm input hidden
 		function add(name, value)
@@ -299,7 +343,7 @@ function SaveExitGame(runtime)
 			form.appendChild(input);
 		}
 
-		add("token", runtime.globalVars.token);
+		//add("token", runtime.globalVars.token);
 		add("msisdn", runtime.globalVars.msisdn);
 		add("transId", runtime.globalVars.transId);
 		add("level", runtime.globalVars.cur_level);
@@ -308,29 +352,12 @@ function SaveExitGame(runtime)
 		add("gameOver", runtime.globalVars.gameOver);
 
 		document.body.appendChild(form);
+
 		// Submit form
 		HTMLFormElement.prototype.submit.call(form);
-		form.remove();
-
-		exitTimeoutId = window.setTimeout(() =>
-		{
-			exitSending = false;
-			exitTimeoutId = 0;
-			lastExitGame = 0;
-			runtime.globalVars.exitGame = 0;
-			if (btn)
-				btn.isCollisionEnabled = true;
-			console.error("ExitGame timeout");
-		}, 15000);
-
 	}
 	catch (error)
 	{
-		exitSending = false;
-		lastExitGame = 0;
-		runtime.globalVars.exitGame = 0;
-		if (btn)
-			btn.isCollisionEnabled = true;
 		console.error("SaveExitGame Error:", error);
 	}
 }
@@ -443,3 +470,6 @@ function MovePlayer(offsetX, offsetY)
     player.x += offsetX;
     player.y += offsetY;
 }
+
+
+

+ 3 - 1
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/kitty/js/all.min.js

@@ -457,7 +457,9 @@ const initKittyFall = () => {
                 gameStarted = true;
                 playGameRoot.classList.add("is-game-running");
                 gameShell.setAttribute("aria-hidden", "false");
-                gameFrame.src = playGameRoot.dataset.gameUrl || "/catpuzzle/index.html";
+                const gameUrl = playGameRoot.dataset.gameUrl || "/catpuzzle/index.html";
+                const separator = gameUrl.includes("?") ? "&" : "?";
+                gameFrame.src = `${gameUrl}${separator}gameType=${encodeURIComponent(selectedLevel)}`;
             } catch (error) {
                 console.error("StartSession Error:", error);
                 window.alert("Unable to start game.");

+ 3 - 1
Kitty_Fall/Kitty_Fall/Kitty_Fall.Website/wwwroot/kitty/js/input.js

@@ -457,7 +457,9 @@ const initKittyFall = () => {
                 gameStarted = true;
                 playGameRoot.classList.add("is-game-running");
                 gameShell.setAttribute("aria-hidden", "false");
-                gameFrame.src = playGameRoot.dataset.gameUrl || "/catpuzzle/index.html";
+                const gameUrl = playGameRoot.dataset.gameUrl || "/catpuzzle/index.html";
+                const separator = gameUrl.includes("?") ? "&" : "?";
+                gameFrame.src = `${gameUrl}${separator}gameType=${encodeURIComponent(selectedLevel)}`;
             } catch (error) {
                 console.error("StartSession Error:", error);
                 window.alert("Unable to start game.");

BIN
Kitty_Fall/catpuzzle.zip


Некоторые файлы не были показаны из-за большого количества измененных файлов