Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ coding For this assignment you will be creating the lobby for a game. In normal game lobbies players will connect to the lobby and

C++ coding

For this assignment you will be creating the lobby for a game. In normal game lobbies players will connect to the lobby and then signal for the game to start. Although this is normally done over network, we will be simulating this using only a local computer. To do this project you will need three things: a Lobby class a Player class and a Player_state enum The lobby class has two jobs: to hold all the players and to check if they are all ready to start the game. So, this is what you will need for the Lobby class. Instance variables representing lobby_id Note that this id MUST be unique to the lobby, so if we make a bunch of lobbies at the same time none of them should have the same id. The list of players. The maximum size of the lobby. The minimum number of players required to start the game. Constructor initializes lobby_id should initialize the min number of players and the max size of the lobby the list of players is initially empty Instance functions check_if_all_players_ready() checks if all the players are ready check_if_ready_to_start_game() checks if the number of players is within the specified range, and if all the players are ready start_game() starts the game and you just need to print Game Started join_game(Player player_id) connects a player to the game and adds the player to the list of players. leave_game(Player player_id) disconnects a player from the game and removes the player from the list of players. The Player class represents a player for our lobby, so it needs to have a players state. Instance variables representing player_id like the lobby id this needs to be unique for this player, so any 2 players will never have the same ids. lobby_id this is the lobby id of the lobby we are currently connected to. If we are not connected to a lobby this should be -1. player_state this value holds the state of the player. It is a Player_state enum so it can be several different things to consider (read the next part to figure out what this holds). Constructor this will initialize lobby_id, player_id, and player_state 2 player_state is initially set to Disconnected lobby_id should be initialized to -1 Instance functions ready_player() set the player state to Ready; must be connected to a lobby unready_player() set the player state to Not_ready; must be connected to a lobby connect_to_lobby(Lobby) connects to the lobby. This really means: set lobby_id set player_state to Connected call the join_game function in the given lobby disconnect_from_lobby(Lobby) disconnects from the lobby. This really means: set lobby_id to -1 set player_state to Disconnected call the leave_game function in the given lobby Player_state is an enum that we will use in our player class to show what state our player is in. It will have these enumerations: Connected means that a user has connected to the lobby but hasnt stated whether it is ready or not Disconnected means that this player is not connected to a lobby Ready means that a player is connected and ready Not_ready means that the player is connected and not ready

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions