-
Notifications
You must be signed in to change notification settings - Fork 3
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 #55 from JoelBerglund05/CreateGames
Create games
- Loading branch information
Showing
4 changed files
with
122 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<button id="createGame">Sök motståndare</button> | ||
<button id="tmp">wdojwepdok</button> | ||
<script src="./js/main.js" type="module"></script> | ||
</body> | ||
</html> |
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,31 @@ | ||
export default class GameHandeler { | ||
constructor() {} | ||
async CreateGame(dataBase) { | ||
const activeGames = await dataBase.GetAllActiveGames(); | ||
const user = await dataBase.GetUser(); | ||
|
||
let foundEmptyGame = false; | ||
activeGames.forEach(async (emptyId) => { | ||
if ( | ||
emptyId.userId2 === null && | ||
!foundEmptyGame && | ||
emptyId.userId1 !== user.id | ||
) { | ||
console.log( | ||
"Stämmer detta? ", | ||
emptyId.userId1 !== user.id, | ||
user.id, | ||
emptyId.userId1, | ||
); | ||
foundEmptyGame = true; | ||
emptyId.userId2 = user.id; | ||
await dataBase.UpdateSpesificActiveGame(emptyId.id); | ||
} | ||
}); | ||
|
||
if (!foundEmptyGame) { | ||
dataBase.CreateGame(); | ||
console.log("yeppi!"); | ||
} | ||
} | ||
} |
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