Finite-State Machine Using Interval:


File: StateMachineUsingInterval.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>***</title>
<!-- Use the following value to display the webpage in edge mode, which is the highest standards mode supported by Internet Explorer: -->
<meta http-equiv="x-ua-compatible" content="IE=edge">
<script type="text/javascript" src="StateMachineUsingInterval.js"></script>

</head>

<body style="background-color:green">
<h1></h1>
</body>

</html>


File: StateMachineUsingInterval.js

(function () {
// GLOBAL VARIABLES (Scope in JavaScript is function/object based):
// ================================================================
var iBodyWidth = 0;
var iBodyHeight = 0;
var iMaxBodyX = 0;
var iMaxBodyY = 0;

var newImage;

iTimeoutStateMachine = 2000;
iStateMachineStatus = 0;

function fStateMachineUsingIntervall() {
var intervalStatemachine = window.setInterval(function States() {
if (iStateMachineStatus === 2) {
console.log("Start: StateMachine State: 2");
// Your Code 555555555555
// Your Code 555555555555

// Wenn fertig:
// Intervall löschen:
// console.log("FERTIG !!!!!");
window.clearInterval(intervalStatemachine);
}
else if (iStateMachineStatus === 1) {

console.log("Start: StateMachine State: 1");
// Your Code 444444444444
// Your Code 444444444444

iTimeoutStateMachine = 2000;
iStateMachineStatus = 2;
}
else if (iStateMachineStatus === 0) {

console.log("Start: StateMachine State: 0");
// Your Code 333333333333
// Your Code 333333333333

iTimeoutStateMachine = 2000;
iStateMachineStatus = 1;
}
}, iTimeoutStateMachine);
}

function fStartApplication() {
console.log("Start: fStartApplication");

// Your Code 222222222222
// Your Code 222222222222

iStateMachineStatus = 0;
iTimeoutStateMachine = 2000;
fStateMachineUsingIntervall();
}

function fInit() {
console.log("Start: fInit");
iMaxBodyX = iBodyWidth = document.body.clientWidth;
iMaxBodyY = iBodyHeight = window.innerHeight;
//console.log("iBodyWidth (iMaxBodyX) = " + iMaxBodyX + "px");
//console.log("iBodyHeight (iMaxBodyY) = " + iMaxBodyY + "px");

//document.body.style.cursor = 'none';

// Your Code 111111111111
// Your Code 111111111111

fStartApplication();
}

window.addEventListener("load", fInit);

})();


***********************************************************************************


File: StateMachineUsingInterval.html (Version 2):


<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>***</title>
<!-- Use the following value to display the webpage in edge mode, which is the highest standards mode supported by Internet Explorer: -->
<meta http-equiv="x-ua-compatible" content="IE=edge">


</head>

<body style="background-color:green">
<h1></h1>
</body>

</html>



File: StateMachineUsingInterval.js (Version 2):


(function () {
// GLOBAL VARIABLES (Scope in JavaScript is function/object based):
// ================================================================
var iBodyWidth = 0;
var iBodyHeight = 0;
var iMaxBodyX = 0;
var iMaxBodyY = 0;

var iStart = 0;
var iEnd = 100;

function fStateMachineUsingIntervall_State_02() {
console.log("*** State_02 ***");
var interval = window.setInterval(function func() {
iStart++;
console.log("State_02: " + iStart);
if (iStart == iEnd) {
window.clearInterval(interval);
iStart = 0;
// again ??? - or End ???
}
}, 25);
}

function fStateMachineUsingIntervall_State_01(){
console.log("*** State_01 ***");
var interval = window.setInterval(function func() {
iStart++;
console.log("State_01: " + iStart);
if (iStart == iEnd) {
window.clearInterval(interval);
iStart = 0;
fStateMachineUsingIntervall_State_02();
}
}, 25);
}

function fStateMachineUsingIntervall_State_00() {
console.log("*** State_00 ***");
var interval = window.setInterval(function func() {
iStart++;
console.log("State_00: " + iStart);
if (iStart == iEnd) {
window.clearInterval(interval);
iStart = 0;
fStateMachineUsingIntervall_State_01();
}
}, 25);
}

function fStartApplication() {
console.log("Start: fStartApplication");

// Your Code 222222222222
// Your Code 222222222222

iStateMachineStatus = 0;
iTimeoutStateMachine = 2000;

fStateMachineUsingIntervall_State_00();
}

function fInit() {
console.log("Start: fInit");
iMaxBodyX = iBodyWidth = document.body.clientWidth;
iMaxBodyY = iBodyHeight = window.innerHeight;
//console.log("iBodyWidth (iMaxBodyX) = " + iMaxBodyX + "px");
//console.log("iBodyHeight (iMaxBodyY) = " + iMaxBodyY + "px");

//document.body.style.cursor = 'none';

// Your Code 111111111111
// Your Code 111111111111

fStartApplication();
}

window.addEventListener("load", fInit);

})();


***********************************************************************************