Example #1
0
 public void joinRoom(Room room)
 {
     //Main.ludo.Users[ClientBase.myUserListIndex].CurrentRoomID = ClientBase.roomListSelectionID;
     room.RoomAction = "joinRoom";
     room.UserInRoomIDs.Add(ClientBase.myUserListIndex); // Add this user to Room list
     websocket.Send(JsonConvert.SerializeObject(room));
 }
Example #2
0
 // returns the room id which this user has created
 public bool createRoom(Room room)
 {
     room.RoomModeratorUserID = ClientBase.myUserListIndex;
     room.RoomAction = "createRoom";
     websocket.Send(JsonConvert.SerializeObject(room));
     while (!isRoomCreated()); // wait until the room is succesfully created
     return true;
 }
Example #3
0
        public GameHandler(TableLayoutPanel gamePanel, TableLayoutPanel gameFieldPanel, PictureBox dicePictureBox,
            Button rollTheDiceButton, ListBox playerListBox)
        {
            this.gamePanel = gamePanel;
            this.gameFieldPanel = gameFieldPanel;
            this.dicePictureBox = dicePictureBox;
            this.rollTheDiceButton = rollTheDiceButton;
            this.playerListBox = playerListBox;
            this.oldRoom = new Room();

            websocket = new WebSocket("ws://" + ClientBase.serverAdress + PORT_ROUTE);
            websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(handleGame);
            websocket.Open();

            showGamePanel();

            //Room room = new Room();
            //room.RoomAction = "iAmInGame";
            //websocket.Send(JsonConvert.SerializeObject(room));
        }
Example #4
0
        private void handleGame(object sender, MessageReceivedEventArgs args)
        {
            oldRoom = Main.ludo.Rooms[ClientBase.roomListSelectionID];
            //Room room = JsonConvert.DeserializeObject<Room>(args.Message);
            Main.ludo = JsonConvert.DeserializeObject<Ludo>(args.Message);
            Room room = Main.ludo.Rooms[ClientBase.roomListSelectionID];

            if (room.RoomID == ClientBase.roomListSelectionID) // affects this my room?
            {
                updatePlayerListBox();
                updateRollTheDiceButton(room);
                if (room.RoomAction.Equals("diceRolled"))
                {
                    printDiceValue(room.Game.DiceValue);
                }
                if (room.Game.MoveCount > 0)
                {
                    updateTheMap(room);
                }
            }
        }
Example #5
0
 private bool isItMyTurn(Room room)
 {
     if (room.Game.UsersTurnID == ClientBase.myUserListIndex)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #6
0
 public void rollTheDice()
 {
     Room room = new Room();
     room.RoomAction = "rollTheDice";
     websocket.Send(JsonConvert.SerializeObject(room));
 }
Example #7
0
        private void updateTheMap(Room room)
        {
            if (this.gameFieldPanel.InvokeRequired)
            {
                this.gameFieldPanel.Invoke(new MethodInvoker(() => this.updateTheMap(room)));
                return;
            }

            int[,] fields = room.Game.Fields;
            int[,] oldFields = oldRoom.Game.Fields;

            for (int x = 0; x <= 10; x++)
            {
                for (int y = 0; y <= 10; y++)
                {
                    if (fields[x, y] > -1) {
                        foreach (var userID in room.Game.UserInGameIDs)
                        {
                            //createFieldPanel(x, y, userID);

                            Panel fieldPanel = new Panel();
                            fieldPanel.BackgroundImageLayout = ImageLayout.Stretch;

                            if (userID == fields[x, y])
                            {
                                fieldPanel.BackgroundImage = ludo_client.Properties.Resources.green_circle_3d;
                                this.gameFieldPanel.Controls.Add(fieldPanel, x, y);
                            }
                            else if (userID == fields[x, y])
                            {
                                fieldPanel.BackgroundImage = ludo_client.Properties.Resources.yellow_circle_3d;
                                this.gameFieldPanel.Controls.Add(fieldPanel, x, y);
                                MessageBox.Show("Added Yellow @: " + x + " " + y);
                            }
                            else if (userID == fields[x, y])
                            {
                                fieldPanel.BackgroundImage = ludo_client.Properties.Resources.red_circle_3d;
                                this.gameFieldPanel.Controls.Add(fieldPanel, x, y);
                                MessageBox.Show("Added Red @: " + x + " " + y);
                            }
                            else if (userID == fields[x, y])
                            {
                                fieldPanel.BackgroundImage = ludo_client.Properties.Resources.blue_circle_3d;
                                this.gameFieldPanel.Controls.Add(fieldPanel, x, y);
                                MessageBox.Show("Added Blue @: " + x + " " + y);
                            }
                            else
                            {
                                fieldPanel = null;
                            }

                            if (userID == ClientBase.myUserListIndex)
                            {
                                if (fieldPanel != null)
                                {
                                    fieldPanel.Click += new EventHandler(fieldPanel_Click);
                                }
                            }
                        }
                    }
                }
            }

            //Panel panel = (Panel)this.gameFieldPanel.GetControlFromPosition(0, 0);
            //panel.BackgroundImage = ludo_client.Properties.Resources.green_circle_3d;
        }
Example #8
0
        private void updateRollTheDiceButton(Room room)
        {
            if (this.rollTheDiceButton.InvokeRequired)
            {
                this.rollTheDiceButton.Invoke(new MethodInvoker(() => this.updateRollTheDiceButton(room)));
            }

            if (isItMyTurn(room))
            {
                this.rollTheDiceButton.Enabled = true;
            }
            else
            {
                this.rollTheDiceButton.Enabled = false;
            }
        }
Example #9
0
 private void createRoomButton_Click(object sender, EventArgs e)
 {
     CreateRoomForm createRoomForm = new CreateRoomForm();
     createRoomForm.ShowDialog();
     if (createRoomForm.DialogResult == DialogResult.OK)
     {
         Room room = new Room();
         room.RoomName = ClientBase.createRoomName;
         roomHandler.createRoom(room);
         joinRoom();
     }
 }
Example #10
0
        public void leaveRoom(Room room)
        {
            room.UserInRoomIDs.Remove(ClientBase.myUserListIndex);
            if (Main.ludo.Users[ClientBase.myUserListIndex].StatusInRoom)
            {
                // When the User was ready remove him from readyUsersInRoomIDs List
                room.ReadyUsersInRoomIDs.Remove(ClientBase.myUserListIndex);
            }
            Main.ludo.Users[ClientBase.myUserListIndex].CurrentRoomID = -1; // set current room id back to default
            room.RoomAction = "leaveRoom";
            websocket.Send(JsonConvert.SerializeObject(room));

            // Hide all room action buttons when the user leaves the room
            updateButton(this.startButton, false, false);
            updateButton(this.readyButton, false, false);
        }
Example #11
0
 public void setStart(Room room)
 {
     room.RoomAction = "setStart";
     websocket.Send(JsonConvert.SerializeObject(room));
 }
Example #12
0
 public void setReady(Room room)
 {
     room.RoomAction = "setReady";
     if (Main.ludo.Users[ClientBase.myUserListIndex].StatusInRoom)
     {
         // when he was ready before remove him from readyUsersInRoomIDs List
         room.ReadyUsersInRoomIDs.Remove(ClientBase.myUserListIndex);
         updateButton(this.backButton, true, true);
     }
     else
     {
         // when he was NOT ready before add him to readyUsersInRoomIDs List
         room.ReadyUsersInRoomIDs.Add(ClientBase.myUserListIndex);
         updateButton(this.backButton, true, false);
     }
     websocket.Send(JsonConvert.SerializeObject(room));
 }