private void drawGame(Game g, GameState gs) { lblGameCaption.Text = g.PlayerA.Name + " vs " + g.PlayerB.Name; Label lbl = null; for (int i = 0; i < g.GetFieldSize(); i++) { if (g.Field.Houses[i] is SideHouse) { lblSideA.Text = /*"\n"*/ +g.Field.Houses[i].Idx + ": " + g.Field.Houses[i].TokenAmount; switch (g.Field.Houses[i].TokenAmount) { case 0: lblSideA.ImageIndex = 0; break; case 1: lblSideA.ImageIndex = 1; break; case 2: lblSideA.ImageIndex = 2; break; case 3: lblSideA.ImageIndex = 3; break; case 4: lblSideA.ImageIndex = 3; break; case 5: lblSideA.ImageIndex = 3; break; default: lblSideA.ImageIndex = 3; break; } } else { lbl = (Label)(pnlBasicA.Controls.Find("lblBasicA_" + i.ToString(), false))[0]; lbl.Text = /*"\n" + *//*g.FieldA.Houses[i].Idx + ": " +*/ "" + g.Field.Houses[i].TokenAmount; lbl.ImageIndex = (g.Field.Houses[i].TokenAmount == 0) ? 1 : 2; } } for (int i = g.GetFieldSize(); i < g.GetFieldSize() * 2; i++) { if (g.Field.Houses[i] is SideHouse) { lblSideB.Text =/* "\n"+*/g.Field.Houses[i].Idx + ": " + g.Field.Houses[i].TokenAmount; switch (g.Field.Houses[i].TokenAmount) { case 0: lblSideB.ImageIndex = 6; break; case 1: lblSideB.ImageIndex = 7; break; case 2: lblSideB.ImageIndex = 8; break; case 3: lblSideB.ImageIndex = 9; break; case 4: lblSideB.ImageIndex = 9; break; case 5: lblSideB.ImageIndex = 9; break; default: lblSideB.ImageIndex = 9; break; } /*using (Graphics graphics = pbxSideB.CreateGraphics()){ graphics.DrawString("++", fntBasic, new SolidBrush(clrBasic), 0, 0); }*/ } else { lbl = (Label)(pnlBasicB.Controls.Find("lblBasicB_" + i.ToString(), false))[0]; lbl.Text = /*"\n" +*//* g.FieldA.Houses[i].Idx + ": " +*/ "" + g.Field.Houses[i].TokenAmount; lbl.ImageIndex = (g.Field.Houses[i].TokenAmount == 0) ? 3 : 4; } } switch (g.LastTurnResult) { case TurnResult.NOTHING: break; case TurnResult.CELL_BELONGS_OTHER_PLAYER: addToLog("This cell belongs to other player, you can't make turn here."); break; case TurnResult.SIDEHOUSE_SELECTED: addToLog("This cell is a sidehouse, you can't make turn here."); break; case TurnResult.EMPTY_HOUSE: addToLog("This cell is empty, you can't make turn here."); break; case TurnResult.ADDITIONAL_TURN: addToLog("You finished in sidehouse, additional turn!"); break; case TurnResult.SUCCESSFUL: break; case TurnResult.GAME_FINISHED: addToLog("Game finished! "); if (gs.CurrentPlayer != null) { addToLog("Player " + gs.CurrentPlayer.Name + " wins!"); } else { addToLog("Nobody wins."); } break; default: break; } lblSideA.Text =/*+= "\n" +*/ g.PlayerA.Name /*+ "\nfield: " + gs.ABasicSum */+ "\nRedeemed: " + gs.ASideNum; lblSideB.Text =/*+= "\n" +*/ g.PlayerB.Name /*+ "\nfield: " + gs.BBasicSum */+ "\nEnthralled: " + gs.BSideNum; // lblPlayerAInfo.Text= g.PlayerA.Name + "\nfield: " + gs.ABasicSum + "\nside: " + gs.ASideNum; // lblPlayerBInfo.Text= g.PlayerB.Name + "\nfield: " + gs.BBasicSum + "\nside: " + gs.BSideNum; if (!gs.GameFinished) { addToLog("It is your turn, " + gs.CurrentPlayer.Name); // pnlBasicA.Enabled = (gs.CurrentPlayer == g.PlayerA); setPanelControlsState(pnlBasicA, gs.CurrentPlayer == g.PlayerA); setPanelControlsState(pnlBasicB, gs.CurrentPlayer != g.PlayerA); //pnlBasicB.Enabled = !pnlBasicA.Enabled; } else { //pnlBasicB.Enabled = pnlBasicA.Enabled = false; setPanelControlsState(pnlBasicA, false); setPanelControlsState(pnlBasicB, false); } }
private void startNewGame() { game = new Game("Good", "Evil", 7, 6); gs = game.GetGameState(); fillControls(game); drawGame(game, gs); }
static void drawGame(Game g, GameState gs) { Console.WriteLine(); Console.WriteLine(g.PlayerA.Name + " vs " + g.PlayerB.Name); Console.WriteLine("---------------------------------------------------------------"); Console.Write("".PadLeft(9,' ')); for (int i = 0; i < g.GetFieldSize(); i++) { Console.Write("|" +( ((g.Field.Houses[i] is SideHouse) ? "+" : " ") + g.Field.Houses[i].Idx + ": " + g.Field.Houses[i].TokenAmount).PadLeft(8,' ')); } Console.WriteLine(); Console.WriteLine("---------------------------------------------------------------"); for (int i = g.GetFieldSize()*2-1; i >= g.GetFieldSize(); i--) { Console.Write("|" +( ((g.Field.Houses[i] is SideHouse) ? "+" : " ") + g.Field.Houses[i].Idx + ": " + g.Field.Houses[i].TokenAmount).PadLeft(8, ' ')); } Console.WriteLine(); switch (g.LastTurnResult) { case TurnResult.NOTHING: break; case TurnResult.CELL_BELONGS_OTHER_PLAYER: Console.WriteLine("This cell belongs to other player, you can't make turn here."); break; case TurnResult.SIDEHOUSE_SELECTED: Console.WriteLine("This cell is a sidehouse, you can't make turn here."); break; case TurnResult.EMPTY_HOUSE: Console.WriteLine("This cell is empty, you can't make turn here."); break; case TurnResult.ADDITIONAL_TURN: Console.WriteLine("You finished in sidehouse, additional turn!"); break; case TurnResult.SUCCESSFUL: break; case TurnResult.GAME_FINISHED: Console.WriteLine("Game finished! "); if (gs.CurrentPlayer != null) { Console.WriteLine("Player " + gs.CurrentPlayer.Name + " wins!"); } else { Console.WriteLine("Nobody wins."); } break; default: break; } Console.WriteLine(g.PlayerA.Name+": field: " +gs.ABasicSum+", side: "+gs.ASideNum); Console.WriteLine(g.PlayerB.Name + ": field: " + gs.BBasicSum + ", side: " + gs.BSideNum); if (!gs.GameFinished) { Console.WriteLine("It is your turn, " + g.ActivePlayer.Name); } /* Console.Write(" "); for (int i = 0; i < g.GetFieldSize(); i++) { Console.Write("|" + ((g.FieldB.Houses[i] is SideHouse) ? "+" : " ") + g.FieldB.Houses[i].Idx+": "+ g.FieldB.Houses[i].TokenAmount); } Console.WriteLine(); Console.WriteLine("It is your turn, "+g.ActivePlayer.Name); */ }
void lblBasicHouse_Click(object sender, EventArgs e) { stopBlinking(); // addToLog("House " + (sender as Label).Tag.ToString() + " selected."); int fIdx = Int32.Parse((sender as Label).Tag.ToString()); game.MakeTurn(fIdx); gs = game.GetGameState(); drawGame(game, gs); if (gs.GameFinished) { drawGame(game, gs); if (MessageBox.Show("Game is finished! " + gs.CurrentPlayer.Name + " wins!\nStart new game?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { startNewGame(); } } }
public GameState GetGameState() { GameState result = new GameState(); result.GameFinished = false; result.CurrentPlayer = null; result.CellsA = new int[this.GetFieldSize()]; result.CellsB = new int[this.GetFieldSize()]; int emptyCells = 0; for (int i = 0; i < this.GetFieldSize(); i++) { result.CellsA[i] = this.Field.Houses[i].TokenAmount; if (this.Field.Houses[i] is BasicHouse) { result.ABasicSum += this.Field.Houses[i].TokenAmount; } else { result.ASideNum += this.Field.Houses[i].TokenAmount; } if (this.Field.Houses[i] is BasicHouse && this.Field.Houses[i].TokenAmount == 0) { emptyCells++; } } if (emptyCells == this.GetFieldSize() - 1) { result.GameFinished = true; result.CurrentPlayer = this.PlayerA; } emptyCells = 0; for (int i = this.GetFieldSize(); i < this.GetFieldSize() * 2; i++) { result.CellsB[i - this.GetFieldSize()] = this.Field.Houses[i].TokenAmount; if (this.Field.Houses[i] is BasicHouse) { result.BBasicSum += this.Field.Houses[i].TokenAmount; } else { result.BSideNum += this.Field.Houses[i].TokenAmount; } if (!result.GameFinished && this.Field.Houses[i] is BasicHouse && this.Field.Houses[i].TokenAmount == 0) { emptyCells++; } } if (result.CurrentPlayer == null && emptyCells == this.GetFieldSize() - 1) { result.GameFinished = true; result.CurrentPlayer = this.PlayerB; } if (!result.GameFinished) { result.CurrentPlayer = this.ActivePlayer; } else { for (int i = 0; i < this.GetFieldSize(); i++) { if (this.Field.Houses[i] is BasicHouse) { result.CellsA[i] = 0; result.ABasicSum -= this.Field.Houses[i].TokenAmount; result.ASideNum += this.Field.Houses[i].TokenAmount; this.Field.Houses[i].TokenAmount = 0; } } for (int i = this.GetFieldSize(); i < this.GetFieldSize() * 2; i++) { if (this.Field.Houses[i] is BasicHouse) { result.CellsB[i - this.GetFieldSize()] = 0; result.BBasicSum -= this.Field.Houses[i].TokenAmount; result.BSideNum += this.Field.Houses[i].TokenAmount; this.Field.Houses[i].TokenAmount = 0; } } if (result.ASideNum + result.ABasicSum > result.BSideNum + result.BBasicSum) { result.CurrentPlayer = this.PlayerA; } if (result.ASideNum + result.ABasicSum < result.BSideNum + result.BBasicSum) { result.CurrentPlayer = this.PlayerB; } if (result.ASideNum + result.ABasicSum == result.BSideNum + result.BBasicSum) { result.CurrentPlayer = null; } this.LastTurnResult = TurnResult.GAME_FINISHED; } result.LastTurnResult = this.LastTurnResult; return result; }