Click here to Skip to main content
15,895,841 members
Please Sign up or sign in to vote.
1.27/5 (5 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Drawing;
using System.Drawing.Text;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page

{
   static public SpelKnapp[] SpelPlan = new SpelKnapp[9];

    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = "Click a button";


        if (!IsPostBack)
        {
            /*for(int i; i<9; i++)
            {
                SpelPlan[i].Turn(true);
                SpelPlan[].Text("");
            }*/

            for(int i=0; i<9; i++)
            {
                SpelPlan[i] = new SpelKnapp();
            }


        }




    }

    static bool turn = true;
    public bool didwin;


    public void winforX()
    {

        if (
       (Button1.Text == "X" & Button2.Text == "X" & Button3.Text == "X")
    || (Button4.Text == "X" & Button5.Text == "X" & Button6.Text == "X")
    || (Button7.Text == "X" & Button8.Text == "X" & Button9.Text == "X")
    || (Button1.Text == "X" & Button4.Text == "X" & Button7.Text == "X")
    || (Button2.Text == "X" & Button5.Text == "X" & Button8.Text == "X")
    || (Button3.Text == "X" & Button6.Text == "X" & Button9.Text == "X")
    || (Button1.Text == "X" & Button5.Text == "X" & Button9.Text == "X")
    || (Button3.Text == "X" & Button5.Text == "X" & Button7.Text == "X")
             )
        ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        PublishWinX();

    }
        ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    public void winforY()
    {
        if (
       (Button1.Text == "Y" & Button2.Text == "Y" & Button3.Text == "Y")
    || (Button4.Text == "Y" & Button5.Text == "Y" & Button6.Text == "Y")
    || (Button7.Text == "Y" & Button8.Text == "Y" & Button9.Text == "Y")
    || (Button1.Text == "Y" & Button4.Text == "Y" & Button7.Text == "Y")
    || (Button2.Text == "Y" & Button5.Text == "Y" & Button8.Text == "Y")
    || (Button3.Text == "Y" & Button6.Text == "Y" & Button9.Text == "Y")
    || (Button1.Text == "Y" & Button5.Text == "Y" & Button9.Text == "Y")
    || (Button3.Text == "Y" & Button5.Text == "Y" & Button7.Text == "Y")
          )

        PublishWinY();

        changeturn();

    }

    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    private void PublishWinX()
    {


        txt_box.Text = ("X Wins!");



        didwin = true;
        lockall();

    }

    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    private void PublishWinY()
    {


        txt_box.Text = ("Y Wins!");



        didwin = true;
        lockall();

    }

    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


    public void lockall()
    {

        Button1.Enabled = false;
        Button2.Enabled = false;
        Button3.Enabled = false;
        Button4.Enabled = false;
        Button5.Enabled = false;
        Button6.Enabled = false;
        Button7.Enabled = false;
        Button8.Enabled = false;
        Button9.Enabled = false;
    }

    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (turn == true)
        {

            Button1.Text = "X";

            turn = false;


        }
        else
        {
            Button1.Text = "Y";
            turn = true;
        }

        Button1.Enabled = false;
        winforX();
        winforY();
        checkforcat();

    }
    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    protected void Button2_Click(object sender, EventArgs e)
    {
        if (turn == true)
        {
            Button2.Text = "X";
            turn = false;

        }
        else
        {
            Button2.Text = "Y";
            turn = true;
        }
        Button2.Enabled = false;
        winforX();
        winforY();
        checkforcat();

    }
    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (turn == true)
        {
            Button3.Text = "X";
            turn = false;
        }
        else
        {
            Button3.Text = "Y";
            turn = true;
        }
        Button3.Enabled = false;
        winforX();
        winforY();
        checkforcat();

    }
    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    protected void Button4_Click(object sender, EventArgs e)
    {
        if (turn == true)
        {
            Button4.Text = "X";
            turn = false;
            //SpelPlan[5].Turn(false);//Knapp5 ska vara av
            //Button4.Enabled = SpelPlan[5].Get_Turn();
        }
        else
        {
            Button4.Text = "Y";
            turn = true;
        }
        Button4.Enabled = false;
        winforX();
        winforY();
        checkforcat();
        // if (turn == true)
        //{
        //    Button4.Text = "X";
        //    SpelPlan[5].Turn(false);//Knapp5 ska vara av
        //    Button4.Enabled = SpelPlan[5].Get_Turn();
        //}
        //else
        //{
        //    Button4.Text = "Y";
        //    turn = true;
        //}

        //SpelPlan[5].Turn(true);//Knapp5 ska vara av
        //Button4.Enabled = SpelPlan[5].Get_Turn();
    }
    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    protected void Button5_Click(object sender, EventArgs e)
    {
        if (turn == true)
        {
            Button5.Text = "X";
            turn = false;
        }
        else
        {
            Button5.Text = "Y";
            turn = true;
        }
        Button5.Enabled = false;
        winforX();
        winforY();
        checkforcat();

    }
    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    protected void Button10_Click(object sender, EventArgs e)
    {
        if (turn == true)
        {
            Button6.Text = "X";
            turn = false;
        }
        else
        {
            Button6.Text = "Y";
            turn = true;
        }
        Button6.Enabled = false;
        winforX();
        winforY();
        checkforcat();

    }
    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    protected void Button7_Click(object sender, EventArgs e)
    {
        if (turn == true)
        {
            Button7.Text = "X";
            turn = false;
        }
        else
        {
            Button7.Text = "Y";
            turn = true;
        }
        Button7.Enabled = false;
        winforX();
        winforY();
        checkforcat();

    }
    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    protected void Button8_Click(object sender, EventArgs e)
    {
        if (turn == true)
        {
            Button8.Text = "X";
            turn = false;
        }
        else
        {
            Button8.Text = "Y";
            turn = true;
        }
        Button8.Enabled = false;
        winforX();
        winforY();
        checkforcat();

    }
    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    protected void Button9_Click(object sender, EventArgs e)
    {
        if (turn == true)
        {
            Button9.Text = "X";
            turn = false;
        }
        else
        {
            Button9.Text = "Y";
            turn = true;
        }
        Button9.Enabled = false;
        winforX();
        winforY();
        checkforcat();
    }
    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    public void checkforcat()
    {
        if (Button1.Enabled == false & Button2.Enabled == false & Button3.Enabled == false & Button4.Enabled == false & Button5.Enabled == false & Button6.Enabled == false & Button7.Enabled == false & Button8.Enabled == false & Button9.Enabled == false)
        {
            if (didwin == false)
            {
                txt_box.Text = ("no one wins :( play again?");

                Label1.Text = "Click a Button Again";

            }
        }
    }

    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    private void changeturn()
    {
        if (didwin == true)
        {

            if (turn == true)
            {

                Label1.Text = "x's Turn";

            }
            else
            {
                Label1.Text = "y's Turn";
            }
        }
    }

    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    private void restart()
    {


        Button1.Enabled = true;
        Button1.Text = " ";
        Button2.Enabled = true;
        Button2.Text = " ";
        Button3.Enabled = true;
        Button3.Text = " ";
        Button4.Enabled = true;
        Button4.Text = " ";
        Button5.Enabled = true;
        Button5.Text = " ";
        Button6.Enabled = true;
        Button6.Text = " ";
        Button7.Enabled = true;
        Button7.Text = " ";
        Button8.Enabled = true;
        Button8.Text = " ";
        Button9.Enabled = true;
        Button9.Text = " ";


        txt_box.Text = (" ");
        txt_box.Enabled = false;


    }

    ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    protected void btn_restart_Click(object sender, EventArgs e)
    {


        restart();



    }
}
Posted
Comments
David_Wimbley 29-May-13 11:01am    
This is a code dump and doesn't specifically pin point any issues/error problem. You are wanting people to sift through your code...aint nobody got time for that.

This is also at least the 2nd (if not more) time you've posted this as well...how bout you give it a shot how you think it should be done...get stuck? Come back and post a SNIPPET of where you think you are stuck and you'll probably have better luck getting assistance.
walanw 29-May-13 11:09am    
its not the same post and the man who helped at first code said ask again if u have any problem u want help if dont want to help dont even write what do want from me ? why are u even putting time on that ?

1 solution

Create a class that represents your player and include the background color as a property of the player class.

You're designing your entire game wrong. You're depending on the values and states of controls to determine the state of the game. That's backwards. Your game state should be maintained by dedicated classes to maintaining the data, then the controls should be set to reflect that state.
 
Share this answer
 
Comments
walanw 29-May-13 11:12am    
so what do you think whould i programm this again? btw thank you for being nice ! not like tha man up there ....
Dave Kreskowiak 29-May-13 12:21pm    
I'd start with an object oriented approach. Classes for player, gamefield, pieces, enemies, whatever, game state, ... There's a ton of information you're going to need that isn't going to fit in a few forum posts.

Start reading: http://www.google.com/#gs_rn=14&gs_ri=psy-ab&cp=22&gs_id=2e&xhr=t&q=object+oriented+game+design&es_nrs=true&pf=p&sclient=psy-ab&oq=object+oriented+game+d&gs_l=&pbx=1&bav=on.2,or.r_qf.&bvm=bv.47008514,d.aWc&fp=5cdd3167d6a3f43d&biw=1920&bih=940

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900