Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am stuck on this program and I am running out of time so if someone could help

ID: 645151 • Letter: I

Question

I am stuck on this program and I am running out of time so if someone could help me out by either pointing me in the right direction or doing it for me or anything will be helpful. Thank you.

My assignment PDF is actually right here if you want to see it: http://csserver.evansville.edu/~blandfor/Engr123/Asn06.pdf

Create a Windows GUI application in C# which will allow two users to play the game of Nim. The game of Nim is played with three piles of stones. The first pile has three stones, the second has 5 stones, and the third has 8 stones. Two players take turns and on each turn a player may take as many stones as she likes from any one pile. Play continues until someone is forced to take the last stone. The player who takes the last stone loses. Create a user interface that shows three "piles" and the number of stones in each pile similar to that shown below. The users can play by entering a pile number and a number of stones to be removed and clicking on the appropriate Enter button. Issue error messages for illegal entries using a message box. Provide a running display that indicates whose turn it is and other game status on the status label. The status label may also be used to declare a winner. Your program must contain a class for the piles. Name your class "Pile" and create appropriate private variables and public functions with properties to allow access.

My current code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Asn06
{
public partial class Nim : Form
{
public Nim()
{
InitializeComponent();
}
private static int Turn;
private void player1Button_Click(object sender, EventArgs e)
{
int remove = Convert.ToInt32(player1Remove.Value);
int pile = Convert.ToInt32(player1FromPile.Value);
int pile1 = Convert.ToInt32(pileBox1.Text);
int pile2 = Convert.ToInt32(pileBox2.Text);
int pile3 = Convert.ToInt32(pileBox3.Text);
if (pile1 == 3 && pile2 == 5 && pile3 == 8)
{
Turn = 1;
}
if (Turn == 1)
{

if (pile == 1 && pile1 != 0)
{
pileBox1.Text = Convert.ToString(pile1 - remove);
gameStatus.Text = "Player 2 Turn";
Turn = 2;
}
if (pile == 2 && pile2 != 0)
{
pileBox2.Text = Convert.ToString(pile2 - remove);
gameStatus.Text = "Player 2 Turn";
Turn = 2;
}
if (pile == 3 && pile3 != 0)
{
pileBox3.Text = Convert.ToString(pile3 - remove);
gameStatus.Text = "Player 2 Turn";
Turn = 2;
}
}
else
{
gameStatus.Text = "Error...it is player 1's turn";
}
if (pile1 == 0 && pile2 == 0 && pile3 == 0)
{
gameStatus.Text = "The winner is Player 2! The Game has been reset";
Turn = 1;
pileBox1.Text = "3";
pileBox2.Text = "5";
pileBox3.Text = "8";
}
}
private void player2Button_Click(object sender, EventArgs e)
{
int remove = Convert.ToInt32(player1Remove.Value);
int pile = Convert.ToInt32(player1FromPile.Value);
int pile1 = Convert.ToInt32(pileBox1.Text);
int pile2 = Convert.ToInt32(pileBox2.Text);
int pile3 = Convert.ToInt32(pileBox3.Text);
if (Turn == 2)
{
if (pile == 1 && pile1 != 0)
{
pileBox1.Text = Convert.ToString(pile1 - remove);
gameStatus.Text = "Player 1 Turn";
Turn = 1;
}
if (pile == 2 && pile2 != 0)
{
pileBox2.Text = Convert.ToString(pile2 - remove);
gameStatus.Text = "Player 1 Turn";
Turn = 1;
}
if (pile == 3 && pile3 != 0)
{
pileBox3.Text = Convert.ToString(pile3 - remove);
gameStatus.Text = "Player 1 Turn";
Turn = 1;
}
}
else
{
gameStatus.Text = "Error...it is player 2's turn";
}
if (pile1 == 0 && pile2 == 0 && pile3 == 0)
{
gameStatus.Text = "The winner is Player 1! The Game has been reset";
Turn = 1;
pileBox1.Text = "3";
pileBox2.Text = "5";
pileBox3.Text = "8";
}
}
}
}

Explanation / Answer

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("1");
listBox1.Items.Add("2");
listBox1.Items.Add("3");

listBox2.Items.Add("1");
listBox2.Items.Add("2");
listBox2.Items.Add("3");
listBox2.Items.Add("4");
listBox2.Items.Add("5");

listBox3.Items.Add("1");
listBox3.Items.Add("2");
listBox3.Items.Add("3");
listBox3.Items.Add("4");
listBox3.Items.Add("5");
listBox3.Items.Add("6");
listBox3.Items.Add("7");
listBox3.Items.Add("8");


}

private void button1_Click(object sender, EventArgs e)
{
string message, title, defaultValue,message1;
string myValue,myValue2;
// Set prompt.
message = "Enter a from which pile you want to draw:";
message1="Enter no of stones you want to draw:";

// Set title.
title = "InputBox Demo";
// Set default value.
defaultValue = "1";//Display message, title, and default value.
myValue = Interaction.InputBox(message, title, defaultValue, 100, 100);// If user has clicked Cancel, set myValue to defaultValue
myValue2 = Interaction.InputBox(message, title, defaultValue, 100, 100);
if (myValue == "")
{
myValue = defaultValue;
  
  
}
else
{
int myVal2 = Convert.ToInt32(myValue2);
for (int i = 0; i < myVal2; i++)
{
listBox1.RemoveAt(i);
}
  
  
}

}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote