Drawer

Game Design:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new GameForm());
}
}

class GameForm : Form {
List<Card> deck;
Card playerCard;
Card cpuCard;
TextBox info;
ComboBox statBox;
Button drawBtn;
Button battleBtn;

```
public GameForm() {
    Text = "Top Trumps Simulator";
    Size = new Size(520,520);
    StartPosition = FormStartPosition.CenterScreen;
    info = new TextBox { Multiline = true, ReadOnly = true, Font = new Font("Segoe UI", 11, FontStyle.Bold), Dock = DockStyle.Fill, ScrollBars = ScrollBars.Vertical };
    statBox = new ComboBox { DropDownStyle = ComboBoxStyle.DropDownList, Width = 140 };
    statBox.Items.AddRange(new string[] { "Power", "Speed", "Intelligence" });
    statBox.SelectedIndex = 0;
    drawBtn = new Button { Text = "Draw Cards", Width = 110 };
    battleBtn = new Button { Text = "Battle", Width = 110 };
    var panel = new FlowLayoutPanel { Dock = DockStyle.Bottom, Height = 50, Padding = new Padding(10), FlowDirection = FlowDirection.LeftToRight };
    panel.Controls.Add(statBox);
    panel.Controls.Add(drawBtn);
    panel.Controls.Add(battleBtn);
    Controls.Add(info);
    Controls.Add(panel);
    MakeDeck();
    drawBtn.Click += (s,e) => Draw();
    battleBtn.Click += (s,e) => Battle();
}

void MakeDeck() {
    deck = new List<Card> {
        new Card("Dragon",90,40,30),
        new Card("Robot",70,60,80),
        new Card("Wizard",50,30,95),
        new Card("Giant",85,25,20),
        new Card("Ninja",40,90,65),
        new Card("Alien",75,70,90),
        new Card("Knight",60,45,50)
    };
    var rnd = new Random();
    deck = deck.OrderBy(x => rnd.Next()).ToList();
}

void Draw() {
    if (deck.Count < 2) {
        info.Text = "Deck empty.\r\nRestart the application to play again.";
        return;
    }
    playerCard = deck[0];
    cpuCard = deck[1];
    deck.RemoveRange(0,2);
    info.Text = "Your Card:\r\n" + playerCard.ToString();
}

void Battle() {
    if (playerCard == null || cpuCard == null) return;
    string stat = statBox.SelectedItem.ToString();
    int p = playerCard.Get(stat);
    int c = cpuCard.Get(stat);
    string res = "Your " + stat + ": " + p + "\r\nCPU " + stat + ": " + c + "\r\n\r\n";
    if (p > c) res += "You Win!";
    else if (p < c) res += "CPU Wins!";
    else res += "It's a Draw!";
    info.Text = "Your Card:\r\n" + playerCard + "\r\nCPU Card:\r\n" + cpuCard + "\r\n" + res;
    playerCard = null;
    cpuCard = null;
}
```

}

class Card {
public string Name { get; }
public int Power { get; }
public int Speed { get; }
public int Intelligence { get; }

```
public Card(string name, int power, int speed, int intelligence) {
    Name = name;
    Power = power;
    Speed = speed;
    Intelligence = intelligence;
}

public int Get(string stat) {
    if (stat == "Power") return Power;
    if (stat == "Speed") return Speed;
    return Intelligence;
}

public override string ToString() {
    return Name + "\r\nPower: " + Power + "\r\nSpeed: " + Speed + "\r\nIntelligence: " + Intelligence + "\r\n";
}
```

}