Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fundamentals 27-1 Beat That Submissions: Eugene Matthew #558

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}

#container {
background-color: pink;
background-color: lightblue;
margin: 40px auto;
max-width: 800px;
padding: 38px 31px;
Expand Down Expand Up @@ -49,8 +49,11 @@
</head>

<body>
<h1 id="header">Basics: Beat That! 🚀</h1>
<h1 id="header">Fundamentals: EuMatt Beat That! 🚀</h1>
<div id="container">
<p>Hello! Welcome to Beat That! Click submit to start the game.</p>
<p>Create a two-digit number by selecting the order of your dice rolls.</p>
<p>The player with the highest number wins! Good luck!</p>
<p>Input:</p>
<input id="input-field" />
<br />
Expand Down
111 changes: 110 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,113 @@
var player1_list = []
Copy link

Choose a reason for hiding this comment

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

Good job on defining your global variables here!

var player2_list = []
var player1_selectedNum = 0
var player2_selectedNum = 0
var player1wins = 0
var player2wins = 0

var game_state = "PLAYER_1_DICE_ROLL"
var player1_diceroll_roll = "PLAYER_1_DICE_ROLL"
var player1_diceroll_select = "PLAYER_1_ROLL_SELECT"
var player2_diceroll_roll = "PLAYER_2_DICE_ROLL"
var player2_diceroll_select = "PLAYER_2_ROLL_SELECT"
var player_score = "PLAYER_SCORE"


var genRandNum = function () {
var randomNum = Math.random() * 6;
var randInt = Math.floor(randomNum) + 1;

console.log(`Random generated number: ${randInt}`);

return randInt;
};

var genPlayerDiceRoll = function () {
var genNum1 = genRandNum();
var genNum2 = genRandNum();

console.log(`Dice Roll 1: ${genNum1}`);
console.log(`Dice Roll 2: ${genNum2}`);

return [genNum1,genNum2]
};


var reset_Score = function () {
console.log("Scores reset initialized");
var player1_list = []
var player2_list = []
var player1_selectedNum = 0
var player2_selectedNum = 0
};


var main = function (input) {
var myOutputValue = 'hello world';

if (game_state == player1_diceroll_roll){
console.log("ENTERED PLAYER 1 ROLL");
player1_list = genPlayerDiceRoll()
var myOutputValue = `Welcome Player 1<br>You rolled ${player1_list[0]} for Dice 1 and ${player1_list[1]} for Dice 2.<br>Choose the order of the dice. Please input "1" or "2"`;
game_state = player1_diceroll_select;

} else if (game_state == player1_diceroll_select){
console.log("ENTERED PLAYER 1 SELECT");
if(input == "1") {
player1_selectedNum = Number(`${player1_list[0]}${player1_list[1]}`)
console.log(`PLAYER 1 CHOSE ${input}. Result will be ${player1_selectedNum}`);
var myOutputValue = `Player 1, you chose Dice 1 first.<br>Your number is ${player1_selectedNum}.<br>It is now Player 2's turn`;
game_state = player2_diceroll_roll;
} else if (input == "2"){
player1_selectedNum = Number(`${player1_list[1]}${player1_list[0]}`)
console.log(`PLAYER 1 CHOSE ${input}. Result will be ${player1_selectedNum}`);
var myOutputValue = `Player 1, you chose Dice 2 first.<br>Your number is ${player1_selectedNum}.<br>It is now Player 2's turn`;
game_state = player2_diceroll_roll;
} else {
console.log(`PLAYER 1 input incorrect values.`);
var myOutputValue = `Player 1, please input only "1" or "2"<br>You rolled ${player1_list[0]} for Dice 1 and ${player1_list[1]} for Dice 2.<br>Choose the order of the dice. Please input "1" or "2"`;
};
} else if (game_state == player2_diceroll_roll){
console.log("ENTERED PLAYER 2 ROLL");
player2_list = genPlayerDiceRoll()
var myOutputValue = `Welcome Player 2<br>You rolled ${player2_list[0]} for Dice 1 and ${player2_list[1]} for Dice 2.<br>Choose the order of the dice. Please input "1" or "2"`;
game_state = player2_diceroll_select;

} else if (game_state == player2_diceroll_select){
console.log("ENTERED PLAYER 2 SELECT");
if(input == "1") {
player2_selectedNum = Number(`${player2_list[0]}${player2_list[1]}`)
console.log(`PLAYER 2 CHOSE ${input}. Result will be ${player2_selectedNum}`);
var myOutputValue = `Player 2, you chose Dice 1 first.<br>Your number is ${player2_selectedNum}.`;
game_state = player_score;
} else if (input == "2"){
player2_selectedNum = Number(`${player2_list[1]}${player2_list[0]}`)
console.log(`PLAYER 2 CHOSE ${input}. Result will be ${player2_selectedNum}`);
var myOutputValue = `Player 2, you chose Dice 2 first.<br>Your number is ${player2_selectedNum}.`;
game_state = player_score;
} else {
console.log(`PLAYER 2 input incorrect values.`);
var myOutputValue = `Player 1, please input only "1" or "2"<br>You rolled ${player2_list[0]} for Dice 1 and ${player2_list[1]} for Dice 2.<br>Choose the order of the dice. Please input "1" or "2"`;
};

} else {
if (player1_selectedNum > player2_selectedNum) {
var myOutputValue = `Player 1 score: ${player1_selectedNum}<br> Player 2 score: ${player2_selectedNum}<br><br>Player 1 wins!!`
player1wins +=1
} else if (player2_selectedNum > player1_selectedNum) {
var myOutputValue = `Player 1 score: ${player1_selectedNum}<br> Player 2 score: ${player2_selectedNum}<br><br>Player 2 wins!!`
player2wins +=1
} else {
var myOutputValue = `Player 1 score: ${player1_selectedNum}<br> Player 2 score: ${player2_selectedNum}<br><br>WHAT?? BOTH PLAYERS HAVE THE SAME NUMBER!! <br>ITS A DRAW!!!`
};

if (player1wins > 2 || player2wins > 2){
myOutputValue = myOutputValue + `<br><br>CURRENT SCORES: PLAYER 1: ${player1wins} | PLAYER 2: ${player2wins}`
}

reset_Score()
game_state = player1_diceroll_roll;
};


return myOutputValue;
};