Skip to content

Commit

Permalink
Abstracts into classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ASproson committed Aug 13, 2024
1 parent a66e599 commit da0bed6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 48 deletions.
54 changes: 6 additions & 48 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
export const characterList = [
{
name: 'AAAA',
hp: 30,
},
{
name: 'BBBB',
hp: 25,
},
{
name: 'CCCC',
hp: 28,
},
{
name: 'DDDD',
hp: 33,
},
];
import { CharacterSheet } from './components/CharacterSheet';
import { PlayerMenu } from './components/PlayerMenu';
import { characterList } from './library/Characters';

function App() {
const characters = characterList.map(({ name, hp }, idx) => {
return <CharacterSheet key={idx} name={name} hp={hp} />;
const characterSheetList = characterList.map(({ name, hp }) => {
return <CharacterSheet key={name} name={name} hp={hp} />;
});

return (
Expand Down Expand Up @@ -49,38 +34,11 @@ function App() {
</div>

<div className="flex items-end h-full">
<div className="h-full w-[75px] p-1 pt-2">{characters}</div>
<div className="h-full w-[75px] p-1 pt-2">{characterSheetList}</div>
</div>
</div>
</div>
);
}

export default App;

interface Character {
name: string;
hp: number;
}

export const CharacterSheet = ({ name, hp }: Character) => {
return (
<div className="p-1 border-2 border-white rounded-lg">
<p className="uppercase font-bold">{name}</p>
<p className="uppercase font-bold">hp</p>
<p className="text-right">{hp}</p>
</div>
);
};

export const PlayerMenu = () => {
return (
<div className="flex flex-col justify-center flex-wrap font-bold text-lg uppercase p-4 h-full">
<p>Fight</p>
<p>Magic</p>
<p>Drink</p>
<p>Item</p>
<p>Run</p>
</div>
);
};
14 changes: 14 additions & 0 deletions src/components/CharacterSheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface Character {
name: string;
hp: number;
}

export const CharacterSheet = ({ name, hp }: Character) => {
return (
<div className="p-1 border-2 border-white rounded-lg">
<p className="uppercase font-bold">{name}</p>
<p className="uppercase font-bold">hp</p>
<p className="text-right">{hp}</p>
</div>
);
};
11 changes: 11 additions & 0 deletions src/components/PlayerMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const PlayerMenu = () => {
return (
<div className="flex flex-col justify-center flex-wrap font-bold text-lg uppercase p-4 h-full">
<p>Fight</p>
<p>Magic</p>
<p>Drink</p>
<p>Item</p>
<p>Run</p>
</div>
);
};
23 changes: 23 additions & 0 deletions src/library/Characters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
interface CharacterClass {
name: string;
hp: number;
img: string;
attack: number;
critChance: number;
}
class CharacterGenerator implements CharacterClass {
constructor(
public name: string,
public hp: number,
public img: string,
public attack: number,
public critChance: number
) {}
}

export const characterList = [
new CharacterGenerator('AAAA', 30, '/images/AAAA.png', 10, 0.2),
new CharacterGenerator('BBBB', 25, '/images/BBBB.png', 12, 0.3),
new CharacterGenerator('CCCC', 28, '/images/CCCC.png', 8, 0.25),
new CharacterGenerator('DDDD', 33, '/images/DDDD.png', 15, 0.15),
];

0 comments on commit da0bed6

Please sign in to comment.