AOA AOA AOA Folding For Team 45 AOA Files Home Front Page Become an AOA Subscriber! UserCP Calendar Memberlist FAQ Search Forum Home


Go Back   AOA > Software > Programming and Assembly Language

Programming and Assembly Language Please read this Topic's rules!!

Reply
 
LinkBack Thread Tools Rate Thread
  #1 (permalink)  
Old 19th December, 2007, 02:27 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

Angry Switch returns f__ values WTF????

gizmo I am too nervous
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
using System.IO;

namespace Jack
{
    public partial class Main:Form
    {
        #region Initialization routines
        public Main()
        {
            InitializeComponent();
            for (int i=1; i<=52; i++)
                combo_Choose_number.Items.Add(i.ToString());
            for (int i=1; i<=20; i++)
                combo_Speed_step.Items.Add(i.ToString());
        }
        private void Main_Load(object sender,EventArgs e)
        {
            if (File.Exists("UPS.ini"))
            {
                Read_all_settings("UPS.ini");
                First_round();
            }
            else
            {
                Rectangle monitor=Screen.PrimaryScreen.Bounds;
                if (monitor.Width<1280 || monitor.Height<1024)
                    MessageBox.Show("at 1280*1024 pixels.","The game is appeared best",MessageBoxButtons.OK,MessageBoxIcon.Information);                    
                Menu_Actions.Visible=Menu_Other.Visible=Menu_save_game.Visible=false;
                Menu_game.Visible=true;
                ptr_Move_card.Location=ptr_PC_gain_cards.Location=ptr_Player_gain_cards.Location=new Point(1100,1100);
                Sto_diavolo_cards_LEET();
                this.Width=580;
                this.Height=375;
                this.Location=new Point((int) ((monitor.Width-this.Width)/2),(int) ((monitor.Height-this.Height)/2));
                ptr_Jack_photo.Location=new Point(5,35);
                ptr_Jack_photo.SizeMode=PictureBoxSizeMode.AutoSize;
                group_Options.Location=new Point(255,69);               
            }           
        }                                            
        private void Init()             
        {                                                                        
            for (int i=0; i<=52; i++)   
                deck[i]=decks_have_passed[i]=stacked_cards[i]=0;
            for (int i=0; i<=6; i++)
                PC_cards[i]=player_cards[i]=0;
            PC_has_played_times=player_has_played_times=total_passed_cards=0;
            PC_grabbed_cards=player_grabbed_cards=PC_goals=player_goals=0;
            ptr_Jack_photo.Visible=group_Options.Visible=false;
            this.Width=935;
            this.Height=830;
            if (!File.Exists("UPS.ini"))
            {
                Rectangle monitor=Screen.PrimaryScreen.Bounds;
                this.Location=new Point((int) ((monitor.Width-this.Width)/2),(int) ((monitor.Height-this.Height)/2));
            }
            Shuffle_the_cards();
            ptr_Stack_of_cards.Visible=panel_Board.Visible=true;
            Menu_Actions.Visible=Menu_Other.Visible=Menu_save_game.Visible=true;
            Is_PC_the_last_grabber=false;
            ptr_PC_card_1.Image=ptr_PC_card_2.Image=ptr_PC_card_3.Image=global::Jack.Properties.Resources.Card_back_side;
            ptr_PC_card_4.Image=ptr_PC_card_5.Image=ptr_PC_card_6.Image=global::Jack.Properties.Resources.Card_back_side;
            ptr_PC_gain_cards.Location=ptr_Player_gain_cards.Location=new Point(1100,1100);
            Sto_diavolo_cards_LEET();            
            lbl_Stack_counter.Visible=true;
            if (Menu_show_progress_bars.Checked)
                progress_PC.Visible=progress_Player.Visible=true;
            else
                progress_PC.Visible=progress_Player.Visible=false;
            progress_PC.Maximum=progress_Player.Maximum=target;
            progress_PC.Value=PC_score;
            progress_Player.Value=player_score;
        }
        private void Sto_diavolo_cards_LEET()   
        {  // The routine moves the cards outside of form so they are not visible in the beggining
        }
        #endregion

        #region External variables
        bool PC_first_player=false;
        bool Is_PC_the_last_grabber=false;
        bool animation=true;
        int[] deck=new int[53];
        int[] decks_have_passed=new int[53];
        int[] PC_cards=new int[7];
        int[] player_cards=new int[7];
        int[] stacked_cards=new int[53];
        int PC_score=0,player_score=0;
        int PC_grabbed_cards=0,player_grabbed_cards=0;
        int PC_goals=0,player_goals=0;    
        int PC_has_played_times=0,player_has_played_times=0;
        int speed_step=6;
        int total_passed_cards=0;
        int target=151;
        int round=1;
        int total_rounds=1;
        int fatses=1;
        string language="English";
        #endregion

        #region Shuffle the cards
        void Shuffle_the_cards()
        {
            Random shuffle;
            int card;

            up:
            card=0;
            shuffle=new Random();            
            for (int i=1; i<=52; i++)
            {
                back:
                card=shuffle.Next(1,53);
                for (int j=1; j<=i-1; j++)
                    if (deck[j] == card)
                        goto back;
                deck[i]=card;
            }
            for (int i=1; i<=52; i++)
                for (int j=1; j<=52; j++)
                    if (i != j)
                        if (deck[i] == deck[j])
                            goto up;                    
            for (int i=1; i<=52; i++)
                if (deck[i]>52 || deck[i]<1)
                    goto up;
        }
        #endregion

        #region Settings
        void Choose_the_first_player()
        {
            int player_choice=26;
            // Read some values using try/catch blocks (no threads call)
            int PC_choice=player_choice;
            Shuffle_the_cards();
            Random shuffle=new Random();
            while (PC_choice == player_choice)
                PC_choice=shuffle.Next(1,53);
            if (deck[player_choice] > deck[PC_choice])
                PC_first_player=false;
            else
                PC_first_player=true;
            group_Options.Visible=false;
            First_round();
            below: int dummy=0;
            dummy++;
        }
        private void btn_OK_settings_Click(object sender,EventArgs e)
        {
            Choose_the_first_player();
            ptr_Move_card.BackColor=this.BackColor=Color.FromArgb(colorDialog.Color.R,colorDialog.Color.G,colorDialog.Color.B);                        
        }
        private void btn_Color_Click(object sender,EventArgs e)
        {
            colorDialog.ShowDialog();
        }
        #endregion

        #region Sort PC cards
        void Sort_PC_cards()
        {
            // Just sort the PC cards (no threads calling)
        }
        #endregion

        #region Deal the cards

        #region Player
        void Deal_player_cards()
        {
            // Deal the player cards actually uses loops to set the coordinates of ptr_Move_card
            if (round == 1)
            {
                if (PC_first_player)
                {
                   
                    Thread Deal_table=new Thread(new ThreadStart(Deal_table_cards));
                    Deal_table.Start();
                }
                else
                {
                    Thread Deal_PC=new Thread(new ThreadStart(Deal_PC_cards));
                    Deal_PC.Start();
                }
            }
            else
            {
                if (round == 2)
                {
                    if (!PC_first_player)
                    {
                        Thread Deal_PC=new Thread(new ThreadStart(Deal_PC_cards));
                        Deal_PC.Start();
                    }
                    else
                    {
                        PC_play();
                        this.Enabled=true;
                    }
                }
                else if (round == 3)
                {
                    if (!PC_first_player)
                    {
                        Thread Deal_PC=new Thread(new ThreadStart(Deal_PC_cards));
                        Deal_PC.Start();
                    }
                    else
                    {
                        PC_play();
                        this.Enabled=true;
                    }
                }
                else
                {
                    if (!PC_first_player)
                    {
                        Thread Deal_PC=new Thread(new ThreadStart(Deal_PC_cards));
                        Deal_PC.Start();
                    }
                    else
                    {
                        ptr_Stack_of_cards.Location=ptr_Fatsa_1.Location=ptr_Fatsa_2.Location=new Point(1100,1100);
                        PC_play();
                        this.Enabled=true;
                    }
                }
            }      
        }
        #endregion

        #region PC
        void Deal_PC_cards()
        {
            // Similar code
            if (round == 1)
            {
                if (PC_first_player)
                {
                    Thread Deal_player=new Thread(new ThreadStart(Deal_player_cards));
                    Deal_player.Start();
                }
                else
                {
                    Thread Deal_table=new Thread(new ThreadStart(Deal_table_cards));
                    Deal_table.Start();
                }
            }
            else
            {
                if (round == 2)
                {
                    if (PC_first_player)
                    {
                        Thread Deal_player=new Thread(new ThreadStart(Deal_player_cards));
                        Deal_player.Start();
                    }
                    else
                        this.Enabled=true;
                }
                else if (round == 3)
                {
                    if (PC_first_player)
                    {
                        Thread Deal_player=new Thread(new ThreadStart(Deal_player_cards));
                        Deal_player.Start();
                    }
                    else
                        this.Enabled=true;
                }
                else
                {
                    if (PC_first_player)
                    {
                        Thread Deal_player=new Thread(new ThreadStart(Deal_player_cards));
                        Deal_player.Start();
                    }
                    else
                    {
                        ptr_Stack_of_cards.Location=ptr_Fatsa_1.Location=ptr_Fatsa_2.Location=new Point(1100,1100);
                        this.Enabled=true;
                    }
                }
            }            
        }
        #endregion

        #region Table
        void Deal_table_cards()
        {
           // Similar code
            if (PC_first_player && round==1)
            {
                MessageBox.Show("PC plays first!","Ready!",MessageBoxButtons.OK,MessageBoxIcon.Information);
                PC_play();        
            }                      
            else                    
                MessageBox.Show("You play first!","Ready!",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }
        #endregion

        #endregion

        #region Se visible some of the cards
        void Set_visible_all_deal_cards_outside_of_baize()
        {
            // Move the cards only   
        }
        void Set_visible_PC_player_deal_cards_outside_of_baize()
        {
            // Move the cards only   
        }
        #endregion

        #region Rounds

        #region First round
        void First_round()
        {
            if (PC_score>=target && PC_score>player_score)
            {
                ptr_PC_gain_cards.Location=ptr_Player_gain_cards.Location=new Point(1100,1100);
                Sto_diavolo_cards_LEET();
                lbl_Stack_counter.Visible=progress_PC.Visible=progress_Player.Visible=false;
                MessageBox.Show("PC is the winner!",":(",MessageBoxButtons.OK,MessageBoxIcon.Error);
                File.Delete("UPS.ini");
                goto Telos;
            }
            else if (player_score>=target && player_score>PC_score)
            {
                ptr_PC_gain_cards.Location=ptr_Player_gain_cards.Location=new Point(1100,1100);
                Sto_diavolo_cards_LEET();
                lbl_Stack_counter.Visible=progress_PC.Visible=progress_Player.Visible=false;
                MessageBox.Show("You are the winner!","Congrats!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                File.Delete("UPS.ini");
                goto Telos;
            }
            lbl_PC_score.Text="Score: "+PC_score.ToString();
            lbl_PC_cards.Text="Cards: 0";
            lbl_Player_score.Text="Score: "+player_score.ToString();
            lbl_Player_cards.Text="Cards: 0";
            lbl_Stack_counter.Text="Cards: 4";
            lbl_Round.Text="Round 1/"+total_rounds.ToString();
            Init();
            if (PC_first_player)
            {
                PC_cards[1]=deck[1];
                PC_cards[2]=deck[2];
                PC_cards[3]=deck[3];
                PC_cards[4]=deck[4];
                PC_cards[5]=deck[5];
                PC_cards[6]=deck[6];
                player_cards[1]=deck[7];
                player_cards[2]=deck[8];
                player_cards[3]=deck[9];
                player_cards[4]=deck[10];
                player_cards[5]=deck[11];
                player_cards[6]=deck[12];
                stacked_cards[1]=deck[13];
                stacked_cards[2]=deck[14];
                stacked_cards[3]=deck[15];
                stacked_cards[4]=deck[16];
                ptr_Stack_of_cards.Location=new Point(750,560);
                panel_Board.Location=new Point(766,60);
                ptr_Human_card_1.Enabled=ptr_Human_card_2.Enabled=ptr_Human_card_3.Enabled=false;
                ptr_Human_card_4.Enabled=ptr_Human_card_5.Enabled=ptr_Human_card_6.Enabled=false;
            }
            else
            {
                player_cards[1]=deck[1];
                player_cards[2]=deck[2];
                player_cards[3]=deck[3];
                player_cards[4]=deck[4];
                player_cards[5]=deck[5];
                player_cards[6]=deck[6];
                PC_cards[1]=deck[7];
                PC_cards[2]=deck[8];
                PC_cards[3]=deck[9];
                PC_cards[4]=deck[10];
                PC_cards[5]=deck[11];
                PC_cards[6]=deck[12];
                stacked_cards[1]=deck[13];
                stacked_cards[2]=deck[14];
                stacked_cards[3]=deck[15];
                stacked_cards[4]=deck[16];
                ptr_Stack_of_cards.Location=new Point(750,60);
                panel_Board.Location=new Point(766,560);
                ptr_Human_card_1.Enabled=ptr_Human_card_2.Enabled=ptr_Human_card_3.Enabled=true;
                ptr_Human_card_4.Enabled=ptr_Human_card_5.Enabled=ptr_Human_card_6.Enabled=true;
            }
            Sort_PC_cards();
            if (stacked_cards[4]==11 || stacked_cards[4]==24 || stacked_cards[4]==37 || stacked_cards[4]==50)
                Init();
            else
            {
                 // Code which shows the last deck cards               
            }
            decks_have_passed[1]=stacked_cards[1];
            decks_have_passed[2]=stacked_cards[2];
            decks_have_passed[3]=stacked_cards[3];
            decks_have_passed[4]=stacked_cards[4];
            total_passed_cards=4;
            ptr_Stack_of_cards.Visible=true;
            ptr_Human_card_1.Image=Set_image(player_cards[1]);
            ptr_Human_card_2.Image=Set_image(player_cards[2]);
            ptr_Human_card_3.Image=Set_image(player_cards[3]);
            ptr_Human_card_4.Image=Set_image(player_cards[4]);
            ptr_Human_card_5.Image=Set_image(player_cards[5]);
            ptr_Human_card_6.Image=Set_image(player_cards[6]);
            ptr_Table_card_1.Image=Set_image(stacked_cards[1]);
            ptr_Table_card_2.Image=Set_image(stacked_cards[2]);
            ptr_Table_card_3.Image=Set_image(stacked_cards[3]);
            ptr_Table_card_4.Image=Set_image(stacked_cards[4]);
            ptr_PC_card_1.Image=ptr_PC_card_2.Image=ptr_PC_card_3.Image=ptr_PC_card_4.Image=ptr_PC_card_5.Image=ptr_PC_card_6.Image=global::Jack.Properties.Resources.Card_back_side;
            Set_visible_all_deal_cards_outside_of_baize();
            this.Enabled=false;
            if (PC_first_player)
            {
                Thread Deal_PC=new Thread(new ThreadStart(Deal_PC_cards));
                Deal_PC.Start();
            }
            else
            {
                Thread Deal_player=new Thread(new ThreadStart(Deal_player_cards));
                Deal_player.Start();
            }                        
            Telos: int dummy=0;
            dummy++;
        } 
        #endregion                      
    }    
}
This is a part of the source code of one card game.
Sometimes (very rare) the passing parameter card in Set_image has the default value=0.
I have no idea what's up....
The Set_image routine is called only by First_round(), Second_round etc...
In routines I removed some statements just to reduce the post size and code.
Apologize me man but you must realize me I have spent 4 days to solve this problem and nothing.
__________________

Last edited by MrSeanKon; 20th December, 2007 at 07:35 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 19th December, 2007, 12:12 PM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, UFO Shoot Out Champion, Unicycle Challenge Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 14,946
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

Any particular situation where the card is a value of 0 (i.e. can you reproduce it at will or does it appear to be totally random)?

Is the card 0 before you pass it to the function, or is it only 0 once it gets into the function?
__________________
Avatar and sig graphic by Pitch. Subscribers!
Ask about a custom graphic or avatar today!
 
Later,
Gizmo
Thermal Diode Mod and Direct-Die Water Block
8-Cheetah 18GiB U-2 SCSI
MegaRAID Enterprise 1500/128MiB
Samsung SyncMaster 955DF
TTGI/Superflower TTS-520 PSU
 

 
AOA Team filesAOA Team wcgAOA Team fah
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 19th December, 2007, 12:27 PM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

Quote:
Originally Posted by Gizmo View Post
Any particular situation where the card is a value of 0 (i.e. can you reproduce it at will or does it appear to be totally random)?
Sorry I don't understand you. Could you be more specific? The reason is that I am in front of PCs many hours.

Quote:
Originally Posted by Gizmo View Post
Is the card 0 before you pass it to the function, or is it only 0 once it gets into the function?
Well as you understand I create some external variables. They are arrays.
For example deck has 52 total cards.
Ace of diamonds has code 1.
Two of diamonds 2.
Three of diamonds 3.
.....
....
King of diamonds 13 and so on.
Therefore when I define an integer array (the deck[53] array) all values by default are zero.
I wonder that the game does not shuffle the cards.
If it is true I don't understand right now why.
Therefore when I call the Set_image(int) routine cos all deck[i]=0 (i=1..52) the routine returns garbage.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Superman Returns aghastpumpkin Random Nonsense! 0 2nd May, 2006 03:02 PM
Error returns, what is it? XeroHouR Graphics and Sound cards; Speakers and other Peripherals 21 8th February, 2005 12:43 AM
SLI returns! dolanenwindrift Graphics and Sound cards; Speakers and other Peripherals 0 28th June, 2004 04:53 PM
OCZ&lowMBps values usuall General Hardware Discussion 0 26th November, 2002 07:10 AM
DCLK0/1, in need of PCR values (68 & 6D) taxme EPoX MotherBoards 2 5th October, 2002 07:18 AM


All times are GMT -5. The time now is 10:46 PM.


Copyright ©2001 - 2009, AOA Forums

Search Engine Friendly URLs by vBSEO 3.3.0