-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from vmolero/develop
Add all the minimum functionality as original game
- Loading branch information
Showing
10 changed files
with
187 additions
and
62 deletions.
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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as React from 'react'; | ||
import { BoardComponent, BoardStateInterface, JsonStateInterface } from './BoardComponent'; | ||
|
||
class SimpleBlackJack extends React.Component { | ||
private readonly KEY: string = 'blackjack'; | ||
|
||
setItem(key: string, data: string) { | ||
localStorage.setItem(key, data); | ||
} | ||
|
||
getItem(key: string): JsonStateInterface { | ||
const jsonState: string | null = localStorage.getItem(key); | ||
if (jsonState !== null) { | ||
return JSON.parse(jsonState); | ||
} | ||
return { | ||
handNumber: 0, | ||
playerScore: 0, | ||
houseScore: 0, | ||
}; | ||
} | ||
|
||
saveGame(state: BoardStateInterface) { | ||
let jsonSate: JsonStateInterface = { | ||
handNumber: state.handNumber, | ||
playerScore: state.playerScore, | ||
houseScore: state.houseScore, | ||
}; | ||
this.setItem(this.KEY, JSON.stringify(jsonSate)); | ||
} | ||
|
||
loadGame(): JsonStateInterface { | ||
return this.getItem(this.KEY); | ||
} | ||
|
||
handleSaveGame(state: BoardStateInterface): boolean { | ||
try { | ||
this.saveGame(state); | ||
} catch (errorOnSave) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
handleResetGame(): boolean { | ||
try { | ||
localStorage.clear(); | ||
} catch (errorOnSave) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="container"> | ||
<header id="header"> | ||
<h1> | ||
<span>simple</span>BlackJack | ||
</h1> | ||
</header> | ||
<BoardComponent | ||
jsonState={this.loadGame()} | ||
onSaveGameClick={(state: BoardStateInterface) => this.handleSaveGame(state)} | ||
onResetGameClick={() => this.handleResetGame()} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default SimpleBlackJack; |
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
Oops, something went wrong.