Socket.io switch between game states - javascript

I'm making a multiplayer game in Node.js using Socket.js. Between the games I want users to be able to place their bets before a counter is ticking down. After that an incrementing number should pop up on the screen which eventually stops and then the counter and period to place bets comes back. I'm struggling to find anything on how to documentation or help on how to do something like this, where you are switching states/periods in a game.

Related

Best way to orchestrate a sequence of events based on user input in a browser game?

I really struggled to phrase the title, which shows how lost I am. I consider myself a good web developer, but structures like this break my head :D
–––
The game
I'm remaking a little ear-training game of mine (http://twelvenotes.co/) with Nuxt3.
The game features 8 rounds of questions. Each round plays 2 musical notes and the player must tell which one is higher.
The interactive concept for the new version has changed. The game does not start automatically, but waits for a "Start now" input from the Playeyr. Each round the two notes play automatically in sequence. The Player has two options now:
Click on one note to lock in the answer to which note he thinks is higher
Replay the two notes in the same sequence, but lose "1 life" (or "extra listen") of 3
Answering a question shows an animation indicating if Player is right or wrong. After the animation is completed the game should move to the next round automatically and also start the round automatically, after the animated transition to the new round is done.
The whole game and each round individually is timed with a visible stop watch which will influence the final score.
After 8 rounds the Player is presented with an end screen showing the performance and a score.
The problem
As of right now, Creating the array of playable rounds, locking in the answer, moving to the next round, playing notes, replaying notes are all separate functions.
Now to the question: Whats the best way to control all these functions? Especially with timeouts needed for animations and playing notes etc. it's hard to structure which function does what and who tells it when to do it.
Who controls when we move to the next round and when we will start that round? Moving to the next round should only be possible when the current round has been answered. But should all of this be the job of moveToNextRound()? And who actually starts the round as in playing the notes, starting a stopwatch for this round etc. – And who stops the timer of the played round when the round has been answered? Is that a job for moveToNextRound() or startRound(roundIndex) or is that the job of a new function finishRound() - but who then calls finishRound()? Or should it be finishCurrentRound(). When a question is answered we need time for an animation telling the player if his answer was right or not and so on and so forth...
... I guess you get the picture. Structuring this is not easy for me. While doing it I constantly go back and forth between which function does what.
The question
Can you guys point me to best practices or resources in that field? Only thing I can think of googling is: "Gamecontroller"... which obviously only gives you results for gaming console gamepads.
Thanks!

Connecting players' local games together

I'm looking for a special answer that i can't find anywhere and i need your help/ideas:
The situaton:
I'm making a mobile web-game that is played on mobile phones. Every player has its own version and profile with levels etc. It is a roulette game so i want if a player gets a card it gets xp and the other players need to get xp as well. But as of now there is no way of syncing game data from one player to other players.
All roulette cards are stored in one big array and if a card is turned the script chooses a random one from the stack.
I was self thinking of some kind of code that everyone enters at the start of the game, and it contains the numbers of idk 20 cards in the array and so the game of all players will show the same card if they click next. But i dont know how to decode this and it is a bit irritating to enter such big code everytime you want to play.
P.s. i do not want to use a third party library or nodejs or something like that. Just javascript.
The "app/game" is hosted on a website that every player loads on their own phone. And game save data is stored in localstorage.
Can you please help? I dont have code to show. That is not relevant here.
I fixed it.
I used QR Codes instead. One qr code generator for the host and a qr code reader for the other players.
Search google for qr code reader js and you'll find it
thnx!

Intervals and server load

Okay, me and a couple of friends had the idea to make a website where you can earn some credits and later on wager these credits, all fun and stuff. Everything works but now we are stuck on a gamemode we thought of.
(BustABit Solo) How the gamemode works is a player chooses a wager amount, then starts the game. When the player has clicked start on the backend there will be a 'crash number' generated on which the game will end. Then on the browser a counter will count up from 1.00x to infinite. Let's say the server decided to crash the game on 2.00x. If a player clicked the cashout button on let's say 1.50x, then he'll get 1.50x (150%) his wager.
Now where the problem lays, the server needs to keep track on what number the player cashs' out, therefor we need some sort of interval (or do we?) to keep track on what number the crash is when the player clicks the cashout button. But there could be over two hundred people at the same time playing which all would need their own interval (?), wouldn't it be a giant load on the server? How do we go about this correctly?

Multi-game round-robin tournament

Each year I am part of a group that hosts a "Lawn Game Olympics." 6 different lawn games (boccee, ladder golf, washer toss etc...) and every year a different amount of teams shows up. The first year was an unbalanced schedule and the drama that ensued was ridiculous, so i've set out to create a balanced schedule with a program that we can just punch in the amount of teams.
The issue is everyone wants to play eachother, or everyone wants to play the same game the same amount of times with a great effort and playing every team.
The traditional round robin formula only works for 13 teams with 1 bye, as it just happens to rotate around 6 games. Using the technique below, its simple (with 14 being a bye, and each line being a different game)
13 teams never happens, just my luck, and i cannot figure anything out for any other amount of teams. I have seemingly tried everything. The closest i've gotten is using combinatorics to generate all the matchups then try to brute force them together tracking whos played who and what etc.. but that still never works before crashing.
The ideal scenario, is every team plays each game twice (12 games per team). The other scenario would be each team playing eachother, with what games they played being luck of the draw, as long as each game is played at least 1 time, and no game is played 3 times when another has been played once.
Does anyone know if this is even possible? If it is, can i get a point in the right direction?

creating a blackjack game using javascript, html and css only

I am coding a mobile app using PhoneGap, and I am only using HTML and JavaScript. so far, i have made all of the betting functions, such as starting an initial bet, buttons to increase or decrease the bet, and the functions that are called when the player wins, loses, or gets blackjack. My problem is with the deck.
It might be helpful to know what I called my functions, I don't know, but here they are anyway:
function win() adds the value in the bet to the total money.
function lose() subtracts the value that was bet from the total money.
function blackjack() adds one and a half times the value bet to the total money, and I used the Math.floor() on that one.
So with that in mind, I have two questions.
I want to have a deck that is just like a physical deck. I might be a little picky, but i want it so that if a card is shown, it will not be called again until all 52 cards are used, or the deck is shuffled. The cards can come out at random, i don't care as long as the cards are not repeated. also, how would you separate the piles that are dealt?
For example, one pile is the user, the other is the dealer. i kinda think this is needed because we will use the card values to add and decide who has won.
This next part is not required, but would be nice.
Would there be a way that I could add an image to the card that is chosen, so that the player can visually see the card that is drawn?
Using JavaScript, html and css __ONLY__, could I save a value to the apps internal memory or something? What I'm trying to achieve is that when, the player closes the app, the amount of money that is their "winnings" will be saved, and shown the next time they open the app.
I also have one more question, but this one is not part of the app.
Do anyone know how old you have to be to sign up for a Google developer account? I want to publish my app when I finish, but I'm only 17 and I don't know if I'm allowed to create a Google developer account to post my app on Google play because of my age.
To store some data in the client side, you can use the localStorage in a web browser, maybe it is not the best method to work in Android, but ut works.
localStorage.setItem("key", "value");
localStorage.getItem("key");
there you can store info

Categories

Resources