private void updateKeyToSend() { try { keyToSend = keyHistory.Pop(); } catch (Exception) { keyToSend = KeyConfiguration.KEYS.NON_PRESSED; } }
private void sendKeyToServer(IPacmanServer server, KeyConfiguration.KEYS key, String clientName, int attempt) { try { server.sendKey(keyToSend, pacmanName); } catch (Exception) { if (attempt <= KeyConfiguration.MAX_ATTEMPTS) { Thread.Sleep(ConnectionLibrary.INTERVAL_RESEND); sendKeyToServer(server, key, clientName, attempt++); } } }
public void sendKey(KeyConfiguration.KEYS key, string player) { Monitor.Enter(this); try { moves.Add(player, key); if (moves.Count >= clients.Count) { sendMovesToClients(moves); moves.Clear(); } } catch(Exception) { //DO NOTHING } Monitor.Exit(this); }
private void movePacman(String pacmanName, KeyConfiguration.KEYS key) { PictureBox pacman1 = pacmans[pacmanName]; //move player switch (key) { case KeyConfiguration.KEYS.LEFT_KEY: pacman1.Image = Properties.Resources.Left; if (pacman1.Left > (boardLeft)) { pacman1.Left -= speed; } break; case KeyConfiguration.KEYS.RIGHT_KEY: pacman1.Image = Properties.Resources.Right; if (pacman1.Left < (boardRight)) { pacman1.Left += speed; } break; case KeyConfiguration.KEYS.UP_KEY: pacman1.Image = Properties.Resources.Up; if (pacman1.Top > (boardTop)) { pacman1.Top -= speed; } break; case KeyConfiguration.KEYS.DOWN_KEY: pacman1.Image = Properties.Resources.down; if (pacman1.Top < (boardBottom)) { pacman1.Top += speed; } break; } }
public void addKey(KeyConfiguration.KEYS key) { keyHistory.Push(key); }