public override void Init(params string[] Param) { GameIsOver = false; Turn = PlayerChips.X; MainWindow = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Game2)); Control = new Hashtable(); //GT.Picture pic = null; Bitmap pic; Box = new Hashtable(); ImgFull = (GHI.Glide.UI.Image)MainWindow.GetChildByName("imgFull"); ImgFull.Visible = false; for (int i = 1; i <= 9; i++) { var imgTemp = (GHI.Glide.UI.Image)MainWindow.GetChildByName("box" + i); //pic = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.blank), GT.Picture.PictureEncoding.JPEG); imgTemp.Bitmap = Resources.GetBitmap(Resources.BitmapResources.blank);//pic.MakeBitmap(); Control.Add(i, imgTemp); Box.Add(i, PlayerChips.Blank); imgTemp.TapEvent += (x) => { if (Turn == PlayerChips.X) { var img = x as GHI.Glide.UI.Image; var PinSel = int.Parse(img.Name.Substring(3)); Choose(PinSel); } }; if (i <= 2) { var linehor = (GHI.Glide.UI.Image)MainWindow.GetChildByName("line" + i); //pic = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.linehor), GT.Picture.PictureEncoding.JPEG); linehor.Bitmap = Resources.GetBitmap(Resources.BitmapResources.linehor);//pic.MakeBitmap(); } else if (i <= 4) { var linever = (GHI.Glide.UI.Image)MainWindow.GetChildByName("line" + i); //pic = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.linever), GT.Picture.PictureEncoding.JPEG); linever.Bitmap = Resources.GetBitmap(Resources.BitmapResources.linever);//pic.MakeBitmap(); } } Glide.MainWindow = MainWindow; //MainWindow.Invalidate(); }
bool EvaluatePos(PlayerChips player) { //ambil yg tinggal menang int BlankCounter = 0; int PlayerCounter = 0; int BlankPos = 0; //check horizontal for (int i = 1; i <= 7; i += 3) { BlankCounter = 0; PlayerCounter = 0; BlankPos = 0; for (int x = i; x <= i + 2; x++) { if ((PlayerChips)Box[x] == player) { PlayerCounter++; } if ((PlayerChips)Box[x] == PlayerChips.Blank) { BlankCounter++; BlankPos = x; } } if (BlankCounter == 1 && PlayerCounter == 2) { Choose(BlankPos); return(true); } } //check vertikal for (int i = 1; i <= 3; i++) { BlankCounter = 0; PlayerCounter = 0; BlankPos = 0; for (int y = i; y <= i + 6; y += 3) { if ((PlayerChips)Box[y] == player) { PlayerCounter++; } if ((PlayerChips)Box[y] == PlayerChips.Blank) { BlankCounter++; BlankPos = y; } } if (BlankCounter == 1 && PlayerCounter == 2) { Choose(BlankPos); return(true); } } //check diagonal { BlankCounter = 0; PlayerCounter = 0; BlankPos = 0; for (int y = 1; y <= 9; y += 4) { if ((PlayerChips)Box[y] == player) { PlayerCounter++; } if ((PlayerChips)Box[y] == PlayerChips.Blank) { BlankCounter++; BlankPos = y; } } if (BlankCounter == 1 && PlayerCounter == 2) { Choose(BlankPos); return(true); } } { BlankCounter = 0; PlayerCounter = 0; BlankPos = 0; var tmp = (PlayerChips)Box[3]; if (tmp != PlayerChips.Blank) { for (int y = 3; y <= 7; y += 2) { if ((PlayerChips)Box[y] == player) { PlayerCounter++; } if ((PlayerChips)Box[y] == PlayerChips.Blank) { BlankCounter++; BlankPos = y; } } if (BlankCounter == 1 && PlayerCounter == 2) { Choose(BlankPos); return(true); } } } return(false); }
bool CheckWin() { int counter = 0; //check horizontal for (int i = 1; i <= 7; i += 3) { counter = 0; var tmp = (PlayerChips)Box[i]; if (tmp == PlayerChips.Blank) { break; } for (int x = i; x <= i + 2; x++) { if (tmp != (PlayerChips)Box[x]) { break; } counter++; } if (counter >= 3) { Winner = tmp; return(true); } } //check vertikal for (int i = 1; i <= 3; i++) { counter = 0; var tmp = (PlayerChips)Box[i]; if (tmp == PlayerChips.Blank) { break; } for (int y = i; y <= i + 6; y += 3) { if (tmp != (PlayerChips)Box[y]) { break; } counter++; } if (counter >= 3) { Winner = tmp; return(true); } } //check diagonal { counter = 0; var tmp = (PlayerChips)Box[1]; if (tmp != PlayerChips.Blank) { for (int y = 1; y <= 9; y += 4) { if (tmp != (PlayerChips)Box[y]) { break; } counter++; } if (counter >= 3) { Winner = tmp; return(true); } } } { counter = 0; var tmp = (PlayerChips)Box[3]; if (tmp != PlayerChips.Blank) { for (int y = 3; y <= 7; y += 2) { if (tmp != (PlayerChips)Box[y]) { break; } counter++; } if (counter >= 3) { Winner = tmp; return(true); } } } //check all counter = 0; for (int i = 1; i <= 9; i++) { if ((PlayerChips)Box[i] != PlayerChips.Blank) { counter++; } } if (counter >= 9) { Winner = PlayerChips.Blank; return(true); } return(false); }
void Choose(int Pos) { if (GameIsOver) { return; } var box = (PlayerChips)Box[Pos]; if (box == PlayerChips.Blank) { var img = (GHI.Glide.UI.Image)Control[Pos]; Box[Pos] = Turn; if (Turn == PlayerChips.X) { //var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.x), GT.Picture.PictureEncoding.JPEG); img.Bitmap = Resources.GetBitmap(Resources.BitmapResources.x);//tmp.MakeBitmap(); Turn = PlayerChips.O; } else { //var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.o), GT.Picture.PictureEncoding.JPEG); img.Bitmap = Resources.GetBitmap(Resources.BitmapResources.o);// tmp.MakeBitmap(); Turn = PlayerChips.X; } img.Invalidate(); //[change] MainWindow.Invalidate(); if (CheckWin()) { GameIsOver = true; //load game over Bitmap bmp = null; if (Winner == PlayerChips.X) { //var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.WIN), GT.Picture.PictureEncoding.JPEG); bmp = Resources.GetBitmap(Resources.BitmapResources.WIN);//tmp.MakeBitmap(); } else if (Winner == PlayerChips.O) { //var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.LOSE), GT.Picture.PictureEncoding.JPEG); bmp = Resources.GetBitmap(Resources.BitmapResources.LOSE);//tmp.MakeBitmap(); } else { //var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.draw), GT.Picture.PictureEncoding.JPEG); bmp = Resources.GetBitmap(Resources.BitmapResources.draw);//tmp.MakeBitmap(); } ImgFull.Visible = true; ImgFull.Bitmap = bmp; ImgFull.Invalidate(); //[change] MainWindow.Invalidate(); Thread.Sleep(3000); CallFormRequestEvent(ScreenTypes.MainMenu); } else if (Turn == PlayerChips.O) { Thread.Sleep(500); ComMove(); } } }
bool EvaluatePos(PlayerChips player) { //ambil yg tinggal menang int BlankCounter = 0; int PlayerCounter = 0; int BlankPos = 0; //check horizontal for (int i = 1; i <= 7; i += 3) { BlankCounter = 0; PlayerCounter = 0; BlankPos = 0; for (int x = i; x <= i + 2; x++) { if ((PlayerChips)Box[x] == player) PlayerCounter++; if ((PlayerChips)Box[x] == PlayerChips.Blank) { BlankCounter++; BlankPos = x; } } if (BlankCounter == 1 && PlayerCounter == 2) { Choose(BlankPos); return true; } } //check vertikal for (int i = 1; i <= 3; i++) { BlankCounter = 0; PlayerCounter = 0; BlankPos = 0; for (int y = i; y <= i + 6; y += 3) { if ((PlayerChips)Box[y] == player) PlayerCounter++; if ((PlayerChips)Box[y] == PlayerChips.Blank) { BlankCounter++; BlankPos = y; } } if (BlankCounter == 1 && PlayerCounter == 2) { Choose(BlankPos); return true; } } //check diagonal { BlankCounter = 0; PlayerCounter = 0; BlankPos = 0; for (int y = 1; y <= 9; y += 4) { if ((PlayerChips)Box[y] == player) PlayerCounter++; if ((PlayerChips)Box[y] == PlayerChips.Blank) { BlankCounter++; BlankPos = y; } } if (BlankCounter == 1 && PlayerCounter == 2) { Choose(BlankPos); return true; } } { BlankCounter = 0; PlayerCounter = 0; BlankPos = 0; var tmp = (PlayerChips)Box[3]; if (tmp != PlayerChips.Blank) { for (int y = 3; y <= 7; y += 2) { if ((PlayerChips)Box[y] == player) PlayerCounter++; if ((PlayerChips)Box[y] == PlayerChips.Blank) { BlankCounter++; BlankPos = y; } } if (BlankCounter == 1 && PlayerCounter == 2) { Choose(BlankPos); return true; } } } return false; }
void Choose(int Pos) { if (GameIsOver) return; var box = (PlayerChips)Box[Pos]; if (box == PlayerChips.Blank) { var img = (GHI.Glide.UI.Image)Control[Pos]; Box[Pos] = Turn; if (Turn == PlayerChips.X) { var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.x), GT.Picture.PictureEncoding.JPEG); img.Bitmap = tmp.MakeBitmap(); Turn = PlayerChips.O; } else { var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.o), GT.Picture.PictureEncoding.JPEG); img.Bitmap = tmp.MakeBitmap(); Turn = PlayerChips.X; } img.Invalidate(); if (CheckWin()) { GameIsOver = true; //load game over Bitmap bmp = null; if (Winner == PlayerChips.X) { var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.WIN), GT.Picture.PictureEncoding.JPEG); bmp = tmp.MakeBitmap(); } else if (Winner == PlayerChips.O) { var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.LOSE), GT.Picture.PictureEncoding.JPEG); bmp = tmp.MakeBitmap(); } else { var tmp = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.draw), GT.Picture.PictureEncoding.JPEG); bmp = tmp.MakeBitmap(); } ImgFull.Visible = true; ImgFull.Bitmap = bmp; ImgFull.Invalidate(); Thread.Sleep(3000); CallFormRequestEvent(ScreenTypes.MainMenu); } else if (Turn == PlayerChips.O) { Thread.Sleep(500); ComMove(); } } }
bool CheckWin() { int counter = 0; //check horizontal for (int i = 1; i <= 7; i += 3) { counter = 0; var tmp = (PlayerChips)Box[i]; if (tmp == PlayerChips.Blank) break; for (int x = i; x <= i + 2; x++) { if (tmp != (PlayerChips)Box[x]) break; counter++; } if (counter >= 3) { Winner = tmp; return true; } } //check vertikal for (int i = 1; i <= 3; i++) { counter = 0; var tmp = (PlayerChips)Box[i]; if (tmp == PlayerChips.Blank) break; for (int y = i; y <= i + 6; y += 3) { if (tmp != (PlayerChips)Box[y]) break; counter++; } if (counter >= 3) { Winner = tmp; return true; } } //check diagonal { counter = 0; var tmp = (PlayerChips)Box[1]; if (tmp != PlayerChips.Blank) { for (int y = 1; y <= 9; y += 4) { if (tmp != (PlayerChips)Box[y]) break; counter++; } if (counter >= 3) { Winner = tmp; return true; } } } { counter = 0; var tmp = (PlayerChips)Box[3]; if (tmp != PlayerChips.Blank) { for (int y = 3; y <= 7; y += 2) { if (tmp != (PlayerChips)Box[y]) break; counter++; } if (counter >= 3) { Winner = tmp; return true; } } } //check all counter = 0; for (int i = 1; i <= 9; i++) { if ((PlayerChips)Box[i] != PlayerChips.Blank) { counter++; } } if (counter >= 9) { Winner = PlayerChips.Blank; return true; } return false; }
public override void Init(params string[] Param) { GameIsOver = false; Turn = PlayerChips.X; MainWindow = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.GameForm)); Control = new Hashtable(); GT.Picture pic = null; Box = new Hashtable(); ImgFull = (GHI.Glide.UI.Image)MainWindow.GetChildByName("imgFull"); ImgFull.Visible = false; for (int i = 1; i <= 9; i++) { var imgTemp = (GHI.Glide.UI.Image)MainWindow.GetChildByName("box" + i); pic = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.blank), GT.Picture.PictureEncoding.JPEG); imgTemp.Bitmap = pic.MakeBitmap(); Control.Add(i, imgTemp); Box.Add(i, PlayerChips.Blank); imgTemp.TapEvent += (x) => { if (Turn == PlayerChips.X) { var img = x as GHI.Glide.UI.Image; var PinSel = int.Parse(img.Name.Substring(3)); Choose(PinSel); } }; if (i <= 2) { var linehor = (GHI.Glide.UI.Image)MainWindow.GetChildByName("line" + i); pic = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.linehor), GT.Picture.PictureEncoding.JPEG); linehor.Bitmap = pic.MakeBitmap(); } else if (i <= 4) { var linever = (GHI.Glide.UI.Image)MainWindow.GetChildByName("line" + i); pic = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.linever), GT.Picture.PictureEncoding.JPEG); linever.Bitmap = pic.MakeBitmap(); } } Glide.MainWindow = MainWindow; //MainWindow.Invalidate(); }