async void move() { if (selectedPoints.Count < 2) { return; } CHServerResponse resp = await CheckersServer.server.movePiece(selectedPoints[0], selectedPoints[1]); if (resp.worked) { this.isLocked = resp.info.locked; if (this.isLocked && selectedPoints.Count >= 2) { selectedPoints.RemoveAt(0); } if (resp.info.stillTurn) { } else { isLocked = false; isTurn = false; } clearPoints(); updateGame(); } else { clearPoints(); broadcastError(resp); } }
async void leaveGame() { CHServerResponse resp = await CheckersServer.server.leaveGame(); if (resp.worked) { transitionFromGameToLobby(); } else { broadcastError(resp); } }
async void createGame() { CHServerResponse resp = await CheckersServer.server.createGame(); if (resp.worked) { transitionFromLobbyToGame(); } else { broadcastError(resp); } }
async void signIn() { CHServerResponse resp = await CheckersServer.server.logIn(); if (resp.worked) { transitionFromSignInToLobby(); } else { broadcastError(resp); } }
async void signUp() { CHServerResponse resp = await CheckersServer.server.signUp(); if (resp.worked) { MessageBox.Show("You're good to go! Try logging in now."); rbSignIn.Checked = true; } else { broadcastError(resp); } }
async void endTurn() { CHServerResponse resp = await CheckersServer.server.submitEndTurn(); if (resp.worked) { isLocked = false; isTurn = false; clearPoints(); updateGame(); } else { broadcastError(resp); } }
async void joinGame() { string gameId = ""; gameId = lboxGameList.SelectedItem.ToString(); CHServerResponse resp = await CheckersServer.server.joinGame(gameId); if (resp.worked) { transitionFromLobbyToGame(); } else { broadcastError(resp); } }
async void updateGame() { CHServerResponse resp = await CheckersServer.server.getGameSummary(); if (resp.worked) { lastSummary = resp.info.summary; Bitmap newBoard = drawBoard(resp.info.summary); pbBoard.Image = newBoard; lblGameID.Text = "Game ID: " + resp.info.summary.gameid; List <dynamic> players = resp.info.summary.players; List <ListViewItem> newItems = new List <ListViewItem>(); foreach (var eachPlayer in players) { ListViewItem newItem = new ListViewItem(new string[] { eachPlayer["turn"] ? ">" : "", eachPlayer["name"], eachPlayer["score"] + "" }); newItems.Add(newItem); } listViewPlayers.Items.Clear(); listViewPlayers.Columns.Clear(); listViewPlayers.Columns.Add("Turn"); listViewPlayers.Columns.Add("Name"); listViewPlayers.Columns.Add("Score"); foreach (ListViewItem it in newItems) { listViewPlayers.Items.Add(it); } isTurn = resp.info.summary.isturn; if (isTurn && !prevIsTurn) { playSound(); } modifyUIForPlay(); prevIsTurn = isTurn; } else { broadcastError(resp); } }
public void broadcastError(CHServerResponse resp) { string s = resp.info.error; if (!isShowingMessage) { isShowingMessage = true; //DialogResult x = MessageBox.Show(s + "\nWould you like to keep running the application?", "An error occurred.",MessageBoxButtons.YesNo); MessageBox.Show(s); /*if(x == DialogResult.No) * { * //this.Close(); * } * else * {*/ this.isShowingMessage = false; //} } Debug.WriteLine(s); }
public async Task <CHServerResponse> getGamesList() { dynamic getTask; dynamic getTaskResult; dynamic newInfo = new ExpandoObject(); CHServerResponse myResponse; string actionName = "listGames"; getTask = doGetRequest(actionName); try { getTaskResult = await getTask; newInfo.gamesList = getTaskResult.gameslist; myResponse = new CHServerResponse(true, newInfo); } catch (Exception e) { newInfo.error = "Failed to fetch games list: " + e.Message; myResponse = new CHServerResponse(false, newInfo); } return(myResponse); }
public async Task <CHServerResponse> movePiece(Point p1, Point p2) { dynamic postTask; dynamic postTaskResult; dynamic newInfo = new ExpandoObject(); CHServerResponse myResponse; string actionName = "submitMove"; Dictionary <string, string> theParams = new Dictionary <string, string>(); theParams["x1"] = p1.X + ""; theParams["y1"] = p1.Y + ""; theParams["x2"] = p2.X + ""; theParams["y2"] = p2.Y + ""; postTask = doPostRequest(actionName, theParams, true); try { postTaskResult = await postTask; newInfo.valid = postTaskResult.valid; if (!newInfo.valid) { newInfo.error = postTaskResult.movemessage; myResponse = new CHServerResponse(false, newInfo); } else { newInfo.stillTurn = postTaskResult.stillturn; newInfo.message = postTaskResult.movemessage; newInfo.locked = postTaskResult.islockedin; myResponse = new CHServerResponse(true, newInfo); } } catch (Exception e) { newInfo.error = "Failed to get submit move: " + e.Message; myResponse = new CHServerResponse(false, newInfo); } return(myResponse); }
async void updateLobby() { CHServerResponse resp = await CheckersServer.server.getGamesList(); if (resp.worked) { List <object> gamesList = resp.info.gamesList; int selectedIndex = lboxGameList.SelectedIndex; lboxGameList.Items.Clear(); foreach (object o in gamesList) { lboxGameList.Items.Add(o.ToString()); } if (selectedIndex < gamesList.Count) { lboxGameList.SelectedIndex = selectedIndex; } } else { broadcastError(resp); } }
public async Task <CHServerResponse> submitEndTurn() { dynamic postTask; dynamic postTaskResult; dynamic newInfo = new ExpandoObject(); CHServerResponse myResponse; string actionName = "endMove"; Dictionary <string, string> theParams = new Dictionary <string, string>(); postTask = doPostRequest(actionName, theParams, true); try { postTaskResult = await postTask; newInfo.success = postTaskResult.success; myResponse = new CHServerResponse(true, newInfo); } catch (Exception e) { newInfo.error = "Failed to end turn: " + e.Message; myResponse = new CHServerResponse(false, newInfo); } return(myResponse); }
public async Task <CHServerResponse> signUp() { dynamic postTask; dynamic postTaskResult; dynamic newInfo = new ExpandoObject(); CHServerResponse myResponse; string actionName = "createPlayer"; Dictionary <string, string> theParams = new Dictionary <string, string>(); postTask = doPostRequest(actionName, theParams, true); try { postTaskResult = await postTask; newInfo.playerId = postTaskResult.playerid; myResponse = new CHServerResponse(true, newInfo); } catch (Exception e) { newInfo.error = "Failed to sign up: " + e.Message; myResponse = new CHServerResponse(false, newInfo); } return(myResponse); }
public async Task <CHServerResponse> getGameSummary() { dynamic postTask; dynamic postTaskResult; dynamic newInfo = new ExpandoObject(); CHServerResponse myResponse; string actionName = "getGameSummary"; Dictionary <string, string> theParams = new Dictionary <string, string>(); postTask = doPostRequest(actionName, theParams, true); try { postTaskResult = await postTask; newInfo.summary = postTaskResult.summary; myResponse = new CHServerResponse(true, newInfo); } catch (Exception e) { newInfo.error = "Failed to get game info: " + e.Message; myResponse = new CHServerResponse(false, newInfo); } return(myResponse); }
public async Task <CHServerResponse> joinGame(string gameId) { dynamic postTask; dynamic postTaskResult; dynamic newInfo = new ExpandoObject(); CHServerResponse myResponse; string actionName = "joinGame"; Dictionary <string, string> theParams = new Dictionary <string, string>(); theParams.Add("gameId", gameId); postTask = doPostRequest(actionName, theParams, true); try { postTaskResult = await postTask; newInfo.gameId = postTaskResult.gameid; myResponse = new CHServerResponse(true, newInfo); } catch (Exception e) { newInfo.error = "Failed to join game: " + e.Message; myResponse = new CHServerResponse(false, newInfo); } return(myResponse); }