Skip to content

Commit

Permalink
Merge pull request #121 from fleizean/mpa
Browse files Browse the repository at this point in the history
all bugs solved
  • Loading branch information
yeaktas authored Feb 23, 2024
2 parents c46dd2d + 6e23303 commit 42a7bae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
29 changes: 13 additions & 16 deletions indianpong/static/js/local-game.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,36 +260,33 @@ function resetBall() {
}, 500);
}

function frozenBallAbility(Count) {
function frozenBallAbility() {
var nowBallSpeed = ball.speed;
isFrozenBallActive = true;
ball.speed = 0;
Count += 1;
setTimeout(function() {
ball.speed = nowBallSpeed;
isFrozenBallActive = false;
}, 2000);
}

function likeaCheaterAbility(isPlayer2, Count) {
if (isPlayer2) {
function likeaCheaterAbility(whichPlayer) {
if (whichPlayer == "Player2") {
score2++;
if (score1 > 0) {
score1--;
}
}
else {
else if (whichPlayer == "Player1") {
score1++;
if (score2 > 0) {
score2--;
}
}
Count += 1;
}

function fastandFuriousAbility(Count) {
function fastandFuriousAbility() {
ball.speed += 10;
Count += 1;
}

// Control paddle1 with w, s keys
Expand All @@ -301,15 +298,15 @@ document.addEventListener("keydown", function(event) {
downPressed = true;
}
else if (event.key === '1' && likeaCheaterCount < 1 && gameMode == "Abilities") {
likeaCheaterAbility(false, likeaCheaterCount);
likeaCheaterAbility("Player1");
likeaCheaterCount += 1;
}
else if (event.key === '2' && fastandFuriousCount < 1 && gameMode == "Abilities" && isFrozenBallActive == false) {
fastandFuriousAbility(fastandFuriousCount);
fastandFuriousAbility();
fastandFuriousCount += 1;
}
else if (event.key === '3' && frozenBallCount < 1 && gameMode == "Abilities") {
frozenBallAbility(frozenBallCount);
frozenBallAbility();
frozenBallCount += 1;
}
});
Expand All @@ -322,16 +319,16 @@ document.addEventListener("keydown", function(event) {
downPressedPlayer2 = true;
}
else if (event.key === '8' && Player2LikeaCheaterCount < 1 && gameMode == "Abilities") {
likeaCheaterAbility(false, Player2LikeaCheaterCount);
likeaCheaterAbility("Player2");
Player2LikeaCheaterCount += 1;
}
else if (event.key === '9' && Player2FastandFuriousCount < 1 && gameMode == "Abilities" && isFrozenBallActive == false) {
fastandFuriousAbility(Player2FastandFuriousCount);
Player2FastandFuriousCount += 2;
fastandFuriousAbility();
Player2FastandFuriousCount += 1;
}
else if (event.key === '0' && Player2FrozenBallCount < 1 && gameMode == "Abilities") {
frozenBallAbility(Player2FrozenBallCount);
Player2FrozenBallCount += 2;
frozenBallAbility();
Player2FrozenBallCount += 1;
}
});

Expand Down
31 changes: 17 additions & 14 deletions indianpong/static/js/play-ai.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var paddle1 = {x: 0, y: paddleY, width: paddleWidth, height: abilities_paddleHei
var paddle2 = {x: canvas.width - paddleWidth, y: paddleY, width: paddleWidth, height: abilities_paddleHeight, dy: paddleSpeed};

// Ball object
var ball = {x: canvas.width / 2, y: canvas.height / 2, radius: 10, speed: 5, dx: 1, dy: 1};
var ball = {x: canvas.width / 2, y: canvas.height / 2, radius: 10, speed: 10, dx: 1, dy: 1};

// Scores
var score1 = 0;
Expand Down Expand Up @@ -276,19 +276,18 @@ function resetBall() {
}, 500);
}

function frozenBallAbility(Count) {
function frozenBallAbility() {
var nowBallSpeed = ball.speed;
isFrozenBallActive = true;
ball.speed = 0;
Count += 1;
setTimeout(function() {
ball.speed = nowBallSpeed;
isFrozenBallActive = false;
}, 2000);
}

function likeaCheaterAbility(isAi, Count) {
if (isAi) {
function likeaCheaterAbility(isAi) {
if (isAi === true) {
score2++;
if (score1 > 0) {
score1--;
Expand All @@ -300,12 +299,10 @@ function likeaCheaterAbility(isAi, Count) {
score2--;
}
}
Count += 1;
}

function fastandFuriousAbility(Count) {
function fastandFuriousAbility() {
ball.speed += 10;
Count += 1;
}

// Control paddle1 with w, s keys
Expand All @@ -317,15 +314,18 @@ document.addEventListener("keydown", function(event) {
downPressed = true;
}
else if (event.key === '1' && likeaCheaterCount < 1 && likeaCheater == "true") {
likeaCheaterAbility(false, likeaCheaterCount);
likeaCheaterAbility(false);
likeaCheaterCount += 1;

}
else if (event.key === '2' && fastandFuriousCount < 1 && fastandFurious == "true" && isFrozenBallActive == false) {
fastandFuriousAbility(fastandFuriousCount);
fastandFuriousAbility();
fastandFuriousCount += 1;

}
else if (event.key === '3' && frozenBallCount < 1 && frozenBall == "true") {
frozenBallAbility(frozenBallCount);
frozenBallAbility();
frozenBallCount += 1;
}
});

Expand All @@ -352,23 +352,26 @@ setInterval(() => {
if (ball.dx > 0 && ball.x > canvas.width / 2 && ball.y > canvas.height / 2) {
// AI'nın kendisi için kullanması için bir kontrol ekleyin
if (ball.x > paddle2.x + paddle2.width) {
frozenBallAbility(aiFrozenBallCount);
frozenBallAbility();
aiFrozenBallCount += 1;
}
}
}
if (fastandFurious == "true" && aiFastandFuriousCount < 1 && isFrozenBallActive == false) {
// Top rakip yarı sahaya doğru gidiyorsa ve topun X koordinatı AI'nın ceza sahasında ise
if (ball.dx < 0 && ball.x > canvas.width / 2 && ball.x < canvas.width - paddle2.width && ball.speed > 5) {
//console.log("AI Fast and Furious yeteneğini kullandı ve değerleri şu şekilde: ", ball.speed);
fastandFuriousAbility(aiFastandFuriousCount);
fastandFuriousAbility();
aiFastandFuriousCount += 1;
}
}


if (likeaCheater == "true" && aiLikeaCheaterCount < 1) {
if (score2 < score1 || score1 === MAX_SCORE - 1 || score2 + 1 === MAX_SCORE) {
//console.log("AI Like a Cheater yeteneğini kullandı ve değerleri şu şekilde: ", score1, score2);
likeaCheaterAbility(true, aiLikeaCheaterCount);
likeaCheaterAbility(true);
aiLikeaCheaterCount += 1;
}
}

Expand Down

0 comments on commit 42a7bae

Please sign in to comment.