public Piecetype GetPieceType(Piecetype pieceType) { var result = db.Piecetypes .FirstOrDefault(d => d.EnglishName == pieceType.EnglishName && d.PersianName == pieceType.PersianName); return(result); }
private void Form1_MouseUp(object sender, MouseEventArgs e) { if (!Win) { Piece piece = b.placepeice(e.X, e.Y, nexttype); if (piece != null) { this.Controls.Add(piece); dynamic.Add(piece); if (b.Winner == Piecetype.BLACK) { MessageBox.Show("BLACK WIN!"); Win = true; } else if (b.Winner == Piecetype.WHITE) { MessageBox.Show("WHITE WIN!"); Win = true; } if (nexttype == Piecetype.BLACK) { nexttype = Piecetype.WHITE; } else { nexttype = Piecetype.BLACK; } } } }
public Piece placepeice(int x, int y, Piecetype type) { Point temp = findplaced(x, y); Point ans = convertToForm(new Point(x, y)); //MessageBox.Show(temp.X + " " + temp.Y); if (temp == error) { return(null); } //根據 piecetype 產生對應的旗子 if (pieces[temp.X, temp.Y] != null)//已經有旗子 { return(null); //已經有棋子了 } lastPlaced = temp; checkWinner(); if (type == Piecetype.BLACK) { pieces[temp.X, temp.Y] = new Black(ans.X, ans.Y); current = Piecetype.WHITE; } else { pieces[temp.X, temp.Y] = new White(ans.X, ans.Y); current = Piecetype.BLACK; } return(pieces[temp.X, temp.Y]); }
public ActionResult UpdatePieceType(int ID, string EnglishName, string PersianName, int page) { if (Session["AdminUser"] == null) { return(RedirectToAction("Login", "User")); } var piecetype = new Piecetype(); piecetype.EnglishName = EnglishName; piecetype.PersianName = PersianName; var result = ""; if (db.ExistPieceType(ID)) { if (db.ExistPieceType(piecetype)) { result = "نوع قطعه مورد نظر قبلاً ثبت شده است."; } else { result = db.UpdatePieceType(ID, EnglishName, PersianName); } } else { result = "نوع قطعه مورد نظر معتبر نیست."; } object finalResult = new Tuple <string, int>(result, page); return(Json(finalResult)); }
public void checkWinner() { int centx = LastPlaced.X; int centy = LastPlaced.Y; int count = 1; for (int dirx = -1; dirx <= 1; dirx++) { for (int diry = -1; diry <= 1; diry++) { if (dirx == 0 && diry == 0) { continue; } count = 1; int sum = 1; for (int i = 1; i >= -1; i -= 2) { if (i == -1) { //sum -= 1; count = 1; } while (sum < 5) { int targetx = centx + count * dirx * i; int targety = centy + count * diry * i; if (targetx < 0 || targety < 0 || targetx > 8 || targety > 8) { break; } if (getType(targetx, targety) != current) { break; } sum++; count++; } if (sum == 5) { winner = current; } } } } }
public string AddPieceType(Piecetype pieceType) { string result; try { db.Piecetypes.Add(pieceType); db.SaveChanges(); result = "Success"; } catch (Exception ex) { result = "Error"; } return(result); }
public ActionResult AddPieceType(Piecetype pieceType) { if (Session["AdminUser"] == null) { return(RedirectToAction("Login", "User")); } var result = ""; if (!db.ExistPieceType(pieceType)) { result = pieceType == null ? "نوع قطعه نظر معتبر نمی باشد." : db.AddPieceType(pieceType); } else { result = "نوع قطعه مورد نظر قبلاً ثبت شده است."; } var lastPage = db.LastPageNumber(); object finalResult = new Tuple <string, int>(result, lastPage); return(Json(finalResult)); }
public bool ExistPieceType(Piecetype Piecetype) { var existPieceType = GetPieceType(Piecetype); return(existPieceType != null); }
public bool ExistPieceType(Piecetype pieceType) { return(dal_pieceType.ExistPieceType(pieceType)); }
public string AddPieceType(Piecetype pieceType) { return(dal_pieceType.AddPieceType(pieceType)); }