private clsCharacter readStatsFromFile(clsCharacter c, string s) { try { System.IO.StreamReader charFile = new System.IO.StreamReader(s + ".txt"); c.Name = charFile.ReadLine(); c.Aggression = int.Parse(charFile.ReadLine()); c.Intelligence = int.Parse(charFile.ReadLine()); c.Randomness = int.Parse(charFile.ReadLine()); c.Luck = int.Parse(charFile.ReadLine()); } catch (System.IO.FileNotFoundException) { MessageBox.Show("Stats file not found.\nCould not find " + s + ".txt file\nUsing default Character values.", "FNF Error"); c = new clsCharacter(); } catch (FormatException) { MessageBox.Show("Unable to parse a value in the character textfile.\nUsing default Character values.", "Integer Parsing Error"); c = new clsCharacter(); } catch { MessageBox.Show("Non-File Not Found Error.\nCheck to ensure character textfile follows the proper order and structure.\nUsing default Character values.", "Non-FNF Error."); c = new clsCharacter(); } return(c); }
/// <summary> /// Retrieves the database's Money value for a given character. /// </summary> /// <param name="c">The character whose money value we are retrieving.</param> /// <returns>The returned money value that was stored in the database.</returns> public int getCharacterMoneyAmount(clsCharacter c) { int characterMoneyValue = 0; //SQL command string - select all from the characterDatabase Characters table string selMoney = "SELECT * FROM Characters " + "WHERE CharacterName=?"; //Add a parameter for the above statement OleDbParameter paramCharName = new OleDbParameter("CharacterName", c.Name); charComm.Parameters.Add(paramCharName); //prepare the charComm object for executing the SQL command stored in selCharacters charComm = new OleDbCommand(selMoney, charConnection); //use the charReader object to execute the charComm's SQL command, and close the connection when it is done charReader = charComm.ExecuteReader(CommandBehavior.CloseConnection); while (charReader.Read()) { characterMoneyValue = (int)charReader["Money"]; } return(characterMoneyValue); }
//Constructors public clsSeat() //default 0 arg constructor { _character = new clsCharacter(); _money = 1000; _bet = 10; _position = 0; }
public clsSeat(int p, int m, int b, clsCharacter c) { _position = p; _money = m; _bet = b; _character = c; _hand = new clsHand(); }
private void btnStart_Click(object sender, EventArgs e) { //Set the starting money, big blind, small blind, and bets defaultMoney = int.Parse(txtInitialMoney.Text); smallBlind = int.Parse(txtSmallBlind.Text); bigBlind = int.Parse(txtBigBlind.Text); //Create strings to try to load files with string seat1FileName = cmbSeat1.Text; string seat2FileName = cmbSeat2.Text; string seat3FileName = cmbSeat3.Text; string seat4FileName = cmbSeat4.Text; string seat5FileName = cmbSeat5.Text; string seat6FileName = cmbSeat6.Text; //Instantiate the characters to avoid null reference exceptions when setting their stats from files ch1 = new clsCharacter(); ch2 = new clsCharacter(); ch3 = new clsCharacter(); ch4 = new clsCharacter(); ch5 = new clsCharacter(); ch6 = new clsCharacter(); //Then load the character stats and images from file, if the files do not exist, then catch the exception and load defaults ch1 = readStatsFromFile(ch1, seat1FileName); ch1 = readCharacterImageFromFile(ch1, seat1FileName); ch2 = readStatsFromFile(ch2, seat2FileName); ch2 = readCharacterImageFromFile(ch2, seat2FileName); ch3 = readStatsFromFile(ch3, seat3FileName); ch3 = readCharacterImageFromFile(ch3, seat3FileName); ch4 = readStatsFromFile(ch4, seat4FileName); ch4 = readCharacterImageFromFile(ch4, seat4FileName); ch5 = readStatsFromFile(ch5, seat5FileName); ch5 = readCharacterImageFromFile(ch5, seat5FileName); ch6 = readStatsFromFile(ch6, seat6FileName); ch6 = readCharacterImageFromFile(ch6, seat6FileName); //Then open a PokerGame.cs form, sending the characters as parameters frmPokerGame gameInstance = new frmPokerGame(ch1, ch2, ch3, ch4, ch5, ch6, defaultMoney, smallBlind, bigBlind, boardColor, fontColor); gameInstance.Show(); }
private clsCharacter readStatsFromDatabase(clsCharacter c, string s, int databaseIndex) { try { c.Name = characterDatabaseDataSet.Characters.CharacterNameColumn.ToString(); //c.Name = characterDatabaseDataSet.Character["CharacterName"][databaseIndex]; } catch { MessageBox.Show("An error has occurred - readStatsFromDatabase"); } return(c); }
public frmPokerGame(clsCharacter c1, clsCharacter c2, clsCharacter c3, clsCharacter c4, clsCharacter c5, clsCharacter c6, int startingMoney, int smallBlind, int bigBlind, Color bc, Color fc) { InitializeComponent(); int initialBet = bigBlind; seat1 = new clsSeat(1, startingMoney, initialBet, c1); seat2 = new clsSeat(2, startingMoney, initialBet, c2); seat3 = new clsSeat(3, startingMoney, initialBet, c3); seat4 = new clsSeat(4, startingMoney, initialBet, c4); seat5 = new clsSeat(5, startingMoney, initialBet, c5); seat6 = new clsSeat(6, startingMoney, initialBet, c6); this.BackColor = bc; this.ForeColor = fc; }
private clsCharacter readCharacterImageFromFile(clsCharacter c, string s) { try { c.Picture = Image.FromFile(s + ".jpg"); } catch (System.IO.FileNotFoundException) { MessageBox.Show("Image file not found.\nUsing default Character values.", "FNF Error"); c = new clsCharacter(); } catch { MessageBox.Show("Non-File Not Found Error.\n\nUsing default Character values.", "Non-FNF Error."); c = new clsCharacter(); } return(c); }
//None. #endregion #region Class Methods /// <summary> /// Retrieves a list of characters and their stats from the characterDatabase's Characters table. /// </summary> /// <returns></returns> public List <clsCharacter> getCharactersFromDatabase() { //create a list to store the character data List <clsCharacter> allCharacters = new List <clsCharacter>(); //SQL command string - select all from the characterDatabase Characters table string selCharacters = "SELECT * FROM Characters"; //prepare the charComm object for executing the SQL command stored in selCharacters charComm = new OleDbCommand(selCharacters, charConnection); //use the charReader object to execute the charComm's SQL command, and close the connection when it is done charReader = charComm.ExecuteReader(CommandBehavior.CloseConnection); while (charReader.Read()) //read until the end of the database is reached { //store the data from the current character object in individual variables string name = charReader["CharacterName"].ToString(); int aggression = (int)charReader["Aggression"]; int luck = (int)charReader["Luck"]; int randomness = (int)charReader["Randomness"]; int intelligence = (int)charReader["Intelligence"]; string imageString = charReader["Picture"].ToString(); //populate a new character object with those variables clsCharacter c = new clsCharacter(name, aggression, intelligence, randomness, luck, Image.FromFile(imageString)); //add that new character to the List<clsCharacter> object allCharacters.Add(c); } charReader.Close(); return(allCharacters); }
public frmHandEvalTest(clsCharacter c1) { InitializeComponent(); testSeat = new clsSeat(1, 1000, 10, c1); }
public int getHandStrength(clsCharacter character) { int characterIntelligence = character.Intelligence; int characterAggression = character.Aggression; int characterRandomness = character.Randomness; double multiplier = 1; //used to add additional value to handStrength due to same suit, sequential values, same value bool sameValue; bool sequential; bool sameSuit; int handStrength = -1; //evaluates from 0 (least strength) to 100 (highest strength) int card1Value = Card1 % 13; //so ace = 0, 2 = 1, king = 12, if (card1Value == 0) { card1Value = 13; } // and now set ace to 13 instead of 0 int card2Value = Card2 % 13; if (card2Value == 0) { card2Value = 13; } int card1Suit = (Card1 - 1) / 12; //this is 12 because the next suit starts every 12 cards. We subtract 1 since int card2Suit = (Card2 - 1) / 12; // the cards are indexed to 1 instead of zero. In this case, Spades = 0, Heart = 1, Diamonds = 3, Clubs = 4 //Determine truth value of sameValue, sequential if (card1Value - card2Value == 0) //case: card1 and card2 have the same value (e.g. both are jacks) { sameValue = true; sequential = false; } else if (Math.Abs(card1Value - card2Value) == 1 || Math.Abs(card1Value - card2Value) == 12) //case: the absolute value of the { // difference between card1 and card 2 is 1 (1 number away from each other) // or 12 away from each other since ace and 2 are sequential sequential = true; sameValue = false; } else { sequential = false; sameValue = false; } //Determine the truth value of sameSuit if (card1Suit == card2Suit) { sameSuit = true; } else { sameSuit = false; } //if- if else - else artificial intelligence structure for determining hand strength (depends on character intelligence) if (characterIntelligence >= 90) //case: character intelligence is greater than or equal to 90 { //superior concept of both same suit and sequential cards, good concept of pocket pairs (same card) if (sameSuit) { multiplier += .6; } if (sequential) { multiplier += .3; } if (sameValue) { multiplier += .6; } if (card1Value > 9 && card2Value > 9) //case: both face cards { multiplier += .5; } handStrength = (int)((25 * 2) - 2); handStrength = (int)(multiplier * handStrength); } else if (characterIntelligence >= 70) //case: character intelligence is greater than or equal to 70 { //good concept of same suit and sequential cards, some concept of pocket pairs (same card) if (sameSuit) { multiplier += .5; } if (sequential) { multiplier += .3; } if (sameValue) { multiplier += .2; } handStrength = 25 * 2; handStrength = (int)(multiplier * handStrength); } else if (characterIntelligence >= 50) //case: character intelligence is greater than or equal to 50 { //slight concept of same suit and good concept of sequential cards if (sameSuit) { multiplier += .2; } if (sequential) { multiplier += .3; } handStrength = (int)((25 * 2.5) + 2); handStrength = (int)(multiplier * handStrength); } else if (characterIntelligence >= 20) //case: character intelligence is greater than or equal to 20 { //no concept of same suit, values seqential numeric cards if (sequential == true) { multiplier = 1.93; } handStrength = (card1Value + card2Value) * 2; handStrength = (int)(handStrength * multiplier); } else //case: character intelligence is less than 20 { //character has no concept of sequential numbers, believes same color is equal value to same suit :) bool sameColor; if (sameSuit == true || card1Suit == 0 && card2Suit == 3 || card1Suit == 3 && card2Suit == 0 || card1Suit == 1 && card2Suit == 2 || card1Suit == 2 && card2Suit == 1) { sameColor = true; } else { sameColor = false; } if (sameColor == true) { multiplier = 1.93; } handStrength = (card1Value + card2Value) * 2; handStrength = (int)(handStrength * multiplier); } //case: handStrength is still the default value of -1, send an error message and set it to zero if (handStrength == -1) { MessageBox.Show("Hand strength has a value of -1", "Error"); handStrength = 0; } //case: handStrength is greater than 100, set it to 100 if (handStrength > 100) { handStrength = 100; } return(handStrength); } //close calculateHandStrength()