private void updateState() { try { if (proxy == null) { proxy = new GamePlay.GamePlayClient(new InstanceContext(this)); } GamePlay.GameState state = proxy.getGameState(gameId); GamePlay.Player tempPlayer = proxy.getActivePlayer(gameId); string nickname = ""; //int troops = 0; if (tempPlayer != null) { setState(tempPlayer.nickname, state, tempPlayer.alive); //troops = tempPlayer.troopsToPlace; } else { setState(nickname, state, true); } } catch (Exception error) { MessageBox.Show(error.Message); } }
private void updateChatListBox() { try { if (proxy == null) { proxy = new GamePlay.GamePlayClient(new InstanceContext(this)); } String[] messages = proxy.getAllMessages(gameId); lbChat.Items.Clear(); foreach (String s in messages) { if (s.Length > 33) { // split into two lines string sub1 = s.Substring(0, 33); string sub2 = s.Substring(33); lbChat.Items.Add(sub1); lbChat.Items.Add(sub2); } else { lbChat.Items.Add(s); } } } catch (Exception error) { MessageBox.Show(error.Message); } }
private void sendMessage() { if (tbMessage.Text == "") { return; } try { if (proxy == null) { proxy = new GamePlay.GamePlayClient(new InstanceContext(this)); } if (proxy.submitMessage(gameId, tbMessage.Text)) { // message submitted succesfully tbMessage.Text = ""; updateChatListBox(); } else { MessageBox.Show("Something went wrong, message was not sent..."); } } catch (Exception error) { MessageBox.Show(error.Message); } }
private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { //Console.WriteLine(String.Format("mouse x: {0}, mouse y: {1}", e.X, e.Y)); //Console.WriteLine(String.Format("{0}, name{1}, {2}, {3}, 0", tempId, tempId, e.X, e.Y)); //tempId++; GamePlay.Territory tempTerritory = getTerritoryUserClickedOn(e.X, e.Y); if (tempTerritory == null) { return; } // update form //lblCountry.Text = tempTerritory.name; //lblContinent.Text = tempTerritory.continentId.ToString(); //lblId.Text = tempTerritory.id.ToString(); //// check if territory is owned by a player //if (tempTerritory.controlledByPlayer == null) //{ // lblOwner.Text = "none"; // //return; //} //else //{ // lblOwner.Text = tempTerritory.controlledByPlayer.nickname; //} try { if (proxy == null) { proxy = new GamePlay.GamePlayClient(new InstanceContext(this)); } if (yourTurn) { if (proxy.getGameState(gameId) == GamePlay.GameState.attack) { // attack phase and your turn // two territories need to be selected if (firstClick == null) { firstClick = proxy.getTerritory(gameId, tempTerritory.id); if (firstClick == null) { return; } // check if it is your territory if (firstClick.controlledByPlayer.nickname != tbNickName.Text) { firstClick = null; } } else { // first click should be your territory secondClick = proxy.getTerritory(gameId, tempTerritory.id); if (secondClick == null) { return; } if (secondClick.controlledByPlayer.nickname == tbNickName.Text) { firstClick = secondClick; secondClick = null; } else { // attack! proxy.attackTerritory(gameId, firstClick.id, secondClick.id); updateTerritories(); } } } else { // not attack phase, only one territory need to be selected proxy.selectTerritory(gameId, tempTerritory.id); updateTerritories(); } } } catch (Exception error) { MessageBox.Show(error.Message); } }
private void joinGame(GamePlay.Player.playerColor color) { try { if (proxy == null) { proxy = new GamePlay.GamePlayClient(new InstanceContext(this)); } // check that nickname doesn't already exist string nickname = tbNickName.Text; // use correct color bool result = proxy.signIntoGame(gameId, nickname, color); if (result) { tbNickName.Enabled = false; updateChatListBox(); } else { MessageBox.Show("logging into the game failed. Might be that the game is full. That you forgot to type in a nickname or that the nickname is already taken. (Remember that the nickname should be between 3 and 20 characters!"); } } catch (Exception error) { MessageBox.Show(error.Message); } getTerritoriesFromService(); getPlayersFromService(); updatePlayers(); updateTerritories(); }
private void getTerritoriesFromService() { try { if (proxy == null) { proxy = new GamePlay.GamePlayClient(new InstanceContext(this)); } territories = proxy.getAllTerritories(gameId).ToList(); } catch (Exception error) { MessageBox.Show(error.Message); } }