private void CaptureButton_Click(object sender, EventArgs e) { if (videoSource != null) { if (videoSource.IsRunning) { videoSource.SignalToStop(); videoSource.WaitForStop(); CaptureBox.Invoke( new Action( delegate { CaptureBox.Image = null; CaptureBox.Invalidate(); })); CaptureButton.Name = "Start"; } else { videoSource.NewFrame += videoSource_NewFrame; videoSource.Start(); CaptureButton.Name = "Stop"; } SnapshotButton.Enabled = videoSource.IsRunning; RecordButton.Enabled = videoSource.IsRunning; } }
void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs) { currentFrame = (Bitmap)eventArgs.Frame.Clone(); browserFrame = (Bitmap)eventArgs.Frame.Clone(); if ((captureThread == null || !captureThread.IsAlive) && recordVideo) { Bitmap threadFrame = (Bitmap)currentFrame.Clone(); captureThread = new Thread( new ThreadStart( delegate { writer.AddFrame(threadFrame); })); captureThread.Start(); } if ((browserThread == null || !browserThread.IsAlive) && browserRunning) { browserThread = new Thread(new ThreadStart(BrowserSnapshot)); browserRunning = true; browserThread.Start(); } CaptureBox.Invoke( new Action( delegate { CaptureBox.Image = currentFrame; })); }
private void ResolutionCB_SelectedIndexChanged(object sender, EventArgs e) { videoSource.VideoResolution = videoSource.VideoCapabilities[ResolutionCB.SelectedIndex]; if (videoSource.IsRunning) { videoSource.SignalToStop(); videoSource.WaitForStop(); SnapshotButton.Enabled = videoSource.IsRunning; RecordButton.Enabled = videoSource.IsRunning; CaptureBox.Invoke( new Action( delegate { CaptureBox.Image = null; CaptureBox.Invalidate(); })); videoSource.NewFrame += videoSource_NewFrame; videoSource.Start(); SnapshotButton.Enabled = videoSource.IsRunning; RecordButton.Enabled = videoSource.IsRunning; } CaptureButton.Enabled = true; }
public CaptureBench() { this.boxPawn = new CaptureBox(TokenType.PAWN, 18); // 18 this.boxRook = new CaptureBox(TokenType.ROOK, 2); // 2 this.boxBishop = new CaptureBox(TokenType.BISHOP, 2); // 2 this.boxLance = new CaptureBox(TokenType.LANCE, 4); // 4 this.boxKnight = new CaptureBox(TokenType.KNIGHT, 4); // 4 this.boxSilver = new CaptureBox(TokenType.SILVER, 4); // 4 this.boxGold = new CaptureBox(TokenType.GOLD, 4); // 4 allTokenListCaptured = new List <Token>(); }
public void ApplyDataImpl(byte[] data) { if (CaptureBox.InvokeRequired) { var d = new ApplyDelegate(ApplyDataImpl); CaptureBox.Invoke(d, data); } else { ApplyModeDelegate(CaptureBox, data); Refresh(); } }
public void ApplyRGBAInternal(byte[] data) { if (CaptureBox.InvokeRequired) { var d = new ApplyDelegate(ApplyRGBAInternal); CaptureBox.Invoke(d, data); } else { ApplyRGBAToPictureBox(CaptureBox, data); Refresh(); } }
/// <summary> /// Déplacement d'une pièce vers une case non vide. /// </summary> /// <param name="box">Une case.</param> /// <param name="currentPlayer">Joueur courant.</param> /// <param name="opponentPlayer">Joueur adverse.</param> /// <param name="currentToken">Pièce courante.</param> public static void moveTokenToBusyBox(Box box, Player currentPlayer, Player opponentPlayer, Token currentToken) { Token tokenInBox = box.token; if (tokenInBox.owner != currentPlayer) { opponentPlayer.lostCount++; currentPlayer.score += tokenInBox.value; currentPlayer.captCount++; tokenInBox.owner = currentPlayer; Move captureMove = new Move(); captureMove.tokenID = tokenInBox.id; captureMove.playerName = opponentPlayer.name; captureMove.startCoordX = tokenInBox.box.coord.x; captureMove.startCoordY = tokenInBox.box.coord.y; captureMove.isPromoted = tokenInBox.isPromoted; if (tokenInBox.type == TokenType.KING) { // Capture du roi endOfGame = true; } else { // Capture d'une autre pièce if (tokenInBox.isPromoted == true) { tokenInBox.removePromotion(); } CaptureBox cb = tokenInBox.getCaptureLocation(); tokenInBox.box = cb; captureMove.destinationCoordX = cb.coord.x; captureMove.destinationCoordY = cb.coord.y; cb.addToken(tokenInBox); tokenInBox.isCaptured = true; unbindBoxAndToken(currentToken.box, currentToken); bindBoxAndToken(box, currentToken); if (currentToken.type != TokenType.GOLD && currentToken.type != TokenType.KING && currentToken.isPromoted == false) { if (currentToken.isInsideZone(currentToken.box, currentToken.owner.getPromotionZone())) { AIPromote(currentToken); toPromoteToken = null; } } } } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { recordVideo = false; browserRunning = false; if (videoSource.IsRunning) { videoSource.SignalToStop(); CaptureBox.Invoke( new Action( delegate { CaptureBox.Image = null; CaptureBox.Invalidate(); })); videoSource = null; } }
/// <summary> /// Permet de cloner un objet sérializable. /// </summary> /// <param name="list">Une liste de cases de capture.</param> /// <returns>Une copie de l'objet donné.</returns> public static List <CaptureBox> CloneCaptureBoxesNode(List <CaptureBox> list) { List <CaptureBox> newList = new List <CaptureBox> (); foreach (CaptureBox box in list) { if (!box.GetType().IsSerializable) { throw new Exception("Object must be serializable"); } MemoryStream ms = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms, box); ms.Position = 0; CaptureBox newBox = (CaptureBox)bf.Deserialize(ms); ms.Close(); newList.Add(newBox); } return(newList); }
/// <summary> /// Déplacement d'une pièce vers une case non vide lors de la recherche de coup par l'IA. /// </summary> /// <param name="node">Une node.</param> /// <param name="box">Une case.</param> /// <param name="currentPlayer">Joueur courant.</param> /// <param name="currentToken">Pièce courante.</param> public static void AImoveTokenToBusyBox(Node node, Box box, Player currentPlayer, Token currentToken) { Token tokenInBox = box.token; if (tokenInBox.owner != currentPlayer) { currentPlayer.score += tokenInBox.value; tokenInBox.owner = currentPlayer; if (tokenInBox.type != TokenType.KING) { if (tokenInBox.isPromoted == true) { tokenInBox.removePromotion(); } CaptureBox cb = tokenInBox.getCaptureLocation(node); tokenInBox.box = cb; cb.addToken(tokenInBox); tokenInBox.isCaptured = true; unbindBoxAndToken(currentToken.box, currentToken); bindBoxAndToken(box, currentToken); if (currentToken.type != TokenType.GOLD && currentToken.type != TokenType.KING && currentToken.isPromoted == false) { if (currentToken.isInsideZone(currentToken.box, currentPlayer.getPromotionZone())) { AIPromote(currentToken); } } } else { // Permet à endOfGame() de detecter une fin de partie tokenInBox.isCaptured = true; } } }
/// <summary> /// Affectation d'une case de capture. /// </summary> /// <param name="cb">Une case de capture.</param> public void setCaptureLocation(CaptureBox cb) { captureLocation = cb; }
public void GameChanged() { if (MapDisplay.Game.CurrentPlayer == null) { BeginTurnButton.Show(); NextTurnButton.Hide(); BeginTurnButton.Text = "Begin " + MapDisplay.Game.NextPlayer.Faction.ToString() + "'s turn"; } else { BeginTurnButton.Hide(); NextTurnButton.Show(); } MovePictureBox.BorderStyle = BorderStyle.None; BuildPictureBox.BorderStyle = BorderStyle.None; LoadPictureBox.BorderStyle = BorderStyle.None; UnloadPictureBox.BorderStyle = BorderStyle.None; RepairPictureBox.BorderStyle = BorderStyle.None; LightArtilleryPictureBox.BorderStyle = BorderStyle.None; HeavyArtilleryPictureBox.BorderStyle = BorderStyle.None; TorpedoPictureBox.BorderStyle = BorderStyle.None; DivePictureBox.BorderStyle = BorderStyle.None; LoadTorpedoesPictureBox.BorderStyle = BorderStyle.None; DepthChargePictureBox.BorderStyle = BorderStyle.None; InstallBatteryPictureBox.BorderStyle = BorderStyle.None; CapturePictureBox.BorderStyle = BorderStyle.None; MinePictureBox.BorderStyle = BorderStyle.None; LoadMinesPictureBox.BorderStyle = BorderStyle.None; SweepPictureBox.BorderStyle = BorderStyle.None; SearchMinesPictureBox.BorderStyle = BorderStyle.None; if (MapDisplay.Game.SelectedUnit != null) { DivePictureBox.Image = MapDisplay.Game.SelectedUnit.IsSubmerged ? Bitmaps.Get("Data\\Surface.png") : Bitmaps.Get("Data\\Dive.png"); } switch (MapDisplay.CurrentOrder) { case null: break; case Order.Move: MovePictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.Build: BuildPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.LightArtillery: LightArtilleryPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.HeavyArtillery: HeavyArtilleryPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.Repair: RepairPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.Load: LoadPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.Unload: UnloadPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.Torpedo: TorpedoPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.DiveOrSurface: DivePictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.LoadTorpedoes: LoadTorpedoesPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.DepthCharge: DepthChargePictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.InstallBattery: InstallBatteryPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.Capture: CapturePictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.Mine: MinePictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.LoadMines: LoadMinesPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.Sweep: SweepPictureBox.BorderStyle = BorderStyle.Fixed3D; break; case Order.SearchMines: SearchMinesPictureBox.BorderStyle = BorderStyle.Fixed3D; break; } if (MapDisplay.Game.CurrentPlayer != null) { FlagBox.Image = Game.GetFactionFlag(MapDisplay.Game.CurrentPlayer.Faction); GreetingText.Text = Game.GetFactionGreetings(MapDisplay.Game.CurrentPlayer.Faction); GreetingText.BackColor = Game.GetFactionColor(MapDisplay.Game.CurrentPlayer.Faction); NextTurnButton.Show(); BeginTurnButton.Hide(); } else { FlagBox.Image = null; GreetingText.Text = "Press the Begin Turn button."; GreetingText.BackColor = SystemColors.Control; NextTurnButton.Hide(); BeginTurnButton.Show(); } var selectedUnit = MapDisplay.Game.SelectedUnit; if (selectedUnit != null) { if (MapDisplay.Game.CurrentPlayer != null && MapDisplay.Game.CurrentPlayer.Faction != Faction.Neutral) { if (MapDisplay.Game.CurrentPlayer == selectedUnit.Player) { OrdersPanel.Show(); } UnitPanel.Show(); InfoPanel.Show(); } UnitPictureBox.SizeMode = PictureBoxSizeMode.Zoom; UnitPictureBox.Image = MapDisplay.Game.SelectedUnit.Type.LargeBitmap; UnitTextBox.Text = selectedUnit.Name; UnitTextBox.Text += " : " + selectedUnit.Type.Name; UnitTextBox.Text += Environment.NewLine + "Integrity: " + Math.Round(selectedUnit.Health * 100).ToString() + "%"; if (selectedUnit.Type.Capacity >= 1) { UnitTextBox.Text += Environment.NewLine + "Cargo: " + selectedUnit.Cargo + "/" + selectedUnit.Type.Capacity; } if (selectedUnit.TurnsUntilCompletion > 0) { UnitTextBox.Text += Environment.NewLine + "Turns until completion: " + selectedUnit.TurnsUntilCompletion; } if (selectedUnit.Type == UnitType.Submarine && selectedUnit.IsSubmerged) { UnitTextBox.Text += Environment.NewLine + "Oxygen left: " + ((Submarine)selectedUnit).OxygenLeft.ToString(); } if (selectedUnit.Type.Abilities.Contains(Order.Torpedo)) { UnitTextBox.Text += Environment.NewLine + "Torpedo salvoes left: " + selectedUnit.Torpedoes; } if (selectedUnit.Type.Abilities.Contains(Order.Mine)) { UnitTextBox.Text += Environment.NewLine + "Mine placements left: " + selectedUnit.Mines; } if (selectedUnit.Type.Abilities.Contains(Order.Move)) { UnitTextBox.Text += Environment.NewLine + "Moves Left: " + selectedUnit.MovesLeft.ToString("0.0"); } if (selectedUnit.Type.Abilities.Contains(Order.LightArtillery)) { UnitTextBox.Text += Environment.NewLine + "Light Artillery " + "Power: " + selectedUnit.Type.LightPower + ", Range: " + selectedUnit.Type.LightRange; } if (selectedUnit.Type.Abilities.Contains(Order.HeavyArtillery)) { UnitTextBox.Text += Environment.NewLine + "Heavy Artillery " + "Power: " + selectedUnit.Type.HeavyPower + ", Range: " + selectedUnit.Type.HeavyRange; } if (!float.IsPositiveInfinity(selectedUnit.Type.Armour)) { UnitTextBox.Text += Environment.NewLine + "Armour: " + selectedUnit.Type.Armour; } if (selectedUnit.Type.Abilities.Contains(Order.Move)) { MoveBox.Show(); } else { MoveBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.LightArtillery)) { LightArtilleryBox.Show(); } else { LightArtilleryBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.HeavyArtillery)) { HeavyArtilleryBox.Show(); } else { HeavyArtilleryBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.Repair)) { RepairBox.Show(); } else { RepairBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.Build)) { BuildBox.Show(); } else { BuildBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.Load)) { LoadBox.Show(); } else { LoadBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.Unload)) { UnloadBox.Show(); } else { UnloadBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.Torpedo)) { TorpedoBox.Show(); } else { TorpedoBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.DiveOrSurface)) { DiveBox.Show(); DiveButton.Text = selectedUnit.IsSubmerged ? "Surface" : "Dive"; } else { DiveBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.LoadTorpedoes)) { LoadTorpedoesBox.Show(); } else { LoadTorpedoesBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.DepthCharge)) { DepthChargeBox.Show(); } else { DepthChargeBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.InstallBattery)) { InstallBatteryBox.Show(); } else { InstallBatteryBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.Capture)) { CaptureBox.Show(); } else { CaptureBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.Mine)) { MineBox.Show(); } else { MineBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.LoadMines)) { LoadMinesBox.Show(); } else { LoadMinesBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.Sweep)) { SweepBox.Show(); } else { SweepBox.Hide(); } if (selectedUnit.Type.Abilities.Contains(Order.SearchMines)) { SearchMinesBox.Show(); } else { SearchMinesBox.Hide(); } MoveBox.Enabled = selectedUnit.MovesLeft >= 1; LightArtilleryBox.Enabled = selectedUnit.LightShotsLeft >= 1 && !selectedUnit.IsSubmerged; HeavyArtilleryBox.Enabled = selectedUnit.HeavyShotsLeft >= 1 && !selectedUnit.IsSubmerged; BuildBox.Enabled = !selectedUnit.IsSubmerged; RepairBox.Enabled = selectedUnit.RepairsLeft >= 1 && !selectedUnit.IsSubmerged; LoadBox.Enabled = selectedUnit.LoadsLeft >= 1 && !selectedUnit.IsSubmerged; UnloadBox.Enabled = selectedUnit.LoadsLeft >= 1 && !selectedUnit.IsSubmerged; TorpedoBox.Enabled = selectedUnit.TorpedoesLeft >= 1 && selectedUnit.Torpedoes >= 1; DiveBox.Enabled = selectedUnit.DivesLeft >= 1; LoadTorpedoesBox.Enabled = selectedUnit.Torpedoes < selectedUnit.Type.MaxTorpedoes; DepthChargeBox.Enabled = selectedUnit.DepthChargesLeft >= 1; InstallBatteryBox.Enabled = selectedUnit.InstallsLeft >= 1; CaptureBox.Enabled = selectedUnit.CapturesLeft >= 1; MineBox.Enabled = selectedUnit.MinesLeft >= 1 && selectedUnit.Mines >= 1; LoadMinesBox.Enabled = selectedUnit.Mines < selectedUnit.Type.MaxMines; SweepBox.Enabled = selectedUnit.SweepsLeft >= 1; SearchMinesBox.Enabled = selectedUnit.MineSearchesLeft >= 1; if (MapDisplay.CurrentOrder == Order.Move && selectedUnit.MovesLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.LightArtillery && selectedUnit.LightShotsLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.HeavyArtillery && selectedUnit.HeavyShotsLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.Repair && selectedUnit.RepairsLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.Load && selectedUnit.LoadsLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.Unload && selectedUnit.LoadsLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.Torpedo && selectedUnit.TorpedoesLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.LoadTorpedoes && selectedUnit.Torpedoes >= selectedUnit.Type.MaxTorpedoes) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.DepthCharge && selectedUnit.DepthChargesLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.InstallBattery && selectedUnit.InstallsLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.Capture && selectedUnit.CapturesLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.Mine && selectedUnit.MinesLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.LoadMines && selectedUnit.Mines >= selectedUnit.Type.MaxMines) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.Sweep && selectedUnit.SweepsLeft < 1) { MapDisplay.CurrentOrder = null; } if (MapDisplay.CurrentOrder == Order.SearchMines && selectedUnit.MineSearchesLeft < 1) { MapDisplay.CurrentOrder = null; } HealthBar.Value = (int)(selectedUnit.Health * 100); } else { UnitPanel.Hide(); OrdersPanel.Hide(); InfoPanel.Hide(); } Invalidate(); }