target/web/public/main/js/cardgame.js
//4. The `play` function, which is your game or application logic that runs in a loop
4. The `play` function, which is your game or application logic that runs in a loop
4 . The ` play ` function which is your game or application logic that runs in a loop
function play(){
  if (gameActorInitalized) {
	if (!gameStart) {
		ws.send(JSON.stringify({
    		messagetype: "initalize"
  		}));
        gameStart = true;
		renderPlayer1Card();
		renderPlayer2Card();
		renderEndTurnButton();
	}
	while (drawTileQueue.length>0) {
		drawTile(drawTileQueue.pop());
	}
	while (drawUnitQueue.length>0) {
		drawUnit(drawUnitQueue.pop());
	}
	var continuingProjectiles = [];
	for (i = 0; i < activeProjectiles.length; i++) {
		if(!executeProjectileMoveStep(activeProjectiles[i])) {
			continuingProjectiles.push(activeProjectiles[i]);
		}
	}
	activeProjectiles = continuingProjectiles;
    var completedMoves = [];
    for (let [key, value] of activeMoves) {
	  if (executeMoveStep(value)) {
	  	  completedMoves.push(key);
	  }
    }
    for (i = 0; i < completedMoves.length; i++) {
      activeMoves.delete(completedMoves[i]);
    }
	if (player1Notification!==null) {
		player1Notification.countdown = player1Notification.countdown-1;
		if (player1Notification.countdown<=0) {
			g.stage.removeChild(player1Notification);
			g.stage.removeChild(player1NotificationText);
			player1Notification = null;
			player1NotificationText = null;
		}
	}
	if (player2Notification!==null) {
		player2Notification.countdown = player2Notification.countdown-1;
		if (player2Notification.countdown<=0) {
			g.stage.removeChild(player2Notification);
			g.stage.removeChild(player2NotificationText);
			player2Notification = null;
			player2NotificationText = null;
		}
	}
	if (cardPreview!=null) {
		if (prevewCountdown<=0) {
			g.stage.removeChild(cardPreview);
			cardPreview = null;
		}
		prevewCountdown = prevewCountdown -1;
	}
	for (i = 0; i < playingEffects.length; i++) {
		if (playingEffects[i].killCountdown<=0) {
			g.stage.removeChild(playingEffects[i]);
			playingEffects.splice(i, 1);
			break;
		}
		playingEffects[i].killCountdown = playingEffects[i].killCountdown-1;
    }
	sinceLastHeartbeat = sinceLastHeartbeat+1;
	if (sinceLastHeartbeat==120) {
		ws.send(JSON.stringify({
    		messagetype: "heartbeat"
        }));
        sinceLastHeartbeat = 1;
	}
  }
}
function play ( ) { if ( gameActorInitalized ) { if ( ! gameStart ) { ws . send ( JSON . stringify ( { messagetype : "initalize" } ) ) ; gameStart = true ; renderPlayer1Card ( ) ; renderPlayer2Card ( ) ; renderEndTurnButton ( ) ; } while ( drawTileQueue . length > 0 ) { drawTile ( drawTileQueue . pop ( ) ) ; } while ( drawUnitQueue . length > 0 ) { drawUnit ( drawUnitQueue . pop ( ) ) ; } var continuingProjectiles = [ ] ; for ( i = 0 ; i < activeProjectiles . length ; i ++ ) { if ( ! executeProjectileMoveStep ( activeProjectiles [ i ] ) ) { continuingProjectiles . push ( activeProjectiles [ i ] ) ; } } activeProjectiles = continuingProjectiles ; var completedMoves = [ ] ; for ( let [ key , value ] of activeMoves ) { if ( executeMoveStep ( value ) ) { completedMoves . push ( key ) ; } } for ( i = 0 ; i < completedMoves . length ; i ++ ) { activeMoves . delete ( completedMoves [ i ] ) ; } if ( player1Notification !== null ) { player1Notification . countdown = player1Notification . countdown - 1 ; if ( player1Notification . countdown <= 0 ) { g . stage . removeChild ( player1Notification ) ; g . stage . removeChild ( player1NotificationText ) ; player1Notification = null ; player1NotificationText = null ; } } if ( player2Notification !== null ) { player2Notification . countdown = player2Notification . countdown - 1 ; if ( player2Notification . countdown <= 0 ) { g . stage . removeChild ( player2Notification ) ; g . stage . removeChild ( player2NotificationText ) ; player2Notification = null ; player2NotificationText = null ; } } if ( cardPreview != null ) { if ( prevewCountdown <= 0 ) { g . stage . removeChild ( cardPreview ) ; cardPreview = null ; } prevewCountdown = prevewCountdown - 1 ; } for ( i = 0 ; i < playingEffects . length ; i ++ ) { if ( playingEffects [ i ] . killCountdown <= 0 ) { g . stage . removeChild ( playingEffects [ i ] ) ; playingEffects . splice ( i , 1 ) ; break ; } playingEffects [ i ] . killCountdown = playingEffects [ i ] . killCountdown - 1 ; } sinceLastHeartbeat = sinceLastHeartbeat + 1 ; if ( sinceLastHeartbeat == 120 ) { ws . send ( JSON . stringify ( { messagetype : "heartbeat" } ) ) ; sinceLastHeartbeat = 1 ; } } }
4.
4 .
//This is your game loop, where you can move sprites and add your //game logic // Draw Tile Actions // Draw Tile Actions // Operationalize Sprite Movement // Remove the card preview after the pre-determined time // tidy up animations that have finished playing