Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Zadaci
- // 1. zadatak
- namespace LV7___Zadatak_1
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<IPayable> list = new List<IPayable>();
- BankAccount B1 = new BankAccount("Enio", 1000, 0.0);
- BankAccount B2 = new BankAccount("Petar", 2000, 500);
- MobileAccount P1 = new MobileAccount("0992051444", 2.5, 50);
- MobileAccount P2 = new MobileAccount("0976432454", 1.4, 100);
- list.Add(B1);
- list.Add(B2);
- list.Add(P1);
- list.Add(P2);
- Random rnd = new Random();
- foreach (IPayable account in list)
- {
- account.SendPayment(rnd.Next(10, 100));
- }
- foreach (IPayable account in list)
- {
- account.RequestPayment(rnd.Next(1, 100));
- }
- foreach (IPayable account in list)
- {
- Console.WriteLine("Balance: " + account.GetBalance() + "$");
- }
- }
- }
- interface IPayable
- {
- double GetBalance();
- void SendPayment(double payment);
- void RequestPayment(double payment);
- }
- public class BankAccount : IPayable
- {
- private string mName;
- private double mLimit;
- private double mBalance;
- public BankAccount(string name, double limit, double balance)
- {
- this.mName = name;
- this.mLimit = limit;
- this.mBalance = balance;
- }
- public double GetBalance()
- {
- return this.mBalance;
- }
- public void SendPayment(double payment)
- {
- this.mBalance += payment;
- }
- public void RequestPayment(double payment)
- {
- double balance = this.mBalance;
- balance -= payment;
- if (balance > mLimit)
- {
- this.mBalance += payment;
- }
- else
- {
- Console.WriteLine("Error!");
- }
- }
- }
- public class MobileAccount : IPayable
- {
- private string mNumber;
- private double mPrice;
- private double mBalance;
- public MobileAccount(string number, double price, double balance)
- {
- this.mNumber = number;
- this.mPrice = price;
- this.mBalance = balance;
- }
- public double GetBalance()
- {
- return this.mBalance;
- }
- public void SendPayment(double payment)
- {
- this.mBalance += payment;
- }
- public void RequestPayment(double payment)
- {
- double balance = this.mBalance;
- balance -= payment;
- if (balance > 0)
- {
- this.mBalance += payment;
- }
- else
- {
- Console.WriteLine("Error!");
- }
- }
- }
- }
- // 2. zadatak
- namespace LV7___Zadatak_2
- {
- public partial class Form1 : Form
- {
- Graphics g;
- Pen p;
- public Form1()
- {
- InitializeComponent();
- g = pbDrawing.CreateGraphics();
- }
- private void pbDrawing_Click(object sender, EventArgs e)
- {
- }
- private void pbDrawing_MouseUp(object sender, MouseEventArgs e)
- {
- if (rbRed.Checked == true)
- {
- p = new Pen(Color.Red, sbThickness.Value);
- }
- else if (rbGreen.Checked == true)
- {
- p = new Pen(Color.Green, sbThickness.Value);
- }
- else if (rbBlue.Checked == true)
- {
- p = new Pen(Color.Blue, sbThickness.Value);
- }
- if (rbCircle.Checked == true)
- {
- Circle c = new Circle();
- c.draw(g, p, e.X, e.Y);
- }
- else if (rbSquare.Checked == true)
- {
- Square s = new Square();
- s.draw(g, p, e.X, e.Y);
- }
- else if (rbTriangle.Checked == true)
- {
- Triangle t = new Triangle();
- t.draw(g, p, e.X, e.Y);
- }
- }
- }
- class Circle
- {
- int r;
- public Circle()
- {
- r = 10;
- }
- public void draw(Graphics g, Pen p, int x, int y)
- {
- g.DrawEllipse(p, x, y, r, r);
- }
- }
- class Square
- {
- int a, b;
- public Square()
- {
- a = 10;
- b = 10;
- }
- public void draw(Graphics g, Pen p, int x, int y)
- {
- g.DrawRectangle(p, x, y, a, b);
- }
- }
- class Triangle
- {
- int a;
- public Triangle()
- {
- }
- public void draw(Graphics g, Pen p, int x, int y)
- {
- Point[] points = { new Point(x, y), new Point(x + 90, y), new Point(x + 40, y + 90) };
- g.DrawPolygon(p, points);
- }
- }
- }
- // Analiza
- // 1. Napravite igru križić-kružić (iks-oks) korištenjem znanja stečenih na ovoj
- // laboratorijskoj vježbi. Omogućiti pokretanje igre, unos imena dvaju igrača, ispis
- // koji igrač je trenutno na potezu, igranje igre s iscrtavanjem križića i kružića na
- // odgovarajućim mjestima te ispis dijaloga s porukom o pobjedi, odnosno
- // neriješenom rezultatu kao i praćenje ukupnog rezultata.
- namespace LV7___Analiza
- {
- public partial class TicTacToe : Form
- {
- bool turn = true; // true = X turn; flase = O turn
- public TicTacToe()
- {
- InitializeComponent();
- }
- private void NewGame()
- {
- label_turn.Text = "Turn: " + textBox_player1.Text;
- button1.Text = "";
- button2.Text = "";
- button3.Text = "";
- button4.Text = "";
- button5.Text = "";
- button6.Text = "";
- button7.Text = "";
- button8.Text = "";
- button9.Text = "";
- button1.Enabled = true;
- button2.Enabled = true;
- button3.Enabled = true;
- button4.Enabled = true;
- button5.Enabled = true;
- button6.Enabled = true;
- button7.Enabled = true;
- button8.Enabled = true;
- button9.Enabled = true;
- }
- private void button_click(object sender, EventArgs e)
- {
- Button b = (Button)sender;
- if (turn)
- {
- label_turn.Text = "Turn: " + textBox_player2.Text;
- b.Text = "X";
- }
- else
- {
- label_turn.Text = "Turn: " + textBox_player1.Text;
- b.Text = "O";
- }
- turn = !turn;
- b.Enabled = false;
- 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"))
- {
- MessageBox.Show(textBox_player1.Text + " has won!");
- NewGame();
- }
- else if ((button1.Text == "O" && button2.Text == "O" && button3.Text == "O") || (button4.Text == "O" && button5.Text == "O" && button6.Text == "O") || (button7.Text == "O" && button8.Text == "O" && button9.Text == "O"))
- {
- MessageBox.Show(textBox_player2.Text + " has won!");
- NewGame();
- }
- else if ((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"))
- {
- MessageBox.Show(textBox_player1.Text + " has won!");
- NewGame();
- }
- else if ((button1.Text == "O" && button4.Text == "O" && button7.Text == "O") || (button2.Text == "O" && button5.Text == "O" && button8.Text == "O") || (button3.Text == "O" && button6.Text == "O" && button9.Text == "O"))
- {
- MessageBox.Show(textBox_player2.Text + " has won!");
- NewGame();
- }
- else if ((button1.Text == "X" && button5.Text == "X" && button9.Text == "X") || (button3.Text == "X" && button5.Text == "X" && button7.Text == "X"))
- {
- MessageBox.Show(textBox_player1.Text + " has won!");
- NewGame();
- }
- else if ((button1.Text == "O" && button5.Text == "O" && button9.Text == "O") || (button3.Text == "O" && button5.Text == "O" && button7.Text == "O"))
- {
- MessageBox.Show(textBox_player2.Text + " has won!");
- NewGame();
- }
- else
- {
- if (!button1.Enabled && !button2.Enabled && !button3.Enabled && !button4.Enabled && !button5.Enabled && !button6.Enabled && !button7.Enabled && !button8.Enabled && !button9.Enabled)
- {
- MessageBox.Show("Tie!");
- NewGame();
- }
- }
- }
- private void button10_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void button_start_Click(object sender, EventArgs e)
- {
- if (textBox_player1.Text.Length == 0 || (textBox_player2.Text.Length == 0))
- {
- MessageBox.Show("Invalid player name!");
- }
- else
- {
- NewGame();
- }
- }
- private void TicTacToe_Load(object sender, EventArgs e)
- {
- 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement