MCPcopy Create free account
hub / github.com/codemistic/Web-Development / change

Function change

Memory-Matching-Game/gameScript.js:77–139  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

75
76//Function for flipping blocks
77function change(x) {
78 //Variables
79 let i = "#"+x+" .inner";
80 let f = "#"+x+" .inner .front";
81 let b = "#"+x+" .inner .back";
82
83 //Dont flip for these conditions
84 if (turn==2 || $(i).attr("flip")=="block" || ppID==x) {}
85
86 //Flip
87 else {
88 $(i).css(t, flip);
89 if (turn==1) {
90 //This value will prevent spam clicking
91 turn=2;
92
93 //If both flipped blocks are not same
94 if (pre!=$(b).text()) {
95 setTimeout(function() {
96 $(pID).css(t, flipBack);
97 $(i).css(t, flipBack);
98 ppID=0;
99 },1000);
100 }
101
102 //If blocks flipped are same
103 else {
104 rem--;
105 $(i).attr("flip", "block");
106 $(pID).attr("flip", "block");
107 }
108
109 setTimeout(function() {
110 turn=0;
111 //Increase moves
112 moves++;
113 $("#moves").html("Moves: "+moves);
114 },1150);
115
116 }
117 else {
118 pre = $(b).text();
119 ppID = x;
120 pID = "#"+x+" .inner";
121 turn=1;
122 }
123
124 //If all pairs are matched
125 if (rem==0) {
126 clearInterval(time);
127 if (min==0) {
128 time = `${sec} seconds`;
129 }
130 else {
131 time = `${min} minute(s) and ${sec} second(s)`;
132 }
133 setTimeout(function() {
134 $("#ol").html(`<center><div id="iol"><h2>Congrats!</h2><p style="font-size:23px;padding:10px;">You completed the ${mode} mode in ${moves} moves. It took you ${time}.</p><p style="font-size:18px">Comment Your Score!<br/>Play Again ?</p><button onclick="start(3, 4)">3 x 4</button> <button onclick="start(4, 4)" style="w">4 x 4</button><button onclick="start(4, 5)">4 x 5</button><button onclick="start(5, 6)">5 x 6</button><button onclick="start(6, 6)">6 x 6</button></div></center>`);

Callers

nothing calls this directly

Calls 2

$Function · 0.50
textMethod · 0.45

Tested by

no test coverage detected