Hi, been working on this project and just confusing the heck out of myself with classes and stuff and was hoping maybe someone could lend a hand on what I might be doing wrong?
The general idea of this is to get the arrow (int 231-234) to point in the direct that the use clicked (n/s/w/e) and then when they press go 1 or go 10 it goes the direction selected and go either 1 or 10. But I have to limit it from going over 100 in any direct and show a message that they can't do that. And on load it set to 0,0 and set to north which I believe I have figured already.
General I'm confused on the class\method stuff, which is below, I think I got it right, but for some reason on my form I can't get it to find the getDirection function just errors up on all that.
I'm not sure if I coded something wrong or what, suggested hints or tricks would be helpful.
Thanks in advance.
Main Form:
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;
namespace simple_robot
{
public partial class Robot : Form
{
Robot myRobot = new Robot();
public Robot()
{
InitializeComponent();
pointer.Text = myRobot.getDirection().ToString();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void robotbox_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label1_Click_1(object sender, EventArgs e)
{
}
private void northBtn_Click(object sender, EventArgs e)
{
myRobot.setDirection(231);
pointer.Text = myRobot.getDirection().ToString();
}
private void westBtn_Click(object sender, EventArgs e)
{
myRobot.SetDirection(232);
pointer.Text = myRobot.getDirection().ToString();
}
private void southBtn_Click(object sender, EventArgs e)
{
myRobot.SetDirection(233);
pointer.Text = myRobot.getDirection().ToString();
}
private void eastBtn_Click(object sender, EventArgs e)
{
myRobot.SetDirection(234);
pointer.Text = myRobot.getDirection().ToString();
}
private void label1_Click_2(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.OnClick = myRobot.getX(myRobot.getX() + 1);
}
private void button2_Click(object sender, EventArgs e)
{
this.OnClick = myRobot.getX(myRobot.getX() + 10);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace simple_robot
{
class robot
{
private int direction;
private int x;
private int y;
public void setDirection(int newDirection)
{
direction = newDirection;
}
public int getDirection(int direction)
{
return direction;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public void move(int unitToMove)
{
}
public robot()
{
x = 0;
y = 0;
direction = 231;
}
}
}