Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 492233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T02:05:30+00:00 2026-05-13T02:05:30+00:00

I’m trying to learn C# (so go easy on me!) and as part of

  • 0

I’m trying to learn C# (so go easy on me!) and as part of a coursework I have been asked to create a game called strikeout.

The game rules are very simple. It is simply a case of knocking one counter into another, with the aim of leaving one counter left on the screen.

I am having trouble simply moving one counter into another. I have created a number of picture boxes using a loop (to make up my board), and created an event handler using the loop. How can I use the single even handler to move all of my counters?

{
    (...)
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            int x = j * (75);
            int y = i * (75);

            pictureBoxCounter[j, i] = new PictureBox();
            pictureBoxCounter[j, i].Location = new System.Drawing.Point(x, y);
            pictureBoxCounter[j, i].Size = new System.Drawing.Size(75, 75);
            pictureBoxCounter[j, i].BackColor = System.Drawing.Color.Transparent;
            panelGame.Controls.Add(pictureBoxCounter[j, i]);
            this.pictureBoxCounter[j, i].Click += new System.EventHandler(this.pictureBoxCounter_Click);
        }
    }
} // end of some function

private void pictureBoxCounter_Click(object sender, EventArgs e)
{
     //I need some code here but nothing seems to work :(
}

I’ve spent way to long on this problem. Even asked my tutor to help. Instead of helping he managed to break most of my code. So after fixing the problems he caused I am now back with a compiling program!

(When running the program you will need to enter player info to enable the start game button.)

If I can help with any other information don’t hesitate to ask!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T02:05:30+00:00Added an answer on May 13, 2026 at 2:05 am

    This programming problem appears intended to teach you about separation of concerns. If it isn’t, it should be. (It is now!)

    You have two problems, not one. (Actually, you have more than two, but you have two big ones.) One problem is: How do I create a set of objects representing the counters in this game, and what rules do those objects follow? The other problem is: How do I represent the counters on the screen?

    If your solution to the first problem is to create a bunch of PictureBoxes, you’re going down a rabbit hole that it’s going to be tough to get back out of. You should solve the first problem first, and then the second problem.

    Here’s a rough sketch (very rough, because I don’t know the rules of this game) of an object model that addresses the first problem:

    public class Board
    {
       public const int Height = 8;
       public const int Width = 8;
       private Counters[Height][] Counters { get; set; }
    
       public Counter GetCounter(int row, int col)
       {
          return Counters[row][col];
       }
       public void Initialize() { }
       public void ExecuteMove(Counter c) { }
    }
    
    public class Counter
    {
       public int Row { get; set; }
       public int Column { get; set; }
    }
    

    So, a Counter object knows where it is (its Row and Column). A Board object knows about all of the Counter objects, it knows how to find a Counter given its row and column, and it knows how to execute a move when a counter gets clicked on. (I don’t know anything about the rules of the game, but they’re going to live in the ExecuteMove method.

    You can now trivially write a method that prints the board to the console:

    public void PrintBoard(Board b)
    {
       for (int col = 0; col < board.Width; col ++)
       {
          for (int row = 0, row < board.Height; row++)
          {
             Counter c = board.GetCounter[row][col];
             Console.Write(c == null ? " " : "*");
          }
          Console.WriteLine();
       }
    }
    

    and a method to input a move:

    public Counter InputMove(Board b)
    {
       string s;
       Console.Write("Row: ");
       s = Console.ReadLine();
       int row = Convert.ToInt32(s);
       if (s == "") return null;
       Console.Write("Column: ");
       s = Console.ReadLine();
       if (s == "") return null;
       int column = Convert.ToInt32(s);
       return b.GetCounter(row, column);
    }
    

    …and now you have everything you need in order to code and test the ExecuteMove method. Get that working. I’ll wait.

    You done? Good. There are a couple of problems that you probably ran into that I haven’t addressed. For instance, you probably discovered that when you move a Counter, you have to update both the board’s array and the Counter itself. And you also probably discovered that you have to come up with some way of keeping track of what happens when a Counter is destroyed. Aren’t you glad you weren’t screwing around with mouse clicks and UI elements too?

    Now for part two. Let’s make a UI that knows how to talk to the Board. In your form, loop through the counters in the board, create a PictureBox for each (with its position based on the Row and Column properties), and add it to a Dictionary<PictureBox, Counter> called, say, Counters. You’ll also want a Dictionary<Counter, PictureBox> called, say, PictureBoxes. These maps give you the ability to find a Counter given its PictureBox, and vice versa.

    Attach this event handler to each PictureBox:

    private void PictureBox_Click(object sender, EventArgs e)
    {
       PictureBox p = (PictureBox) sender;
       Counter c = Counters[p];
       Board.ExecuteMove(c);
    }
    

    (This, by the way, is the answer to your original question.)

    Well, that’s all well and good: you can click on a PictureBox, find its Counter, and execute the move. But how do you update the visual state of the game in the UI? That depends, a lot, on what the actual rules of the game are.

    For instance, if clicking on a counter makes it disappear, you might add a Visible property to the Counter class and have the Board class’s ExecuteMove update it. If, when a Counter becomes invisible, the other Counters in its row move left or right, the ExecuteMove method will have to update their Row and Column, and do something with the now-invisible Counter that was at that position.

    But you already worked all of this out back when you tested all of the game logic, right? All you need to implement in your UI is an equivalent method to the one you built for printing it to the console. Only this one iterates through all of the Counters in the board, and updates their PictureBox based on their state.

    There are a lot of subtleties that I’m glossing over here, mostly because a) I don’t fully understand your problem and b) I’m not actually trying to do your homework for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.