-
Notifications
You must be signed in to change notification settings - Fork 0
Sharedmvp #9
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
Open
nonebula
wants to merge
44
commits into
main
Choose a base branch
from
sharedmvp
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
Sharedmvp #9
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
5da07f0
Tests
f98df9a
Merge pull request #6 from nonebula/playground
nonebula 680da61
Tests
ad25235
Added planning notes for today's actions
nonebula 8b7d7f5
Take2
7aca382
Take 3
9be750e
Testing suite debugging
nonebula 569c5ea
Code for selecting character from gameboard added
nonebula d157660
GameLogic tweaked
nonebula abff432
Question handling refactored
nonebula 44b8c65
Tests added
06490d1
Merging conflicts
nonebula 30d7adf
Refactor attempted
nonebula ddb3df2
Merge pull request #7 from nonebula/type-mismatch-debug
nonebula 3571f98
Team refactoring
69c1f53
Initialisation tests
8e7a773
Handles questions test
3fcdfcf
Testing tests
f856506
BoardSpec hair colour test fixed
151cb53
new tests added
6fb9000
File cleanup
nonebula 9ad8fa4
Added type to characters
nonebula 6fd6ad8
Test refactor
nonebula 1496ec2
Presentation notes
nonebula 2679ef7
Moved one note to bottom of board
nonebula 1764ed0
few changes
8e71f0a
last commit
de39d12
Ext1 (#8)
nonebula 7002bba
Minor styling
nonebula 4507c39
Final touches
nonebula 286cc46
Notes from presentation added
nonebula aab8b75
Character refactoring (Chunky)
nonebula 851ee31
Board logic refactored
nonebula 2c78d5c
Game object refactored
nonebula 7060122
Game refactor
nonebula f313ae0
update
nonebula a28e99e
tests added
c90cb80
Test edit
nonebula c0cc4c5
EyeColor.Blue
31d73e5
Testing for new elements
nonebula 432854f
Merge branch 'sharedmvp' of github.com:nonebula/GuessWho into sharedmvp
nonebula 3ce5ae1
note added
nonebula 9745878
Testing refinement (boardspec unfinished)
nonebula 28c3fa4
space
nonebula 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 hidden or 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 hidden or 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,7 +1,74 @@ | ||
| package GuessWhoGame | ||
|
|
||
| case class Board (Characters: List[Character]) { | ||
| def printCharacterNames(): Unit = { | ||
| Characters.foreach(Character => println(Character.name)) | ||
| import scala.util.Random | ||
| import GuessWhoGame.character._ | ||
|
|
||
| class Board(val characters: List[Character], val selectedCharacter: Character) { | ||
| def printCharacterNames(): List[String] = { | ||
| characters.map(_.name) | ||
| } | ||
|
|
||
| def printRemainingCharacters(remainingCharacters: List[Character]): List[String] = { | ||
| remainingCharacters.map(_.name) | ||
| } | ||
|
|
||
| def getRemainingCharacters(remainingCharacters: List[Character]): List[Character] = remainingCharacters | ||
|
|
||
| def checkWinCondition(remainingCharacters: List[Character]): Boolean = remainingCharacters.size == 1 | ||
|
|
||
| def handleQuestion(attribute: String, value: Either[String, Boolean], remainingCharacters: List[Character]): List[Character] = { | ||
| attribute match { | ||
| case "name" => filterByName(value, remainingCharacters) | ||
| case "gender" => filterByGender(value, remainingCharacters) | ||
| case "haircolor" => filterByHairColor(value, remainingCharacters) | ||
| case "eyecolor" => filterByEyeColor(value, remainingCharacters) | ||
| case "wearsglasses" => filterByWearGlasses(value, remainingCharacters) | ||
| case "hasfacialhair" => filterByFacialHair(value, remainingCharacters) | ||
| case _ => | ||
| println("Invalid attribute. Try again.") | ||
| remainingCharacters | ||
| } | ||
| } | ||
nonebula marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def filterByName(value: Either[String, Boolean], remainingCharacters: List[Character]): List[Character] = { | ||
| value match { | ||
| case Left(name) => remainingCharacters.filter(_.name.equalsIgnoreCase(name)) | ||
| case _ => remainingCharacters | ||
| } | ||
| } | ||
|
|
||
| def filterByGender(value: Either[String, Boolean], remainingCharacters: List[Character]): List[Character] = { | ||
| value match { | ||
| case Left(gender) => remainingCharacters.filter(_.gender.toString.equalsIgnoreCase(gender)) | ||
| case _ => remainingCharacters | ||
| } | ||
| } | ||
|
|
||
| def filterByHairColor(value: Either[String, Boolean], remainingCharacters: List[Character]): List[Character] = { | ||
| value match { | ||
| case Left(hairColor) => remainingCharacters.filter(_.hairColor.toString.equalsIgnoreCase(hairColor)) | ||
| case _ => remainingCharacters | ||
| } | ||
| } | ||
|
|
||
| def filterByEyeColor(value: Either[String, Boolean], remainingCharacters: List[Character]): List[Character] = { | ||
| value match { | ||
| case Left(eyeColor) => remainingCharacters.filter(_.eyeColor.toString.equalsIgnoreCase(eyeColor)) | ||
| case _ => remainingCharacters | ||
| } | ||
| } | ||
|
|
||
| def filterByWearGlasses(value: Either[String, Boolean], remainingCharacters: List[Character]): List[Character] = { | ||
| value match { | ||
| case Right(wearsGlasses) => remainingCharacters.filter(_.wearsGlasses.exists(_.value == wearsGlasses)) | ||
| case _ => remainingCharacters | ||
| } | ||
| } | ||
|
|
||
| def filterByFacialHair(value: Either[String, Boolean], remainingCharacters: List[Character]): List[Character] = { | ||
| value match { | ||
| case Right(facialHair) => remainingCharacters.filter(_.facialHair.exists(_.value == facialHair)) | ||
| case _ => remainingCharacters | ||
| } | ||
nonebula marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,80 +1,98 @@ | ||
| package GuessWhoGame | ||
|
|
||
| import scala.util.Random | ||
| import scala.io.StdIn | ||
| import GuessWhoGame.character._ | ||
| import scala.annotation.tailrec | ||
|
|
||
| object Game extends App { | ||
|
|
||
| val char1: Character = Character("joe", "male", "brown", "blue", wearsGlasses = false, facialHair = false) | ||
| val char2: Character = Character("muhammad", "male", "black", "brown", wearsGlasses = true, facialHair = true) | ||
| val char3: Character = Character("april", "female", "blonde", "blue", wearsGlasses = true, facialHair = false) | ||
| val char4: Character = Character("sally", "female", "blue", "green", wearsGlasses = true, facialHair = true) | ||
| val char5: Character = Character("spencer", "male", "brown", "brown", wearsGlasses = false, facialHair = true) | ||
| val char6: Character = Character("gemma", "female", "ginger", "Blue", wearsGlasses = true, facialHair = false) | ||
| val char7: Character = Character("jamie", "male", "none", "green", wearsGlasses = true, facialHair = true) | ||
| val char8: Character = Character("jessica", "female", "green", "green", wearsGlasses = false, facialHair = false) | ||
| val char9: Character = Character("bilal", "male", "brown", "green", wearsGlasses = false, facialHair = true) | ||
| val char10: Character = Character("lisa", "female", "black", "brown", wearsGlasses = true, facialHair = false) | ||
| val char11: Character = Character("tom", "male", "brown", "blue", wearsGlasses = true, facialHair = false) | ||
| val char12: Character = Character("cheryl", "female", "blonde", "green", wearsGlasses = false, facialHair = false) | ||
| val char13: Character = Character("arei", "male", "brown", "brown", wearsGlasses = false, facialHair = true) | ||
| val char14: Character = Character("kelly", "female", "none", "green", wearsGlasses = false, facialHair = false) | ||
| val char15: Character = Character("tayamul", "male", "brown", "blue", wearsGlasses = false, facialHair = false) | ||
| val char16: Character = Character("elaine", "female", "ginger", "blue", wearsGlasses = false, facialHair = true) | ||
| val char17: Character = Character("roshan", "male", "brown", "blue", wearsGlasses = true, facialHair = false) | ||
| val char18: Character = Character("patricia", "female", "purple", "yellow", wearsGlasses = false, facialHair = false) | ||
| val char19: Character = Character("dave", "male", "none", "yellow", wearsGlasses = false, facialHair = false) | ||
| val char20: Character = Character("bobbiana", "female", "Brown", "Blue", wearsGlasses = true, facialHair = false) | ||
|
|
||
| var gameBoard = Board(List(char1, char2, char3, char4, char5, char6, char7, char8, char9, char10, char11, char12, char13, char14, char15, char16, char17, char18, char19, char20)) | ||
|
|
||
| gameBoard.printCharacterNames() | ||
|
|
||
|
|
||
| //Run example of the game | ||
| //Call methods | ||
|
|
||
| /** game start - random character selected (private), characterlist printed to screen | ||
| * yes / no question asked | ||
| * list filtered based on fulfilment of criteria | ||
| * list reprinted to screen | ||
| * loop through all options, filtering and reprinting each time | ||
| * trigger game end when length of list is 1 ------- could end anytime, defined/earlier in code | ||
| * */ | ||
|
|
||
|
|
||
|
|
||
| // case class GuessWhoGame.Character( | ||
| // name: String, | ||
| // gender: String, | ||
| // hairColor: String, | ||
| // eyeColor: String, | ||
| // wearsGlasses: Boolean, | ||
| // facialHair: Boolean | ||
| // ) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| def createGameBoard(): Board = { | ||
| val characters = CharacterManager.createCharacters() | ||
| val selectedCharacter = CharacterManager.selectRandomCharacter(characters) | ||
| new Board(characters, selectedCharacter) | ||
| } | ||
|
|
||
| def startGame(board: Board): Unit = { | ||
| println("Welcome to the Guess Who game!") | ||
| println("Try to guess the character by asking some questions...") | ||
| println("Available characters:") | ||
| board.printCharacterNames().foreach(println) | ||
|
|
||
| @tailrec | ||
| def playGame(remainingCharacters: List[Character]): Unit = { | ||
| if (board.checkWinCondition(remainingCharacters)) { | ||
| println(s"\nCongratulations, You guessed correctly. The character was ${board.selectedCharacter.name}.") | ||
| } else { | ||
| println("\nRemaining Characters:") | ||
| board.printRemainingCharacters(remainingCharacters).foreach(println) | ||
|
|
||
| val newRemainingCharacters = askQuestion(remainingCharacters) | ||
| playGame(newRemainingCharacters) | ||
| } | ||
| } | ||
|
|
||
| def askQuestion(remainingCharacters: List[Character]): List[Character] = { | ||
| println("\nEnter an attribute (hairColor, eyeColor, gender, wearsGlasses, hasFacialHair) to guess or 'name' to guess the character:") | ||
| val attribute = StdIn.readLine().toLowerCase() | ||
| attribute match { | ||
| case "haircolor" => | ||
| println("Enter the hair color:") | ||
| val hairColor = StdIn.readLine().toLowerCase() | ||
| board.handleQuestion(attribute, Left(hairColor), remainingCharacters) | ||
| case "eyecolor" => | ||
| println("Enter the eye color:") | ||
| val eyeColor = StdIn.readLine().toLowerCase() | ||
| board.handleQuestion(attribute, Left(eyeColor), remainingCharacters) | ||
| case "gender" => | ||
| println("Enter the gender (male/female):") | ||
| val gender = StdIn.readLine().toLowerCase() | ||
| board.handleQuestion(attribute, Left(gender), remainingCharacters) | ||
| case "wearsglasses" => | ||
| println("Does the character wear glasses? (true/false):") | ||
| val wearsGlasses = StdIn.readLine().toLowerCase().toBoolean | ||
| board.handleQuestion(attribute, Right(wearsGlasses), remainingCharacters) | ||
| case "hasfacialhair" => | ||
| println("Does the character have facial hair? (true/false):") | ||
| val hasFacialHair = StdIn.readLine().toLowerCase().toBoolean | ||
| board.handleQuestion(attribute, Right(hasFacialHair), remainingCharacters) | ||
| case "name" => | ||
| println("Enter the name of the character:") | ||
| val nameInput = StdIn.readLine().toLowerCase() | ||
| val newRemainingCharacters = board.handleQuestion(attribute, Left(nameInput), remainingCharacters) | ||
| if (board.checkWinCondition(newRemainingCharacters) && board.selectedCharacter.name.equalsIgnoreCase(nameInput)) { | ||
| println(s"\nCongratulations, You guessed correctly. The character was ${board.selectedCharacter.name}.") | ||
| } else { | ||
| println(s"\nGame over, you guessed incorrectly. The character was ${board.selectedCharacter.name}.") | ||
| } | ||
| newRemainingCharacters | ||
| case _ => | ||
| println("Invalid attribute. Try again.") | ||
| remainingCharacters | ||
| } | ||
| } | ||
|
|
||
| @tailrec | ||
| def replayOrExit(): Unit = { | ||
| println("\nDo you want to play again? (yes/no)") | ||
| val playAgain = StdIn.readLine().toLowerCase() | ||
| playAgain match { | ||
| case "yes" | "y" => | ||
| println("Starting a new game...") | ||
| val newBoard = createGameBoard() | ||
| startGame(newBoard) | ||
| case "no" | "n" => | ||
| println("Thanks for playing Guess Who!") | ||
| case _ => | ||
| println("Invalid response. Please type 'yes' or 'no'.") | ||
| replayOrExit() | ||
| } | ||
| } | ||
|
|
||
| playGame(board.characters) | ||
| replayOrExit() | ||
| } | ||
|
|
||
| val initialBoard = createGameBoard() | ||
| startGame(initialBoard) | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| //package Week2.Monday.AfternoonTaskSolution | ||
| // | ||
| //object Sanctuary extends App { | ||
| // | ||
| // def feedAnimal(animal: Animal) = println(s"You fed ${animal.name} some ${animal.dietType.eats}!") | ||
| // | ||
| // val hedwigTheSnowyOwl = new Owl("Hedwig", "Snowy Owl", 8, 2, "White", 150) | ||
| // val pumbaTheWarthog = new Warthog("Pumbaa", "Common Warthog", 4, "Brown", true) | ||
| // val jeffTheDragonfly = new Dragonfly("Jeff", "Blue Eyed Darner", 1, 12, 10, 1) | ||
| // | ||
| // feedAnimal(hedwigTheSnowyOwl) | ||
| // | ||
| //} | ||
|
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.