-
Notifications
You must be signed in to change notification settings - Fork 660
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
eugenematthewcheong
wants to merge
1
commit into
rocketacademy:main
Choose a base branch
from
eugenematthewcheong:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,113 @@ | ||
var player1_list = [] | ||
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; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!