Skip to content

Zeeslag feedback - #1

Open
milotolboom wants to merge 1 commit into
masterfrom
feature/feedback-milo
Open

Zeeslag feedback#1
milotolboom wants to merge 1 commit into
masterfrom
feature/feedback-milo

Conversation

@milotolboom

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread zeeslag_for_feedback.html
Comment thread zeeslag_for_feedback.html
Comment thread zeeslag_for_feedback.html
Comment thread zeeslag_for_feedback.html
return square;
}

function insertEnemyGameMethods(gridNumber) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deze functie kan eigenlijk weg. Bij het maken van de enemy squares (createEnemySquares), maak je al een square object aan met changeStateAndDraw en doCoordinatesOverlap er in. Alleen geen getEnemySeaColor. Haal deze functie dus weg, en geef een parameter mee aan createAndGetGridSquare:

function createAndGetGridSquare(x, y, gridNumber, isForEnemy) {
            let getColor;
            if (isForEnemy) {
                 getColor = getMySeaColor
            } else {
                  getColor = getEnemySeaColor
            }

            const square = {
                x: x,
                y: y,
                state: "water",
                getColor: getColor,
                id: gridNumber,
                changeAndDraw: changeStateAndDraw,
                isClicked: doCoordinatesOverlap
            };
            return square;
        }

en daarna alle aanroepen van deze functie de parameter mee geven of het voor enemy is of voor eigen

Comment thread zeeslag_for_feedback.html
function drawEnemySea() {
for (let rowNumber = 0; rowNumber < numOfRows; rowNumber++) {
for (let columnNumber = 0; columnNumber < numOfRows; columnNumber++) {
const square = insertEnemyGameMethods(rowNumber * numOfRows + columnNumber);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deze insertEnemyGameMethods functie gaat weg, dus dan hier gewoon
const square = enemySquares[rowNumber * numOfRows + columnNumber]

Comment thread zeeslag_for_feedback.html
const firstSquareIndex = Math.floor(Math.random() * numOfRows * numOfRows);
const enemyShipOrientation = Math.round(Math.random());

if (enemyShipOrientation === 0) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je checkt hier of enemyShipOrientation 0 is, maar een orientation kan helemaal geen 0 zijn. Beter zou zijn als je dit doet:

const enemyShipOrientationIsHorizontal = Math.round(Math.random()) === 0;

en dan op deze regel

if (enemyShipOrientationIsHorizontal) {
    shipOrientation = "horizontal";
     .... 
} else {
    shipOrientation = "vertical";
     .... 
}

Comment thread zeeslag_for_feedback.html
Comment thread zeeslag_for_feedback.html
Comment thread zeeslag_for_feedback.html
Comment thread zeeslag_for_feedback.html
Als dat zo is, beslist de functie wat er moet gebeuren. */
function playHumanTurn(mouseX, mouseY) {
for (let i = 0; i < enemySquares.length; i++) {
if (enemySquares[i].isClicked(mouseX, mouseY)) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deze if heeft verder geen code eronder, dus dan is het netter om de if om te draaien en te returnen ( continue in dit geval want je zit in een for loop), zodat er niet onnodig veel indent zit in de code:

if (!enemySquares[i].isClicked(mouseX, mouseY)) {
    continue;
}
// .... rest van de code

Comment thread zeeslag_for_feedback.html
}

let hitSquare = null;
function saveHitSquare(location) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deze functie kan weg, gewoon waar saveHitSquare aangeroepen wordt ipv daarvan hitSquare = location; neerzetten

Comment thread zeeslag_for_feedback.html
playComputerTurn();
} else if (enemySquares[i].state === "hit" || enemySquares[i].state === "miss") {
// Wanneer er twee keer een bom op dezelfde plek gegooid wordt, blijft de beurt staan.
document.getElementById("instruction-text").innerHTML = "A bomb has already been thrown here";

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hier zet je instructiontext zonder functie te gebruiken zoals bij de andere. Als je dit mooi wilt oplossen kan je ook alle manieren van instructies zetten groeperen:


const setInstruction = {
    element: document.getElementById("instruction-text"),
    throwBomb: function () {
        if (currentShipIndex >= 5) {
            setInstructions.element.innerHTML = "Throw a bomb";
        }
    },
    duplicateBomb: function () {
        setInstructions.element.innerHTML = "Oopsie woopsie!"
    },
    waitForYourTurn: function () {
        setInstructions.element.innerHTML = "Wait for your turn!"
    }
};

en dan zo aanroepen:
setInstruction.throwBomb();

Comment thread zeeslag_for_feedback.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant