Skip to content

Commit 6882b7b

Browse files
committed
code clean up
1 parent b8e21bb commit 6882b7b

File tree

5 files changed

+129
-2
lines changed

5 files changed

+129
-2
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
exports.handler = async( event ) => {
2+
3+
const getSuit = ( suitId ) => {
4+
switch ( suitId ) {
5+
case 0:
6+
return "diams";
7+
case 1:
8+
return "hearts";
9+
case 2:
10+
return "spades";
11+
case 3:
12+
return "clubs";
13+
default:
14+
throw "only 4 suits";
15+
}
16+
};
17+
18+
const getRank = ( rankId ) => {
19+
if ( rankId > 13 || rankId < 1 )
20+
throw "invalid rank " + rankId;
21+
switch ( rankId ) {
22+
case 11:
23+
return "J";
24+
case 12:
25+
return "Q";
26+
case 13:
27+
return "K";
28+
case 1:
29+
return "A";
30+
default:
31+
return rankId.toString();
32+
}
33+
};
34+
35+
const buildDeck = () => {
36+
let deck = [];
37+
38+
for ( let suit = 0; suit < 3; suit++ ) {
39+
for ( let value = 1; value <= 13; value++ ) {
40+
deck.push( {
41+
suit: getSuit( suit ),
42+
rank: getRank( value ),
43+
value: value,
44+
visible: false
45+
} );
46+
}
47+
}
48+
49+
return deck;
50+
};
51+
52+
const getCards = () => {
53+
54+
let deck = buildDeck();
55+
deck.sort( ( a, b ) => 0.5 - Math.random() );
56+
57+
let cards = [];
58+
59+
for ( let i = 0; i < 6; i++ ) {
60+
let card = deck[i];
61+
62+
if ( i == 0 )
63+
card.visible = true;
64+
65+
card.order = i;
66+
67+
cards.push( card );
68+
}
69+
return cards;
70+
};
71+
72+
const response = {
73+
statusCode: 200,
74+
body: JSON.stringify( getCards() )
75+
};
76+
return response;
77+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
exports.handler = async( event ) => {
2+
3+
const getHighScores = () => {
4+
5+
const scores = [];
6+
7+
scores.push( {
8+
player: "Roger Rabbit",
9+
score: 100
10+
} );
11+
12+
scores.push( {
13+
player: "Donald Duck",
14+
score: 50
15+
} );
16+
17+
scores.push( {
18+
player: "Goofy",
19+
score: 40
20+
} );
21+
22+
scores.push( {
23+
player: "John Daly",
24+
score: 30
25+
} );
26+
27+
scores.push( {
28+
player: "Mike Tyson",
29+
score: 20
30+
} );
31+
32+
return scores;
33+
34+
};
35+
36+
const response = {
37+
statusCode: 200,
38+
body: JSON.stringify( getHighScores() ),
39+
};
40+
return response;
41+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports.handler = async ( event ) => {
2+
3+
const response = {
4+
statusCode: 200,
5+
body: JSON.stringify( {
6+
player: event.player,
7+
score: event.score
8+
} ),
9+
};
10+
return response;
11+
};

src/Components/Card.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react";
2-
32
import "../cards.css";
43

54
const Card = ( { card } ) => {

src/Components/GameHome.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react";
2-
32
import { Row, Col, Table, Button } from "react-bootstrap";
43

54
const GameHome = ( { newGameClick, highScores, submitHighScore } ) => {

0 commit comments

Comments
 (0)